lang F1 2.5: contextual typing for multi-param closure literals
An untyped lambda (a, b, c) => ... now takes each param's type positionally from the expected Closure(T0, T1, T2) -> R signature, for heterogeneous param types, in both assignment and argument position. Previously only the first param (or all-same-typed params) resolved: lowerLambda's signature loop applied contextual typing into params, but the return-type-inference temp scope and the body param binding both re-resolved each param via resolveParamType -- which defaults an untyped (inferred_type) param to s64. So b in Closure(s64, string) bound as s64 and b.len errored. Both sites now read the already-resolved signature types params.items[user_param_base + i].ty (user_param_base skips the pre-populated ctx/env slots). Regression: examples/201-closure-contextual-params.sx. Note: a generic return $R inferred through a closure-typed parameter is still unresolved (folds into Phase 4 function monomorphization); concrete returns work.
This commit is contained in:
@@ -7098,6 +7098,8 @@ pub const Lowering = struct {
|
||||
}
|
||||
break :blk null;
|
||||
} else null;
|
||||
// User params follow the ctx (optional) + env slots in `params`.
|
||||
const user_param_base: usize = (if (lambda_wants_ctx) @as(usize, 1) else 0) + 1;
|
||||
for (lam.params, 0..) |p, pi| {
|
||||
var pty = self.resolveParamType(&p);
|
||||
// Infer param type from target closure type if no annotation
|
||||
@@ -7136,8 +7138,8 @@ pub const Lowering = struct {
|
||||
var temp_scope = Scope.init(self.alloc, self.scope);
|
||||
const saved = self.scope;
|
||||
self.scope = &temp_scope;
|
||||
for (lam.params) |p| {
|
||||
const pty = self.resolveParamType(&p);
|
||||
for (lam.params, 0..) |p, i| {
|
||||
const pty = params.items[user_param_base + i].ty;
|
||||
temp_scope.put(p.name, .{ .ref = @enumFromInt(0), .ty = pty, .is_alloca = false });
|
||||
}
|
||||
const inferred = self.inferExprType(lam.body);
|
||||
@@ -7210,9 +7212,12 @@ pub const Lowering = struct {
|
||||
}
|
||||
}
|
||||
|
||||
// Bind params (user args start at user_param_base_lam, shifted past ctx + env)
|
||||
// Bind params (user args start at user_param_base_lam, shifted past ctx + env).
|
||||
// Use the signature types computed above (`params`), which already
|
||||
// applied contextual typing from the target closure to untyped params —
|
||||
// `resolveParamType` alone would drop it and default each to s64.
|
||||
for (lam.params, 0..) |p, i| {
|
||||
const pty = self.resolveParamType(&p);
|
||||
const pty = params.items[user_param_base + i].ty;
|
||||
const slot = self.builder.alloca(pty);
|
||||
const param_ref = Ref.fromIndex(user_param_base_lam + @as(u32, @intCast(i)));
|
||||
self.builder.store(slot, param_ref);
|
||||
|
||||
Reference in New Issue
Block a user