@@ -20048,10 +20048,14 @@ fn arrayInitAnon(
20048
20048
const types = try sema.arena.alloc(InternPool.Index, operands.len);
20049
20049
const values = try sema.arena.alloc(InternPool.Index, operands.len);
20050
20050
20051
+ var any_comptime = false;
20051
20052
const opt_runtime_src = rs: {
20052
20053
var runtime_src: ?LazySrcLoc = null;
20053
20054
for (operands, 0..) |operand, i| {
20054
- const operand_src = src; // TODO better source location
20055
+ const operand_src = block.src(.{ .init_elem = .{
20056
+ .init_node_offset = src.offset.node_offset.x,
20057
+ .elem_index = @intCast(i),
20058
+ } });
20055
20059
const elem = try sema.resolveInst(operand);
20056
20060
types[i] = sema.typeOf(elem).toIntern();
20057
20061
if (Type.fromInterned(types[i]).zigTypeTag(zcu) == .@"opaque") {
@@ -20066,6 +20070,7 @@ fn arrayInitAnon(
20066
20070
}
20067
20071
if (try sema.resolveValue(elem)) |val| {
20068
20072
values[i] = val.toIntern();
20073
+ any_comptime = true;
20069
20074
} else {
20070
20075
values[i] = .none;
20071
20076
runtime_src = operand_src;
@@ -20074,9 +20079,21 @@ fn arrayInitAnon(
20074
20079
break :rs runtime_src;
20075
20080
};
20076
20081
20082
+ // A field can't be `comptime` if it references a `comptime var` but the aggregate can still be comptime-known.
20083
+ // Replace these fields with `.none` only for generating the type.
20084
+ const values_no_comptime = if (!any_comptime) values else blk: {
20085
+ const new_values = try sema.arena.alloc(InternPool.Index, operands.len);
20086
+ for (values, new_values) |val, *new_val| {
20087
+ if (val != .none and Value.fromInterned(val).canMutateComptimeVarState(zcu)) {
20088
+ new_val.* = .none;
20089
+ } else new_val.* = val;
20090
+ }
20091
+ break :blk new_values;
20092
+ };
20093
+
20077
20094
const tuple_ty: Type = .fromInterned(try ip.getTupleType(gpa, pt.tid, .{
20078
20095
.types = types,
20079
- .values = values ,
20096
+ .values = values_no_comptime ,
20080
20097
}));
20081
20098
20082
20099
const runtime_src = opt_runtime_src orelse {
@@ -20086,6 +20103,14 @@ fn arrayInitAnon(
20086
20103
20087
20104
try sema.requireRuntimeBlock(block, src, runtime_src);
20088
20105
20106
+ for (operands, 0..) |operand, i| {
20107
+ const operand_src = block.src(.{ .init_elem = .{
20108
+ .init_node_offset = src.offset.node_offset.x,
20109
+ .elem_index = @intCast(i),
20110
+ } });
20111
+ try sema.validateRuntimeValue(block, operand_src, try sema.resolveInst(operand));
20112
+ }
20113
+
20089
20114
if (is_ref) {
20090
20115
const target = sema.pt.zcu.getTarget();
20091
20116
const alloc_ty = try pt.ptrTypeSema(.{
0 commit comments