fix(lower): free-fn UFCS auto-address-of + lazy lowering (issue 0063)
A free function called via UFCS (recv.fn(args)) whose first param is *T was passed the receiver by value (LLVM "Call parameter type does not match function signature"), and a function reached only via UFCS was declared but never emitted (undefined symbol at link). The bare-name UFCS fallback now mirrors the qualified-method path: it lazily lowers the target body and calls fixupMethodReceiver + coerceCallArgs, so the value receiver gets the same implicit address-of as a struct-defined method and mutations through *T are visible. Regression: 0039-basic-free-fn-ufcs-pointer-receiver.sx.
This commit is contained in:
26
examples/0039-basic-free-fn-ufcs-pointer-receiver.sx
Normal file
26
examples/0039-basic-free-fn-ufcs-pointer-receiver.sx
Normal file
@@ -0,0 +1,26 @@
|
||||
// Free-function UFCS with a pointer first-param (issue 0063). `recv.fn(args)`
|
||||
// on a value `recv` whose matching free function takes `*T` now takes the
|
||||
// receiver's address (the same implicit address-of as a struct-defined method),
|
||||
// so mutations through the pointer are visible. Also: a function reached ONLY
|
||||
// via UFCS is lazily lowered (previously declared-but-never-emitted → undefined
|
||||
// symbol at link).
|
||||
|
||||
#import "modules/std.sx";
|
||||
|
||||
Counter :: struct { n: s32; }
|
||||
|
||||
// FREE functions (defined outside the struct), pointer first param.
|
||||
bump :: (c: *Counter) -> s32 { c.n += 1; return c.n; }
|
||||
// reached ONLY via UFCS — must still be emitted.
|
||||
reset :: (c: *Counter) { c.n = 0; }
|
||||
|
||||
main :: () -> s32 {
|
||||
c := Counter.{ n = 10 };
|
||||
a := c.bump(); // 11, mutates c
|
||||
b := c.bump(); // 12
|
||||
print("a={} b={} n={}\n", a, b, c.n); // a=11 b=12 n=12
|
||||
|
||||
c.reset(); // UFCS-only free fn
|
||||
print("after reset n={}\n", c.n); // after reset n=0
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
0
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
a=11 b=12 n=12
|
||||
after reset n=0
|
||||
Reference in New Issue
Block a user