You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
use (Zig backend): an importer's constant silently replaces a same-named constant the imported function reads #8342
When a spec imports a function with use, the Zig backend copies the function and the constants it reads into the importer. If the importer declares a constant of the same name, the copy is dropped and the imported function silently reads the importer's value. A test that calls the imported function then checks a function that does not exist in its home module.
This breaks the pattern used to prove a restated rule equal to its home (use queen::actors::... in a test, as specs/queen/reviewer_sizing.t27 does): if the importer happens to restate a constant under the same name, a wrong value can pass, and a right one can fail, for a reason no line of either spec shows.
#7380 is the gen-c form of a neighbouring problem (an imported #define capturing a local); this one is the Zig backend and test-report, and it changes a value without any error.
See #5980. Found while building specs/queen/actors_hw.t27 (#8336), which names every restated constant HW_ for this reason.
Reproducer
module ImportShadow;
use queen::actors::jittered_seconds;
/// Same name as a constant jittered_seconds reads; nothing in this file uses it.
pub const JITTER_PERCENT : u32 = 50;
test the_imported_function_keeps_its_own_constant {
// actors.t27 pins this second: slot 1 draws the whole 20 per cent
assert jittered_seconds(300, 1) == 240;
}
t27c test-report import_shadow.t27: FAIL the_imported_function_keeps_its_own_constant. The imported jittered_seconds computes with JITTER_PERCENT = 50 (spread 150, so 300 - 40503 % 151 = 265) instead of actors.t27's 20 (240).
Expected
An imported function reads its own module's declarations. Either the splice keeps the imported constant under a module-qualified name, or test-report refuses the spec when an imported dependency and a local declaration share a name, as a compile error that names both.
User Scenarios
Given a spec imports a function via use from another module, and the importer declares a constant with the same name as a constant the imported function reads in its home module, when the test executes the imported function, then the function must compute using its home module's constant value, not the importer's shadowing constant.
Requirements
FR-001: The Zig backend MUST preserve each imported function's original constant bindings when copying the function into the importer.
FR-002: The Zig backend MUST either rename imported constants to module-qualified names during the splice, or reject the spec at compile time with an error that names both the imported dependency and the local declaration that share a name.
FR-003: Test-report MUST execute imported functions against their home module's constant values, so that a restated rule proven equal in its home module remains proven when used via use in a test spec.
The reproducer pattern from the issue (import_shadow.t27) passes: assert jittered_seconds(300, 1) == 240 with the importer's JITTER_PERCENT = 50 present but ignored
Activity