issues: file 0127 — namespaced generic call's result mis-types as the unbound T stub
This commit is contained in:
61
issues/0127-namespaced-generic-call-result-unbound-stub.md
Normal file
61
issues/0127-namespaced-generic-call-result-unbound-stub.md
Normal file
@@ -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).
|
||||
Reference in New Issue
Block a user