aboutsummaryrefslogtreecommitdiff
path: root/test/compile_errors.zig
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2025-01-05 05:27:48 +0000
committermlugg <mlugg@mlugg.co.uk>2025-01-09 06:46:47 +0000
commite9bd2d45d4bbaf7eff7e95bc3ef7a0123b66a103 (patch)
treeda18bc40935c7dd9698d792eae3d102fa0ad67ae /test/compile_errors.zig
parent3f95003d4c57650f9b4779f55c8d7368b137337c (diff)
downloadzig-e9bd2d45d4bbaf7eff7e95bc3ef7a0123b66a103.tar.gz
zig-e9bd2d45d4bbaf7eff7e95bc3ef7a0123b66a103.zip
Sema: rewrite semantic analysis of function calls
This rewrite improves some error messages, hugely simplifies the logic, and fixes several bugs. One of these bugs is technically a new rule which Andrew and I agreed on: if a parameter has a comptime-only type but is not declared `comptime`, then the corresponding call argument should not be *evaluated* at comptime; only resolved. Implementing this required changing how function types work a little, which in turn required allowing a new kind of function coercion for some generic use cases: function coercions are now allowed to implicitly *remove* `comptime` annotations from parameters with comptime-only types. This is okay because removing the annotation affects only the call site. Resolves: #22262
Diffstat (limited to 'test/compile_errors.zig')
-rw-r--r--test/compile_errors.zig15
1 files changed, 9 insertions, 6 deletions
diff --git a/test/compile_errors.zig b/test/compile_errors.zig
index f566464bac..13d97ba256 100644
--- a/test/compile_errors.zig
+++ b/test/compile_errors.zig
@@ -57,8 +57,9 @@ pub fn addCases(ctx: *Cases, b: *std.Build) !void {
\\}
, &[_][]const u8{
":3:12: error: unable to resolve comptime value",
- ":2:55: note: generic function instantiated with comptime-only return type '?fn () void' is evaluated at comptime",
- ":2:55: note: use '*const fn () void' for a function pointer type",
+ ":3:19: note: call to generic function instantiated with comptime-only return type '?fn () void' is evaluated at comptime",
+ ":2:55: note: return type declared here",
+ ":3:19: note: use '*const fn () void' for a function pointer type",
});
case.addSourceFile("b.zig",
\\pub const ElfDynLib = struct {
@@ -193,10 +194,12 @@ pub fn addCases(ctx: *Cases, b: *std.Build) !void {
\\ import.anytypeFunction(S{ .x = x, .y = u32 });
\\}
, &[_][]const u8{
- ":4:33: error: runtime-known argument passed to comptime parameter",
- ":1:38: note: declared comptime here",
- ":8:36: error: runtime-known argument passed to comptime parameter",
- ":2:41: note: declared comptime here",
+ ":4:33: error: unable to resolve comptime value",
+ ":4:33: note: argument to comptime parameter must be comptime-known",
+ ":1:29: note: parameter declared comptime here",
+ ":8:36: error: unable to resolve comptime value",
+ ":8:36: note: argument to comptime parameter must be comptime-known",
+ ":2:32: note: parameter declared comptime here",
":13:32: error: unable to resolve comptime value",
":13:32: note: initializer of comptime-only struct 'tmp.callAnytypeFunctionWithRuntimeComptimeOnlyType.S' must be comptime-known",
":12:35: note: struct requires comptime because of this field",