issue 0153 RESOLVED: pin generic return-type resolution to the fn's defining module
inferGenericReturnType resolved a generic call's return-type AST ($R, !E) in the CALL-SITE module context. For a re-exported fn the error-set name (LE / IoErr, re-exported as LE :: lib.LE) resolved through the call-site alias to a TypeId NOT tagged .error_set, so the planned result was a tuple whose last field wasn't an error set — errorChannelOf saw a plain tuple and the value- failable's ! channel was lost (try/or rejected it / built a malformed i1 PHI). monomorphizeFunction already pins the source to the fn's defining module before resolving the return type; inferGenericReturnType did not, so the planned call-result type disagreed with the instance's real signature. Fix: pin the source to fd.body.source_file around the return-type resolution (binding-build stays in the call-site context — its args are typed there). Regression test examples/1058-errors-reexport-value-failable-channel.sx (+ companion lib.sx). Suite green 732/0.
This commit is contained in:
@@ -284,6 +284,18 @@ pub const GenericResolver = struct {
|
||||
// tag.
|
||||
var scope = TypeBindingScope.enter(self.l, tmp_bindings);
|
||||
defer scope.exit();
|
||||
// Resolve the return type in the function's DEFINING module, exactly
|
||||
// as `monomorphizeFunction` does — so a name in the return type (e.g.
|
||||
// the error set of a value-failable `(… , !E)`) resolves to the SAME
|
||||
// TypeId the instance's real signature uses, not whatever a re-export
|
||||
// alias at the call site resolves it to. Without this pin a re-exported
|
||||
// generic value-failable's `!E` resolved to a non-`.error_set` alias,
|
||||
// so the planned call result was a plain tuple and `errorChannelOf`
|
||||
// missed the failable channel (issue 0153). The binding-building above
|
||||
// stays in the call-site context (its args are typed there).
|
||||
const saved_src = self.l.current_source_file;
|
||||
defer self.l.setCurrentSourceFile(saved_src);
|
||||
if (fd.body.source_file) |src| self.l.setCurrentSourceFile(src);
|
||||
return self.l.resolveTypeWithBindings(fd.return_type.?);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user