Repository navigation
fix(hy-check): reject fmt.eprint* when os is shadowed (fixes #3598) - #3614
Conversation
|
Landed in 70c4f08 via merge --no-ff. Verification (FULL battery, ALL-GREEN): merge gate clean vs bfe8a14; Before landing I audited One honest note: the merge commit message lost two short fragments (an Bounty: tracked on BOUNTY.md / discussion #295 rails. CREDIT: @dextermos-dev |
…et/post, pin E11 ? propagation (fixes #3789) (bradwue313) buildable.rs: httptest.get/post calls now reject when `strings` or `http` is shadowed by an in-scope declaration (HYB-E1002 at the call span, is_pkg_symbol_shadowed) — both lower to strings.TrimSuffix / http.NewRequest (Row 13 BUILDABLE, following the #3598/#3614/#3727 shadow-package pattern). New suite shadowed_httptest_and_e11_handler_3789 (7 tests) also pins the existing E11 ? propagation behavior: shadowed `http` or response-writer param at a ? site inside http.handler rejects with HYB-E2011; unshadowed positive control accepts. In-merge fixture fixup (credited): the PR's patch replaced 10 UTF-8 arrows in unrelated doc comments (8 x U+2192, 2 x U+2194 -> literal ?) and appended a stray EOF blank line; all restored byte-identical to prior main inside this merge. Net change: +25 check lines + 85-line test file only. Verification (battery on trial-merge worktree vs main @ 973453c): merge-gate CLEAN; cargo test --workspace 457 suites ok; corpus 135/135 tripwire not fired; differential 45/45 accept + 90/90 reject FULL AGREEMENT. CREDIT: @bradwue313
Overview
Fixes #3598.
Under GUARANTEES.md Row 13 (BUILDABLE), programs accepted by
hy-checkmust emit buildable Go code.In
hy-emit(crates/hy-emit/src/expr.rs),fmt.eprintln,fmt.eprint, andfmt.eprintflower tofmt.Fprint*(os.Stderr, ...).When
osis shadowed by an in-scope parameter, local binding, loop variable, closure argument, generic type parameter, or package-level declaration (const, fn, struct, enum, type alias), the emitted Go code resolvesos.Stderrto the shadowing entity, causing downstreamgo buildto fail withos.Stderr undefined.Changes
crates/hy-check/src/buildable.rs:check_call_operands, when checking calls tofmt.eprint,fmt.eprintln, andfmt.eprintf:osis shadowed usingis_os_shadowed().HYB-E1002:cannot call fmt.<name> because os is shadowed by an in-scope declaration (HYB-E1002)is_os_shadowed(&self) -> boolcovering::=,let,var), loop variables, closure arguments.self.fn_type_params.contains("os")).self.ck.pkg_names.contains_key("os"),self.file_consts,self.file_untyped_consts).self.lookup_kind("os")).crates/hy-check/tests/issue_3598_eprint_os_shadowing.rs:Comprehensive test suite with 15 test cases covering:
os string-> rejectsHYB-E1002os := "darwin"-> rejectsHYB-E1002os intoneprintf-> rejectsHYB-E1002const os = "linux"-> rejectsHYB-E1002fn os() {}-> rejectsHYB-E1002struct os { version int }-> rejectsHYB-E1002enum os { linux, darwin }-> rejectsHYB-E1002type os = string-> rejectsHYB-E1002fn test[os any]()-> rejectsHYB-E1002fn (os *machine) report_error()-> rejectsHYB-E1002cb := fn(os string)-> rejectsHYB-E1002for os in items-> rejectsHYB-E1002fmt.eprint*-> cleanly acceptedimport "os"withfmt.eprintln-> cleanly accepted{ os := ... }with outerfmt.eprintln-> cleanly accepted without false positivesVerification
Settlement Wallet (Base L2 USDC):
0x8366bCe3a2D379De7656D7A67015789FaF999f20