fuzion icon indicating copy to clipboard operation
fuzion copied to clipboard

Numliteral inference, inference via result type of outer feature

Open michaellilltokiwa opened this issue 1 year ago • 1 comments

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...

michaellilltokiwa avatar Jul 19 '24 09:07 michaellilltokiwa

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.

fridis avatar Jul 22 '24 08:07 fridis