Type inference with Numeric
and generic function parameters causes Internal Compiler Error
#6215
Labels
bug
Something isn't working
compiler: frontend
Everything to do with type checking, control flow analysis, and everything between parsing and IRgen
compiler
General compiler. Should eventually become more specific as the issue is triaged
Compiling this code will (as expected) generate an ICE:
As expected, because the ICE is caused by the way we do type inference, monomorphization and
Numeric
decay. I doubt we can do something about it without changing our type inference mechanism to solve the type equation looking at the usages within the whole scope.What happens here is the following. In
let x = 123;
,x
starts asUnkonwn
and gets turned intoNumeric
. TheUnknownGeneric
T
gets then also unified intoNumeric
and since monomorphisation needs it to be a concrete integer,Numeric
decay will turn it intou64
.x
will still beNumeric
. In the final explicit return,x
will be unified with the function result and becomeu8
.Thus, we will end up in the
fn_with_generic_arg
acceptingu64
andx
beingu8
and passed to the function. Generated IR, as expected, shows that:The text was updated successfully, but these errors were encountered: