diff options
| author | Robin Voetter <robin@voetter.nl> | 2021-12-27 01:22:57 +0100 |
|---|---|---|
| committer | Robin Voetter <robin@voetter.nl> | 2022-01-03 00:19:59 +0100 |
| commit | 41e52bd5ccaccc0191c9f3434098d27ed07f62b7 (patch) | |
| tree | fccb23581898f838afadab135beaf93219cae754 | |
| parent | c710d5eefe3f83226f1651947239730e77af43cb (diff) | |
| download | zig-41e52bd5ccaccc0191c9f3434098d27ed07f62b7.tar.gz zig-41e52bd5ccaccc0191c9f3434098d27ed07f62b7.zip | |
stage2: don't call comptime functions with generic poison arguments
When calling a comptime or inline function, if the parameter is generic and
is resolved to generic_poison or generic_poison_type, the invocation was
part of another function's parameters or return type expression and is
dependent on an as-of-yet type of another parameter. In this case, processing
should stop, and we return error.GenericPoison to let the caller in funcCommon,
zirParam or zirParamAnytype know that the function is generic.
| -rw-r--r-- | src/Sema.zig | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index b65e88360f..9ef3d9d425 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -3888,6 +3888,14 @@ fn analyzeCall( if (is_comptime_call) { const arg_val = try sema.resolveConstMaybeUndefVal(&child_block, arg_src, casted_arg); + switch (arg_val.tag()) { + .generic_poison, .generic_poison_type => { + // This function is currently evaluated as part of an as-of-yet unresolvable + // parameter or return type. + return error.GenericPoison; + }, + else => {}, + } memoized_call_key.args[arg_i] = .{ .ty = param_ty, .val = arg_val, @@ -3905,6 +3913,14 @@ fn analyzeCall( if (is_comptime_call) { const arg_src = call_src; // TODO: better source location const arg_val = try sema.resolveConstMaybeUndefVal(&child_block, arg_src, uncasted_arg); + switch (arg_val.tag()) { + .generic_poison, .generic_poison_type => { + // This function is currently evaluated as part of an as-of-yet unresolvable + // parameter or return type. + return error.GenericPoison; + }, + else => {}, + } memoized_call_key.args[arg_i] = .{ .ty = sema.typeOf(uncasted_arg), .val = arg_val, |
