w6c+selfhost: cross-module same-leaf type disambiguation via Sym.mod
This commit is contained in:
8
test/wcc/data/modcollision/mod1/mod1.ww
Normal file
8
test/wcc/data/modcollision/mod1/mod1.ww
Normal file
@@ -0,0 +1,8 @@
|
||||
// modcollision/mod1 — exports `type stream` with mod1-shaped fields.
|
||||
// Paired with mod2/mod2.ww to exercise same-leaf-name cross-module
|
||||
// type disambiguation. Test driver: 696_modtype_leaf_collision.c.
|
||||
|
||||
export type stream = struct {
|
||||
a: i32,
|
||||
b: i32,
|
||||
};
|
||||
12
test/wcc/data/modcollision/mod2/mod2.ww
Normal file
12
test/wcc/data/modcollision/mod2/mod2.ww
Normal file
@@ -0,0 +1,12 @@
|
||||
// modcollision/mod2 — exports `type stream` with mod2-shaped fields.
|
||||
// Paired with mod1/mod1.ww to exercise same-leaf-name cross-module
|
||||
// type disambiguation. Test driver: 696_modtype_leaf_collision.c.
|
||||
//
|
||||
// Fields are intentionally named distinctly from mod1's (c/d vs a/b)
|
||||
// so the negative test (`b: mod1.stream` accessed via mod2-only field
|
||||
// 'c') surfaces as a compile-time field-resolution error.
|
||||
|
||||
export type stream = struct {
|
||||
c: i32,
|
||||
d: i32,
|
||||
};
|
||||
19
test/wcc/data/modcollision/neg.ww
Normal file
19
test/wcc/data/modcollision/neg.ww
Normal file
@@ -0,0 +1,19 @@
|
||||
// Negative case: declare `b: mod1.stream` then access a mod2-only
|
||||
// field. With the mod-tagged scope lookup `b` resolves to mod1.stream
|
||||
// (fields a, b), so the field access `b.c` must be a compile-time
|
||||
// error rather than silently binding to mod2.stream and succeeding.
|
||||
//
|
||||
// No cross-module call is made: a missing mod1.make would itself
|
||||
// trigger a link-time error that could mask the field-resolution
|
||||
// error this test is actually pinning. `let b: mod1.stream;` is
|
||||
// enough — we read b.c before initializing it, which is fine because
|
||||
// the field-resolution error fires at check, long before any reach
|
||||
// analysis or codegen runs.
|
||||
|
||||
use mod1;
|
||||
use mod2;
|
||||
|
||||
fn main() i32 = {
|
||||
let b: mod1.stream;
|
||||
return b.c; // mod1.stream has no `c`; expect a compile error.
|
||||
};
|
||||
18
test/wcc/data/modcollision/pos.ww
Normal file
18
test/wcc/data/modcollision/pos.ww
Normal file
@@ -0,0 +1,18 @@
|
||||
// Positive case: two modules each export `type stream`. The consumer
|
||||
// imports both and disambiguates via the module qualifier. mod1.stream
|
||||
// has fields (a, b); mod2.stream has fields (c, d). The exit code
|
||||
// encodes a sum of all four fields, so any cross-binding would either
|
||||
// fail to compile or return the wrong value.
|
||||
|
||||
use mod1;
|
||||
use mod2;
|
||||
|
||||
fn main() i32 = {
|
||||
let s1: mod1.stream;
|
||||
s1.a = 3: i32;
|
||||
s1.b = 5: i32;
|
||||
let s2: mod2.stream;
|
||||
s2.c = 7: i32;
|
||||
s2.d = 11: i32;
|
||||
return s1.a + s1.b + s2.c + s2.d;
|
||||
};
|
||||
Reference in New Issue
Block a user