Skip to content

fix(sema): remap imported builtin locations to import loc (#1305)#1850

Open
0takuc0mrade wants to merge 2 commits intohyperledger-solang:mainfrom
0takuc0mrade:fix/builtin-note-without-file-position
Open

fix(sema): remap imported builtin locations to import loc (#1305)#1850
0takuc0mrade wants to merge 2 commits intohyperledger-solang:mainfrom
0takuc0mrade:fix/builtin-note-without-file-position

Conversation

@0takuc0mrade
Copy link
Copy Markdown

Summary

Fixes #1305 by preventing diagnostic panics caused by Loc::Builtin notes when importing target builtins.

Problem

When builtin symbols are imported (for example from import "polkadot";) and then collide with user-defined symbols (for example chain_extension), diagnostics may include notes with Loc::Builtin.

Diagnostic rendering expects note locations to be file-backed (Loc::File) and could panic with:

internal error: entered unreachable code: note without file position

What Changed

  • Added replace_builtin_loc(symbol, import_loc) in src/sema/mod.rs.
  • In resolve_import, wrapped imported symbols with this helper before ns.add_symbol() for:
    • pt::Import::Rename
    • pt::Import::Plain
  • replace_builtin_loc rewrites Loc::Builtin entries to the import statement location (import_loc) while leaving non-builtin locations unchanged.

Behavior Change

Before:

  • Diagnostics could panic when a note referenced Loc::Builtin.

After:

  • Diagnostics no longer panic.
  • Notes for imported builtin symbols are anchored to the import statement location in the source file.

Scope / Safety

  • Change is limited to import resolution (resolve_import).
  • Only Loc::Builtin is remapped; all existing Loc::File locations are preserved.
  • No semantic behavior changes outside diagnostic location mapping.

Validation

  • Reproduced the collision scenario with imported builtin symbols.
  • Confirmed panic is avoided and diagnostics are emitted normally with file-backed note locations.

Signed-off-by: 0takuc0mrade <junep059@gmail.com>
@0takuc0mrade 0takuc0mrade force-pushed the fix/builtin-note-without-file-position branch from 3da2275 to 795921e Compare February 28, 2026 14:31
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

Successfully merging this pull request may close these issues.

1 participant