Sema: do not emit generic poison for non generic parameters

Closes #12679
This commit is contained in:
Veikka Tuominen 2022-08-30 14:40:48 +03:00 committed by Andrew Kelley
parent 67a44211f7
commit 01d19a8d3c
2 changed files with 32 additions and 2 deletions

View File

@ -8195,8 +8195,22 @@ fn zirParam(
.is_comptime = comptime_syntax,
.name = param_name,
});
const result = try sema.addConstant(param_ty, Value.initTag(.generic_poison));
try sema.inst_map.putNoClobber(sema.gpa, inst, result);
if (is_comptime) {
// If this is a comptime parameter we can add a constant generic_poison
// since this is also a generic parameter.
const result = try sema.addConstant(param_ty, Value.initTag(.generic_poison));
try sema.inst_map.putNoClobber(sema.gpa, inst, result);
} else {
// Otherwise we need a dummy runtime instruction.
const result_index = @intCast(Air.Inst.Index, sema.air_instructions.len);
try sema.air_instructions.append(sema.gpa, .{
.tag = .alloc,
.data = .{ .ty = param_ty },
});
const result = Air.indexToRef(result_index);
try sema.inst_map.putNoClobber(sema.gpa, inst, result);
}
}
fn zirParamAnytype(

View File

@ -0,0 +1,16 @@
export fn entry() void {
const llamas1 = makeLlamas(5);
const llamas2 = makeLlamas(5);
_ = llamas1;
_ = llamas2;
}
fn makeLlamas(count: usize) [count]u8 {
_ = count;
}
// error
// target=native
//
// :8:30: error: unable to resolve comptime value
// :8:30: note: array length must be comptime known