tokiwa-software / fuzion

The Fuzion Language Implementation
https://fuzion-lang.dev
GNU General Public License v3.0
46 stars 11 forks source link

Numliteral inference, inference via result type of outer feature #3415

Open michaellilltokiwa opened 1 month ago

michaellilltokiwa commented 1 month ago

Consider the following example:

a f64 =>
  3 + 5

Currently during inference i32 is assumed to be the type of the numliterals. Since the outer feature has a valid numliteral type, in these cases we could also take this type as the inferred type.

I am not sure though if this is confusing in more complex examples...

fridis commented 1 month ago

This might be easier than it appears to be: For any operation on numeric whose result type is numeric.this, we could propagate the expected type provided that the target is a numeric literal. This should also work for, e.g.,

b f64 => 1 + 2/3

where the type f64 is first propagated to the target 1 of numeric.infix +, and then propagated as the expected argument type of 2/3, where it is propagated to the target 2 of numeric.infix /, then propagated as the expected argument type of 3.