jfecher / ante

A safe, easy systems language
http://antelang.org
MIT License
1.9k stars 80 forks source link

Adding type annotations to an unbound type variable can crash the compiler #168

Open jfecher opened 1 year ago

jfecher commented 1 year ago
import HashMap
map = mut empty ()

Will run fine, until adding a type annotation:

import HashMap
map: ref (HashMap U8 U16) = mut empty ()

In which case it will cause the following compiler panic:

thread 'main' panicked at 'internal error: entered unreachable code: Tried to apply an unbound type variable (id 259), args: [TypeApplication(UserDefined(TypeInfoId(10)), [TypeApplication(Primitive(IntegerType), [Primitive(IntegerTag(U8))]), TypeApplication(Primitive(IntegerType), [Primitive(IntegerTag(U16))])])]', src/hir/monomorphisation.rs:550:25
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
jfecher commented 1 year ago

The issue here seems to stem from the typo of ref instead of Ref:

map: Ref (HashMap U8 U16) = mut empty ()

a type annotation of a type application to an unbound type variable is rather unusual. Perhaps this issue will be fixed once we check type annotations must match exactly their target types rather than the current behavior where type variables in the annotation may still be bound to more specific types.