diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-12-27 19:39:28 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-12-27 19:39:28 -0700 |
| commit | 6ed7850972c5d74912e6802474564de332ecf0d9 (patch) | |
| tree | 21f6e28332d2abeaebbf75088a4b8af6542c72f7 /src | |
| parent | fc1a5cd9e74faf19e5974c733b0bcd9444d48b7b (diff) | |
| download | zig-6ed7850972c5d74912e6802474564de332ecf0d9.tar.gz zig-6ed7850972c5d74912e6802474564de332ecf0d9.zip | |
Sema: fix anytype parameters whose types require comptime
Diffstat (limited to 'src')
| -rw-r--r-- | src/Sema.zig | 22 | ||||
| -rw-r--r-- | src/type.zig | 1 |
2 files changed, 14 insertions, 9 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index 8d27553f94..544681f5f9 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -4187,10 +4187,17 @@ fn analyzeCall( return sema.failWithNeededComptime(block, arg_src); } } else if (is_anytype) { - // We insert into the map an instruction which is runtime-known - // but has the type of the argument. - const child_arg = try child_block.addArg(sema.typeOf(arg), 0); - child_sema.inst_map.putAssumeCapacityNoClobber(inst, child_arg); + const arg_ty = sema.typeOf(arg); + if (arg_ty.requiresComptime()) { + const arg_val = try sema.resolveConstValue(block, arg_src, arg); + const child_arg = try child_sema.addConstant(arg_ty, arg_val); + child_sema.inst_map.putAssumeCapacityNoClobber(inst, child_arg); + } else { + // We insert into the map an instruction which is runtime-known + // but has the type of the argument. + const child_arg = try child_block.addArg(arg_ty, 0); + child_sema.inst_map.putAssumeCapacityNoClobber(inst, child_arg); + } } arg_i += 1; } @@ -5130,9 +5137,8 @@ fn funcCommon( const comptime_params = try sema.arena.alloc(bool, block.params.items.len); for (block.params.items) |param, i| { param_types[i] = param.ty; - comptime_params[i] = param.is_comptime; - is_generic = is_generic or param.is_comptime or - param.ty.tag() == .generic_poison or param.ty.requiresComptime(); + comptime_params[i] = param.is_comptime or param.ty.requiresComptime(); + is_generic = is_generic or comptime_params[i] or param.ty.tag() == .generic_poison; } if (align_val.tag() != .null_value) { @@ -13146,7 +13152,7 @@ fn coerceInMemoryAllowedFns( return .no_match; } - // TODO: nolias + // TODO: noalias // Note: Cast direction is reversed here. const param = try sema.coerceInMemoryAllowed(block, src_param_ty, dest_param_ty, false, target, dest_src, src_src); diff --git a/src/type.zig b/src/type.zig index 1482710e51..fb543e1f2c 100644 --- a/src/type.zig +++ b/src/type.zig @@ -4275,7 +4275,6 @@ pub const Type = extern union { is_generic: bool, pub fn paramIsComptime(self: @This(), i: usize) bool { - if (!self.is_generic) return false; assert(i < self.param_types.len); return self.comptime_params[i]; } |
