From 70363dda56f2d3e78542a3c1744a68f8e30a592f Mon Sep 17 00:00:00 2001 From: agra Date: Fri, 12 Jun 2026 08:40:45 +0300 Subject: [PATCH] =?UTF-8?q?issues:=20file=200127=20=E2=80=94=20namespaced?= =?UTF-8?q?=20generic=20call's=20result=20mis-types=20as=20the=20unbound?= =?UTF-8?q?=20T=20stub?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...spaced-generic-call-result-unbound-stub.md | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 issues/0127-namespaced-generic-call-result-unbound-stub.md diff --git a/issues/0127-namespaced-generic-call-result-unbound-stub.md b/issues/0127-namespaced-generic-call-result-unbound-stub.md new file mode 100644 index 0000000..df9e7f7 --- /dev/null +++ b/issues/0127-namespaced-generic-call-result-unbound-stub.md @@ -0,0 +1,61 @@ +# 0127: namespaced generic call's result mis-types as the unbound `T` stub + +## Symptom + +A NAMESPACED call to a generic free function returns a value typed as the +unbound `T` empty-struct stub instead of the bound concrete type. + +- **Observed**: `print("{}\n", m.pick(3, 9))` prints `T{}` — the Any boxing + tags the result with the unbound `T` stub type. +- **Expected**: prints `9`. + +The same call through a FLAT import (`pick(3, 9)`) prints `9` — only the +namespaced spelling (`field_access` callee whose object is a namespace +alias) mis-types the result. + +## Reproduction + +m.sx: + +```sx +#import "modules/std.sx"; + +pick :: (a: $T, b: T) -> T { + if a > b then a else b +} +``` + +main.sx: + +```sx +#import "modules/std.sx"; +m :: #import "m.sx"; + +main :: () { + print("{}\n", m.pick(3, 9)); +} +``` + +Observed at master 309f48e: prints `T{}`. The flat-import spelling of the +same call prints `9`. + +## Investigation prompt + +Suspected area: the namespaced/qualified dispatch leg in +`src/ir/lower/call.zig` `lowerCall` (the qualified `fn_ast_map` paths) +and/or the generic return-type inference not being consulted for the +namespaced callee shape. The plain-identifier path routes the call's +result typing through `buildTypeBindings` (the one binding builder — +see a47ea14's note); the namespaced path appears to stamp the declared +return type (`T`) without substituting the call's inferred bindings, so +the result carries the unbound-`T` stub struct into Any boxing. + +Fix: make the namespaced generic call derive its result type from the +call's inferred `$T → concrete` bindings exactly like the flat path. +Check whether the value itself is computed correctly (the mono body) and +only the recorded result TYPE is wrong, or whether dispatch skipped +monomorphization entirely. + +Verification: the repro prints `9`; the flat spelling still prints `9`; +`zig build && zig build test`, `bash tests/run_examples.sh` green; pin +the repro as a generics example (next free 02xx number).