Move diagnostic kind name to the end of the diagnostic. (#4437)

Also surround it in square brackets rather than parentheses. This
matches the format used by Clang and GCC, and means diagnostics will
still match the `file:line:col: error: ` pattern used by some IDE tools.

Before:
```console
fail_builtins.carbon:11:11: error(AliasRequiresNameRef): alias initializer must be a name reference
```

After:
```console
fail_builtins.carbon:11:11: error: alias initializer must be a name reference [AliasRequiresNameRef]
```

Also tighten up test regex to only match on `STDERR` lines that list a
file name.
This commit is contained in:
Richard Smith
2024-10-23 16:56:23 +00:00
committed by GitHub
parent f206072216
commit 2e63da1a40
528 changed files with 1929 additions and 1928 deletions
@@ -9,7 +9,7 @@
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/call/fail_not_callable.carbon
fn Run() {
// CHECK:STDERR: fail_not_callable.carbon:[[@LINE+3]]:16: error(CallToNonCallable): value of type `String` is not callable
// CHECK:STDERR: fail_not_callable.carbon:[[@LINE+3]]:16: error: value of type `String` is not callable [CallToNonCallable]
// CHECK:STDERR: var x: i32 = "hello"();
// CHECK:STDERR: ^~~~~~~~
var x: i32 = "hello"();
@@ -13,52 +13,52 @@ fn Run1(a: i32) {}
fn Run2(a: i32, b: i32) {}
fn Main() {
// CHECK:STDERR: fail_param_count.carbon:[[@LINE+7]]:3: error(CallArgCountMismatch): 1 argument passed to function expecting 0 arguments
// CHECK:STDERR: fail_param_count.carbon:[[@LINE+7]]:3: error: 1 argument passed to function expecting 0 arguments [CallArgCountMismatch]
// CHECK:STDERR: Run0(1);
// CHECK:STDERR: ^~~~~
// CHECK:STDERR: fail_param_count.carbon:[[@LINE-8]]:1: note(InCallToEntity): calling function declared here
// CHECK:STDERR: fail_param_count.carbon:[[@LINE-8]]:1: note: calling function declared here [InCallToEntity]
// CHECK:STDERR: fn Run0() {}
// CHECK:STDERR: ^~~~~~~~~~~
// CHECK:STDERR:
Run0(1);
// CHECK:STDERR: fail_param_count.carbon:[[@LINE+7]]:3: error(CallArgCountMismatch): 2 arguments passed to function expecting 0 arguments
// CHECK:STDERR: fail_param_count.carbon:[[@LINE+7]]:3: error: 2 arguments passed to function expecting 0 arguments [CallArgCountMismatch]
// CHECK:STDERR: Run0(0, 1);
// CHECK:STDERR: ^~~~~
// CHECK:STDERR: fail_param_count.carbon:[[@LINE-16]]:1: note(InCallToEntity): calling function declared here
// CHECK:STDERR: fail_param_count.carbon:[[@LINE-16]]:1: note: calling function declared here [InCallToEntity]
// CHECK:STDERR: fn Run0() {}
// CHECK:STDERR: ^~~~~~~~~~~
// CHECK:STDERR:
Run0(0, 1);
// CHECK:STDERR: fail_param_count.carbon:[[@LINE+7]]:3: error(CallArgCountMismatch): 0 arguments passed to function expecting 1 argument
// CHECK:STDERR: fail_param_count.carbon:[[@LINE+7]]:3: error: 0 arguments passed to function expecting 1 argument [CallArgCountMismatch]
// CHECK:STDERR: Run1();
// CHECK:STDERR: ^~~~~
// CHECK:STDERR: fail_param_count.carbon:[[@LINE-24]]:1: note(InCallToEntity): calling function declared here
// CHECK:STDERR: fail_param_count.carbon:[[@LINE-24]]:1: note: calling function declared here [InCallToEntity]
// CHECK:STDERR: fn Run1(a: i32) {}
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~
// CHECK:STDERR:
Run1();
// CHECK:STDERR: fail_param_count.carbon:[[@LINE+7]]:3: error(CallArgCountMismatch): 2 arguments passed to function expecting 1 argument
// CHECK:STDERR: fail_param_count.carbon:[[@LINE+7]]:3: error: 2 arguments passed to function expecting 1 argument [CallArgCountMismatch]
// CHECK:STDERR: Run1(0, 1);
// CHECK:STDERR: ^~~~~
// CHECK:STDERR: fail_param_count.carbon:[[@LINE-32]]:1: note(InCallToEntity): calling function declared here
// CHECK:STDERR: fail_param_count.carbon:[[@LINE-32]]:1: note: calling function declared here [InCallToEntity]
// CHECK:STDERR: fn Run1(a: i32) {}
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~
// CHECK:STDERR:
Run1(0, 1);
// CHECK:STDERR: fail_param_count.carbon:[[@LINE+7]]:3: error(CallArgCountMismatch): 0 arguments passed to function expecting 2 arguments
// CHECK:STDERR: fail_param_count.carbon:[[@LINE+7]]:3: error: 0 arguments passed to function expecting 2 arguments [CallArgCountMismatch]
// CHECK:STDERR: Run2();
// CHECK:STDERR: ^~~~~
// CHECK:STDERR: fail_param_count.carbon:[[@LINE-40]]:1: note(InCallToEntity): calling function declared here
// CHECK:STDERR: fail_param_count.carbon:[[@LINE-40]]:1: note: calling function declared here [InCallToEntity]
// CHECK:STDERR: fn Run2(a: i32, b: i32) {}
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR:
Run2();
// CHECK:STDERR: fail_param_count.carbon:[[@LINE+6]]:3: error(CallArgCountMismatch): 1 argument passed to function expecting 2 arguments
// CHECK:STDERR: fail_param_count.carbon:[[@LINE+6]]:3: error: 1 argument passed to function expecting 2 arguments [CallArgCountMismatch]
// CHECK:STDERR: Run2(0);
// CHECK:STDERR: ^~~~~
// CHECK:STDERR: fail_param_count.carbon:[[@LINE-48]]:1: note(InCallToEntity): calling function declared here
// CHECK:STDERR: fail_param_count.carbon:[[@LINE-48]]:1: note: calling function declared here [InCallToEntity]
// CHECK:STDERR: fn Run2(a: i32, b: i32) {}
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
Run2(0);
@@ -11,13 +11,13 @@
fn G(a: i32) {}
fn F() {
// CHECK:STDERR: fail_param_type.carbon:[[@LINE+9]]:5: error(ImplicitAsConversionFailure): cannot implicitly convert from `f64` to `i32`
// CHECK:STDERR: fail_param_type.carbon:[[@LINE+9]]:5: error: cannot implicitly convert from `f64` to `i32` [ImplicitAsConversionFailure]
// CHECK:STDERR: G(1.0);
// CHECK:STDERR: ^~~
// CHECK:STDERR: fail_param_type.carbon:[[@LINE+6]]:5: note(MissingImplInMemberAccessNote): type `f64` does not implement interface `ImplicitAs`
// CHECK:STDERR: fail_param_type.carbon:[[@LINE+6]]:5: note: type `f64` does not implement interface `ImplicitAs` [MissingImplInMemberAccessNote]
// CHECK:STDERR: G(1.0);
// CHECK:STDERR: ^~~
// CHECK:STDERR: fail_param_type.carbon:[[@LINE-9]]:6: note(InCallToFunctionParam): initializing function parameter
// CHECK:STDERR: fail_param_type.carbon:[[@LINE-9]]:6: note: initializing function parameter [InCallToFunctionParam]
// CHECK:STDERR: fn G(a: i32) {}
// CHECK:STDERR: ^~~~~~
G(1.0);
@@ -11,10 +11,10 @@
fn Foo() -> f64 { return 1.0; }
fn Run() {
// CHECK:STDERR: fail_return_type_mismatch.carbon:[[@LINE+6]]:3: error(ImplicitAsConversionFailure): cannot implicitly convert from `f64` to `i32`
// CHECK:STDERR: fail_return_type_mismatch.carbon:[[@LINE+6]]:3: error: cannot implicitly convert from `f64` to `i32` [ImplicitAsConversionFailure]
// CHECK:STDERR: var x: i32 = Foo();
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~
// CHECK:STDERR: fail_return_type_mismatch.carbon:[[@LINE+3]]:3: note(MissingImplInMemberAccessNote): type `f64` does not implement interface `ImplicitAs`
// CHECK:STDERR: fail_return_type_mismatch.carbon:[[@LINE+3]]:3: note: type `f64` does not implement interface `ImplicitAs` [MissingImplInMemberAccessNote]
// CHECK:STDERR: var x: i32 = Foo();
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~
var x: i32 = Foo();
@@ -8,7 +8,7 @@
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/call/no_prelude/fail_explicit_self_param.carbon
// CHECK:STDERR: fail_explicit_self_param.carbon:[[@LINE+3]]:6: error(SelfOutsideImplicitParamList): `self` can only be declared in an implicit parameter list
// CHECK:STDERR: fail_explicit_self_param.carbon:[[@LINE+3]]:6: error: `self` can only be declared in an implicit parameter list [SelfOutsideImplicitParamList]
// CHECK:STDERR: fn F(self: ());
// CHECK:STDERR: ^~~~~~~~
fn F(self: ());
@@ -8,7 +8,7 @@
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/call/no_prelude/fail_runtime_implicit_param.carbon
// CHECK:STDERR: fail_runtime_implicit_param.carbon:[[@LINE+3]]:6: error(ImplictParamMustBeConstant): implicit parameters of functions must be constant or `self`
// CHECK:STDERR: fail_runtime_implicit_param.carbon:[[@LINE+3]]:6: error: implicit parameters of functions must be constant or `self` [ImplictParamMustBeConstant]
// CHECK:STDERR: fn F[s: ()]();
// CHECK:STDERR: ^~~~~
fn F[s: ()]();