feat(opy): complete semantic HIR subroutine resolution - #149
Conversation
Materialize implicit subroutine declarations for def definitions, enforce source-order visibility, and expose stable diagnostics and tooling provenance. Fixes #143
Teakowa
left a comment
There was a problem hiding this comment.
Major — crates/opy-rs/src/lower.rs: current_order is derived from separate program.declarations / program.rules vector indexes, but the parser allows those top-level forms to interleave in source. This makes every declaration appear before every rule/def, so e.g. a rule can incorrectly see a variable/macro/enum declared later, while a macro can incorrectly fail to see a def written earlier. Preserve one top-level source order (or compare source positions) when enforcing visibility.
Minor — crates/opy-rs/src/lower.rs: duplicate global/player/subroutine declarations use HashMap::insert, which replaces the first declaration's order with the duplicate's order. References between the first and duplicate declarations can then produce spurious unknown-identifier/visibility failures in addition to the duplicate diagnostic. Keep the first binding/order when reporting a duplicate.
Keep declaration visibility aligned with interleaved source forms and retain first declaration order when reporting duplicates.
Summary
subroutinedeclarations fordefdefinitions with source spans.Verification
cargo fmt --all -- --checkcargo clippy --workspace --all-targets --all-features -- -D warningscargo test --workspace --all-targets --all-featurespython3 compatibility/run_native.py --binary target/debug/opy-cli --semantic-binary target/debug/opy-compatFixes #143