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

Compiler panic with mismatched record field names #7478

Open
imclerran opened this issue Jan 7, 2025 · 2 comments
Open

Compiler panic with mismatched record field names #7478

imclerran opened this issue Jan 7, 2025 · 2 comments

Comments

@imclerran
Copy link
Contributor

imclerran commented Jan 7, 2025

Description

A mismatch between the naming of a record field in its type annotation and its definition/usage causes a compiler panic. This issue occurs under specific conditions involving optional fields in records.

Steps to Reproduce

The following minimal example reproduces the issue:

main! = \_ ->
    _ = foo { bar: 1, baz: 1 }
    Ok {}

foo : { qux ? U16, baz : U8 } -> U8
foo = \{ bar ? 0, baz } ->
    if bar == 0 then
        0
    else
        baz

Conditions

The panic occurs when:

  1. A function takes a record with two or more fields, one of which must be optional.
  2. The optional record field is a number type of U16/I16 or larger, Str, Bool, or possibly others (does not apply to U8/I8).
  3. The optional field has one name in the type annotation but a different name is used in the definition, and the name from the definition is used in the function call.

Expected Behavior

The compiler should emit a type-checking error indicating the field name mismatch instead of panicking.

Actual Behavior

The compiler produces the following panic:

thread 'main' panicked at crates/compiler/gen_llvm/src/llvm/build.rs:5582:19:
Error in alias analysis: error in module ModName("UserApp"), function definition FuncName("\x11\x00\x00\x00\x01\x00\x00\x00\x90\x7f\x81\xfe\xe6S\xe3K"), definition of value binding ValueId(3): tuple field index 2 out of range

Additional Notes

  • Reversing the types of the optional and non-optional fields (e.g., making the optional field U8 and the non-optional field U16) does not trigger the error, indicating the issue is not based on the total size of the record.
@imclerran
Copy link
Contributor Author

imclerran commented Jan 7, 2025

More experimentation:

Type := { a : U8, b : U8 } # This will NOT trigger the bug, but changing a OR b to U16 will.

main! = \_ ->
    _ = foo { bar: { a: 1, b: 1 }, baz: 1 }
    Ok {}

foo : { qux ? Type, baz : U8 } -> U8
foo = \{ bar ? { a: 0, b: 0 }, baz } ->
    if bar.a == 0 then
        0
    else
        baz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants