Skip to content

fix: REPL name resolution to match lake build context (#149)#151

Open
LarsenClose wants to merge 1 commit intomainfrom
fix/149-repl-name-resolution
Open

fix: REPL name resolution to match lake build context (#149)#151
LarsenClose wants to merge 1 commit intomainfrom
fix/149-repl-name-resolution

Conversation

@LarsenClose
Copy link
Copy Markdown
Owner

Closes #149

Summary

  • split_header_body fix: Removed open, namespace, section, set_option, and variable from the declaration-keyword list that triggers header/body splitting. These context-establishing commands now remain in the REPL header environment, ensuring the REPL sees the same namespace openings, options, and variables that lake build does. Previously, they were placed in the body, causing the cached header env to lack the correct elaboration context.

  • lean_verify file error detection: Changed handle_verify to collect ALL diagnostics (not just from the #print axioms appended region). If the original file has compilation errors (e.g., sorry, unknown identifiers), verification now correctly fails instead of silently passing. File errors are reported with priority over axiom-region errors.

  • Tests: Added 7 new tests for split_header_body covering open, namespace, section, set_option, variable, and combined multi-context scenarios. Added a new handle_verify_detects_file_compilation_errors test. Updated existing verify tests to include range information for correct line-based filtering.

Test plan

  • All existing tests pass (cargo test --all)
  • cargo fmt --all -- --check passes
  • cargo clippy --all-targets -- -D warnings passes
  • RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps passes
  • New test: split_header_body_open_in_header — verifies open stays in header
  • New test: split_header_body_namespace_in_header — verifies namespace stays in header
  • New test: split_header_body_set_option_in_header — verifies set_option stays in header
  • New test: split_header_body_variable_in_header — verifies variable stays in header
  • New test: split_header_body_section_in_header — verifies section stays in header
  • New test: split_header_body_multiple_context_lines — verifies combined context in header
  • New test: handle_verify_detects_file_compilation_errors — verifies file errors block verification

Two root causes of REPL/lake build divergence:

1. split_header_body incorrectly treated open, namespace, section,
   set_option, and variable as body separators. These context-establishing
   commands now remain in the REPL header so the header environment
   includes the same namespace openings, options, and variables that
   lake build sees.

2. lean_verify only checked diagnostics from the #print axioms region,
   ignoring compilation errors in the file itself. A file with errors
   (e.g. sorry, unknown identifiers) could pass verification because
   only the appended #print axioms line was checked. Now collects ALL
   diagnostics and fails if the original file has compilation errors.
@LarsenClose LarsenClose enabled auto-merge (squash) March 22, 2026 20:04
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.

REPL name resolution diverges from lake build

2 participants