Skip to content

Improve compiler error messages - hide internal Cranelift errors #36

@mjm918

Description

@mjm918

Description

When compilation fails due to internal type mismatches, the error message exposes Cranelift internals:

declared type of variable var0 doesn't match type of value v0
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

This is confusing for users - they see Rust-specific terms like var0, v0, and RUST_BACKTRACE.

Expected Behavior

Error messages should be user-friendly and naml-specific:

  • Show the actual variable name from the source code
  • Show the expected vs actual types in naml terms
  • Provide a helpful suggestion if possible
  • Hide internal implementation details (Cranelift, Rust panic messages)

Example

Current:

declared type of variable var0 doesn't match type of value v0

Expected:

error: type mismatch for variable 'xx'
  --> file.naml:1:17
   |
 1 | var xx: decimal = 1.0;
   |         ^^^^^^^ expected decimal, found float
   |
help: decimal is not yet fully supported, use float instead

Scope

  1. Wrap Cranelift compilation in proper error handling
  2. Catch panics and convert to user-friendly errors
  3. Map internal variable names back to source names where possible
  4. Add span information to codegen errors for better source locations

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions