Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jfecher opened this issue Oct 19, 2023 · 1 comment
Labels
crash An internal compiler error or (compiler) runtime crash panic A panic within the compiler

Comments

@jfecher
Copy link
Owner

jfecher commented Oct 19, 2023

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 jfecher added panic A panic within the compiler crash An internal compiler error or (compiler) runtime crash labels Oct 19, 2023
@jfecher jfecher changed the title Adding type annotations to a ref can crash the compiler Adding type annotations to an unbound type variable can crash the compiler Oct 19, 2023
@jfecher
Copy link
Owner Author

jfecher commented Oct 19, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash An internal compiler error or (compiler) runtime crash panic A panic within the compiler
Projects
None yet
Development

No branches or pull requests

1 participant