imports: dedup flat decl list by node identity (issue 0056 FIXED)
Impl blocks are anonymous (no declName), so a parameterised-protocol impl in a module reached via a diamond import was appended once per path and registered twice — 'duplicate impl Into for source s64'. mergeFlat and the directory-import merge loop now also dedup by node pointer; a physical AST node is lowered once regardless of how many import paths reach it. Regression: examples/issue-0056-diamond-param-impl.sx.
This commit is contained in:
19
examples/issue-0056-diamond-param-impl.sx
Normal file
19
examples/issue-0056-diamond-param-impl.sx
Normal file
@@ -0,0 +1,19 @@
|
||||
// Regression (issue 0056): a parameterised-protocol (`Into`) impl living in a
|
||||
// module reached through more than one import path must register exactly once.
|
||||
//
|
||||
// main ─┬─ issue-0056/mid_a ─┐
|
||||
// └─ issue-0056/mid_b ─┴─ issue-0056/common (holds `impl Into(Wrapped) for s64`)
|
||||
//
|
||||
// Impl blocks are anonymous (no `declName`), so before the fix the diamond
|
||||
// dedup in imports.zig appended the cached node once per path and the second
|
||||
// registration tripped: `duplicate impl 'Into' for source 's64'`. Now the flat
|
||||
// decl list also dedups by node identity, so this builds and prints 7.
|
||||
#import "modules/std.sx";
|
||||
#import "issue-0056/mid_a.sx";
|
||||
#import "issue-0056/mid_b.sx";
|
||||
|
||||
main :: () -> s32 {
|
||||
w : Wrapped = xx 7;
|
||||
print("{}\n", w.v);
|
||||
0;
|
||||
}
|
||||
12
examples/issue-0056/common.sx
Normal file
12
examples/issue-0056/common.sx
Normal file
@@ -0,0 +1,12 @@
|
||||
// A parameterised-protocol (`Into`) impl living in a module reachable through
|
||||
// more than one import path. Each path must NOT re-register the impl.
|
||||
// Impl blocks are anonymous (`declName() == null`), so the diamond-import
|
||||
// dedup in imports.zig (`mergeFlat`) skips them and appends the node once per
|
||||
// path — `registerParamImpl` then trips its same-file duplicate check.
|
||||
Wrapped :: struct { v: s64; }
|
||||
|
||||
impl Into(Wrapped) for s64 {
|
||||
convert :: (self: s64) -> Wrapped {
|
||||
return .{ v = self };
|
||||
}
|
||||
}
|
||||
3
examples/issue-0056/mid_a.sx
Normal file
3
examples/issue-0056/mid_a.sx
Normal file
@@ -0,0 +1,3 @@
|
||||
#import "common.sx";
|
||||
|
||||
mid_a_marker :: () -> s64 { 1; }
|
||||
3
examples/issue-0056/mid_b.sx
Normal file
3
examples/issue-0056/mid_b.sx
Normal file
@@ -0,0 +1,3 @@
|
||||
#import "common.sx";
|
||||
|
||||
mid_b_marker :: () -> s64 { 2; }
|
||||
Reference in New Issue
Block a user