fix(0111): unannotated decl literals no longer adopt the fn return type
lowerVarDecl (unannotated) and lowerDestructureDecl now clear target_type around the initializer lowering: a declaration without annotation provides no target, so int/float literals take their spec defaults (s64/f64) instead of the enclosing function's implicit-return type (x := 0 in a -> s8 fn was s8; big := 3000000000 in -> s32 silently wrapped to -1294967296). Regression: examples/0173-types-int-literal-default-s64.sx. The remaining explicit-annotation wrap (x : s8 = 300) is filed as issue 0112.
This commit is contained in:
@@ -337,9 +337,15 @@ pub fn lowerVarDecl(self: *Lowering, vd: *const ast.VarDecl) void {
|
||||
// This is critical for generic calls where the return type is only
|
||||
// known after monomorphization.
|
||||
const saved_fbv = self.force_block_value;
|
||||
const saved_target = self.target_type;
|
||||
self.force_block_value = true;
|
||||
// An unannotated decl provides no target type: clear the ambient one
|
||||
// (the enclosing fn's implicit-return target) so literal initializers
|
||||
// take their spec defaults (s64/f64) instead of adopting it.
|
||||
self.target_type = null;
|
||||
const ref = self.lowerExpr(val);
|
||||
self.force_block_value = saved_fbv;
|
||||
self.target_type = saved_target;
|
||||
const ty = self.builder.getRefType(ref);
|
||||
const slot = self.builder.alloca(ty);
|
||||
self.builder.store(slot, ref);
|
||||
@@ -1189,9 +1195,14 @@ pub fn lowerMultiAssign(self: *Lowering, ma: *const ast.MultiAssign) void {
|
||||
pub fn lowerDestructureDecl(self: *Lowering, dd: *const ast.DestructureDecl) void {
|
||||
// Lower the RHS expression (must produce a tuple)
|
||||
const saved_fbv = self.force_block_value;
|
||||
const saved_target = self.target_type;
|
||||
self.force_block_value = true;
|
||||
// Same as the unannotated var-decl path: the destructure declares new
|
||||
// bindings, so the ambient target type must not type the RHS literals.
|
||||
self.target_type = null;
|
||||
const ref = self.lowerExpr(dd.value);
|
||||
self.force_block_value = saved_fbv;
|
||||
self.target_type = saved_target;
|
||||
const ty = self.builder.getRefType(ref);
|
||||
|
||||
// Get tuple field info
|
||||
|
||||
Reference in New Issue
Block a user