Render diagnostics through the terminal library (#7683)

Diagnostic rendering was part of the data model: `Loc::FormatLocation`
and
`Loc::FormatSnippet` wrote plain text to a stream, so no capability,
color, or
terminal width could reach them.

A diagnostic is now one message with labels, contexts, and location
information
attached, and `Diagnostics::Renderer` draws it into a
`Terminal::Buffer`. The
design is in `toolchain/docs/diagnostics_rendering.md` (#7668),
authoring in
`toolchain/docs/diagnostics.md`.

Before:

```
example.carbon:6:3: error: 1 argument passed to function expecting 0 arguments
  Run0(1);
  ^~~~~~~
example.carbon:3:1: note: calling function declared here
fn Run0() {}
^~~~~~~~~~~
```

After:

```
error: 1 argument passed to function expecting 0 arguments
       ╭─┤ example.carbon:6:3
       ┆
     3 │ fn Run0() {}
       · ─────┬─────
       ·      ╰──┤ calling function declared here
       ┆
->   6 │   Run0(1);
       ·   ───────
       ╰────────────
```

`--no-diagnostic-snippets` gives a compact form, `example.carbon:6:3-9`.
File
tests use it; the rendering tests under `toolchain/diagnostics/testdata`
ask for
snippets.

C++ interop diagnostics are data now rather than text Clang drew:
`SemIR::ClangSourceLocId` names a `clang::SourceRange`, and a Clang
location is
marked as the point it names.

`StreamConsumer` moves to a `:renderer` target that `:emitter` does not
depend
on, keeping `common/terminal` out of `consumer.h`. Capabilities come
from the
file behind the error stream, so tests get plain ASCII.

`renderer_fuzzer` draws diagnostics built from fuzzer bytes with every
capability combination, since a shape the renderer doesn't expect must
never be
why the compiler dies while reporting a problem.

TODOs mark the follow-ups: line weights and crossing lines, wrapping
that keeps
a quoted type whole, and ordering diagnostics that share a byte offset.

Also: `IncorrectExtension`'s hint moves into its message, since its note
had no
location of its own, and `strip_noise` in `check_diagnostics.py` blanks
multi-line `#define`s instead of deleting them.

Assisted-by: Claude Code
This commit is contained in:
Chandler Carruth authored and GitHub committed 2026-10-15 06:08:57 +00:00
1 parent e1c8c1f855
commit 2c9739799b
1205 files changed
+20291 -24988

No files matched your search

+14 -38
View File
@@ -47,15 +47,9 @@ class X {}
fn TakeNonConst(p: X*);
// CHECK:STDERR: fail_removed_qualifiers.carbon:[[@LINE+10]]:38: error: cannot implicitly convert expression of type `const X*` to `X*` [ConversionFailure]
// CHECK:STDERR: fn Const(p: const X*) { TakeNonConst(p); }
// CHECK:STDERR: ^
// CHECK:STDERR: fail_removed_qualifiers.carbon:[[@LINE+7]]:38: note: type `const X*` does not implement interface `Core.ImplicitAs(X*)` [MissingImplInMemberAccessInContext]
// CHECK:STDERR: fn Const(p: const X*) { TakeNonConst(p); }
// CHECK:STDERR: ^
// CHECK:STDERR: fail_removed_qualifiers.carbon:[[@LINE-8]]:17: note: initializing function parameter [InCallToFunctionParam]
// CHECK:STDERR: fn TakeNonConst(p: X*);
// CHECK:STDERR: ^~~~~
// CHECK:STDERR: fail_removed_qualifiers.carbon:[[@LINE+4]]:38: error: cannot implicitly convert expression of type `const X*` to `X*` [ConversionFailure]
// CHECK:STDERR: fail_removed_qualifiers.carbon:[[@LINE+3]]:38: note: type `const X*` does not implement interface `Core.ImplicitAs(X*)` [MissingImplInMemberAccessInContext]
// CHECK:STDERR: fail_removed_qualifiers.carbon:[[@LINE-4]]:17-21: note: initializing function parameter [InCallToFunctionParam]
// CHECK:STDERR:
fn Const(p: const X*) { TakeNonConst(p); }
@@ -71,15 +65,9 @@ fn TakeConstConst(p: const (const X*)*);
fn NonConstNonConst(p: X**) {
//@dump-sem-ir-begin
// CHECK:STDERR: fail_todo_nested_qualifiers.carbon:[[@LINE+10]]:18: error: cannot implicitly convert expression of type `X**` to `const (const X*)*` [ConversionFailure]
// CHECK:STDERR: TakeConstConst(p);
// CHECK:STDERR: ^
// CHECK:STDERR: fail_todo_nested_qualifiers.carbon:[[@LINE+7]]:18: note: type `X**` does not implement interface `Core.ImplicitAs(const (const X*)*)` [MissingImplInMemberAccessInContext]
// CHECK:STDERR: TakeConstConst(p);
// CHECK:STDERR: ^
// CHECK:STDERR: fail_todo_nested_qualifiers.carbon:[[@LINE-12]]:19: note: initializing function parameter [InCallToFunctionParam]
// CHECK:STDERR: fn TakeConstConst(p: const (const X*)*);
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR: fail_todo_nested_qualifiers.carbon:[[@LINE+4]]:18: error: cannot implicitly convert expression of type `X**` to `const (const X*)*` [ConversionFailure]
// CHECK:STDERR: fail_todo_nested_qualifiers.carbon:[[@LINE+3]]:18: note: type `X**` does not implement interface `Core.ImplicitAs(const (const X*)*)` [MissingImplInMemberAccessInContext]
// CHECK:STDERR: fail_todo_nested_qualifiers.carbon:[[@LINE-8]]:19-38: note: initializing function parameter [InCallToFunctionParam]
// CHECK:STDERR:
TakeConstConst(p);
//@dump-sem-ir-end
@@ -87,15 +75,9 @@ fn NonConstNonConst(p: X**) {
fn ConstNonConst(p: const (X*)*) {
//@dump-sem-ir-begin
// CHECK:STDERR: fail_todo_nested_qualifiers.carbon:[[@LINE+10]]:18: error: cannot implicitly convert expression of type `const (X*)*` to `const (const X*)*` [ConversionFailure]
// CHECK:STDERR: TakeConstConst(p);
// CHECK:STDERR: ^
// CHECK:STDERR: fail_todo_nested_qualifiers.carbon:[[@LINE+7]]:18: note: type `const (X*)*` does not implement interface `Core.ImplicitAs(const (const X*)*)` [MissingImplInMemberAccessInContext]
// CHECK:STDERR: TakeConstConst(p);
// CHECK:STDERR: ^
// CHECK:STDERR: fail_todo_nested_qualifiers.carbon:[[@LINE-28]]:19: note: initializing function parameter [InCallToFunctionParam]
// CHECK:STDERR: fn TakeConstConst(p: const (const X*)*);
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR: fail_todo_nested_qualifiers.carbon:[[@LINE+4]]:18: error: cannot implicitly convert expression of type `const (X*)*` to `const (const X*)*` [ConversionFailure]
// CHECK:STDERR: fail_todo_nested_qualifiers.carbon:[[@LINE+3]]:18: note: type `const (X*)*` does not implement interface `Core.ImplicitAs(const (const X*)*)` [MissingImplInMemberAccessInContext]
// CHECK:STDERR: fail_todo_nested_qualifiers.carbon:[[@LINE-18]]:19-38: note: initializing function parameter [InCallToFunctionParam]
// CHECK:STDERR:
TakeConstConst(p);
//@dump-sem-ir-end
@@ -109,15 +91,9 @@ class X {}
fn TakeNonConstConst(p: (const X*)*);
// CHECK:STDERR: fail_nested_added_qualifiers.carbon:[[@LINE+10]]:49: error: cannot implicitly convert expression of type `X**` to `const X**` [ConversionFailure]
// CHECK:STDERR: fn NonConstNonConst(p: X**) { TakeNonConstConst(p); }
// CHECK:STDERR: ^
// CHECK:STDERR: fail_nested_added_qualifiers.carbon:[[@LINE+7]]:49: note: type `X**` does not implement interface `Core.ImplicitAs(const X**)` [MissingImplInMemberAccessInContext]
// CHECK:STDERR: fn NonConstNonConst(p: X**) { TakeNonConstConst(p); }
// CHECK:STDERR: ^
// CHECK:STDERR: fail_nested_added_qualifiers.carbon:[[@LINE-8]]:22: note: initializing function parameter [InCallToFunctionParam]
// CHECK:STDERR: fn TakeNonConstConst(p: (const X*)*);
// CHECK:STDERR: ^~~~~~~~~~~~~~
// CHECK:STDERR: fail_nested_added_qualifiers.carbon:[[@LINE+4]]:49: error: cannot implicitly convert expression of type `X**` to `const X**` [ConversionFailure]
// CHECK:STDERR: fail_nested_added_qualifiers.carbon:[[@LINE+3]]:49: note: type `X**` does not implement interface `Core.ImplicitAs(const X**)` [MissingImplInMemberAccessInContext]
// CHECK:STDERR: fail_nested_added_qualifiers.carbon:[[@LINE-4]]:22-35: note: initializing function parameter [InCallToFunctionParam]
// CHECK:STDERR:
fn NonConstNonConst(p: X**) { TakeNonConstConst(p); }
@@ -194,7 +170,7 @@ fn NonConstNonConst(p: X**) { TakeNonConstConst(p); }
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %TakeConstConst.ref: %TakeConstConst.type = name_ref TakeConstConst, file.%TakeConstConst.decl [concrete = constants.%TakeConstConst]
// CHECK:STDOUT: %p.ref: %ptr.9ae = name_ref p, %p
// CHECK:STDOUT: %.loc22: %ptr.b53 = converted %p.ref, <error> [concrete = <error>]
// CHECK:STDOUT: %.loc16: %ptr.b53 = converted %p.ref, <error> [concrete = <error>]
// CHECK:STDOUT: %TakeConstConst.call: init %empty_tuple.type = call %TakeConstConst.ref(<error>)
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: }
@@ -203,7 +179,7 @@ fn NonConstNonConst(p: X**) { TakeNonConstConst(p); }
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %TakeConstConst.ref: %TakeConstConst.type = name_ref TakeConstConst, file.%TakeConstConst.decl [concrete = constants.%TakeConstConst]
// CHECK:STDOUT: %p.ref: %ptr.060 = name_ref p, %p
// CHECK:STDOUT: %.loc38: %ptr.b53 = converted %p.ref, <error> [concrete = <error>]
// CHECK:STDOUT: %.loc26: %ptr.b53 = converted %p.ref, <error> [concrete = <error>]
// CHECK:STDOUT: %TakeConstConst.call: init %empty_tuple.type = call %TakeConstConst.ref(<error>)
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: }
@@ -13,18 +13,12 @@
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/pointer/fail_address_of_error.carbon
fn Test() {
// CHECK:STDERR: fail_address_of_error.carbon:[[@LINE+4]]:4: error: name `undeclared` not found [NameNotFound]
// CHECK:STDERR: &undeclared;
// CHECK:STDERR: ^~~~~~~~~~
// CHECK:STDERR: fail_address_of_error.carbon:[[@LINE+2]]:4-13: error: name `undeclared` not found [NameNotFound]
// CHECK:STDERR:
&undeclared;
// CHECK:STDERR: fail_address_of_error.carbon:[[@LINE+8]]:6: error: name `undeclared` not found [NameNotFound]
// CHECK:STDERR: &(&undeclared);
// CHECK:STDERR: ^~~~~~~~~~
// CHECK:STDERR: fail_address_of_error.carbon:[[@LINE+4]]:6-15: error: name `undeclared` not found [NameNotFound]
// CHECK:STDERR:
// CHECK:STDERR: fail_address_of_error.carbon:[[@LINE+4]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef]
// CHECK:STDERR: &(&undeclared);
// CHECK:STDERR: ^
// CHECK:STDERR: fail_address_of_error.carbon:[[@LINE+2]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef]
// CHECK:STDERR:
&(&undeclared);
}
@@ -56,11 +50,11 @@ fn Test() {
// CHECK:STDOUT:
// CHECK:STDOUT: fn @Test() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %undeclared.ref.loc20: <error> = name_ref undeclared, <error> [concrete = <error>]
// CHECK:STDOUT: %addr.loc20: <error> = addr_of %undeclared.ref.loc20 [concrete = <error>]
// CHECK:STDOUT: %undeclared.ref.loc29: <error> = name_ref undeclared, <error> [concrete = <error>]
// CHECK:STDOUT: %addr.loc29_5: <error> = addr_of %undeclared.ref.loc29 [concrete = <error>]
// CHECK:STDOUT: %addr.loc29_3: <error> = addr_of <error> [concrete = <error>]
// CHECK:STDOUT: %undeclared.ref.loc18: <error> = name_ref undeclared, <error> [concrete = <error>]
// CHECK:STDOUT: %addr.loc18: <error> = addr_of %undeclared.ref.loc18 [concrete = <error>]
// CHECK:STDOUT: %undeclared.ref.loc23: <error> = name_ref undeclared, <error> [concrete = <error>]
// CHECK:STDOUT: %addr.loc23_5: <error> = addr_of %undeclared.ref.loc23 [concrete = <error>]
// CHECK:STDOUT: %addr.loc23_3: <error> = addr_of <error> [concrete = <error>]
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT:
+14 -42
View File
@@ -15,89 +15,61 @@ fn G() -> i32;
fn H() -> {.a: i32};
fn AddressOfLiteral() {
// CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+4]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef]
// CHECK:STDERR: &0;
// CHECK:STDERR: ^
// CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+2]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef]
// CHECK:STDERR:
&0;
// CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+4]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef]
// CHECK:STDERR: &true;
// CHECK:STDERR: ^
// CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+2]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef]
// CHECK:STDERR:
&true;
// CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+4]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef]
// CHECK:STDERR: &1.0;
// CHECK:STDERR: ^
// CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+2]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef]
// CHECK:STDERR:
&1.0;
// CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+4]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef]
// CHECK:STDERR: &"Hello";
// CHECK:STDERR: ^
// CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+2]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef]
// CHECK:STDERR:
&"Hello";
// CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+4]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef]
// CHECK:STDERR: &(1, 2);
// CHECK:STDERR: ^
// CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+2]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef]
// CHECK:STDERR:
&(1, 2);
// CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+4]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef]
// CHECK:STDERR: &{.a = 5};
// CHECK:STDERR: ^
// CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+2]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef]
// CHECK:STDERR:
&{.a = 5};
}
fn AddressOfOperator() {
// CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+4]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef]
// CHECK:STDERR: &(true and false);
// CHECK:STDERR: ^
// CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+2]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef]
// CHECK:STDERR:
&(true and false);
// CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+4]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef]
// CHECK:STDERR: &H().a;
// CHECK:STDERR: ^
// CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+2]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef]
// CHECK:STDERR:
&H().a;
// CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+4]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef]
// CHECK:STDERR: &(not true);
// CHECK:STDERR: ^
// CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+2]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef]
// CHECK:STDERR:
&(not true);
}
fn AddressOfCall() {
// CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+4]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef]
// CHECK:STDERR: &G();
// CHECK:STDERR: ^
// CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+2]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef]
// CHECK:STDERR:
&G();
}
fn AddressOfType() {
// CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+4]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef]
// CHECK:STDERR: &i32;
// CHECK:STDERR: ^
// CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+2]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef]
// CHECK:STDERR:
&i32;
// CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+4]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef]
// CHECK:STDERR: &(const i32*);
// CHECK:STDERR: ^
// CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+2]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef]
// CHECK:STDERR:
&(const i32*);
}
fn AddressOfTupleElementValue() {
// CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+4]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef]
// CHECK:STDERR: &((1, 2).0);
// CHECK:STDERR: ^
// CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+2]]:3: error: cannot take the address of non-reference expression [AddrOfNonRef]
// CHECK:STDERR:
&((1, 2).0);
}
fn AddressOfParam(param: i32) {
// CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+4]]:33: error: cannot take the address of non-reference expression [AddrOfNonRef]
// CHECK:STDERR: var unused param_addr: i32* = &param;
// CHECK:STDERR: ^
// CHECK:STDERR: fail_address_of_value.carbon:[[@LINE+2]]:33: error: cannot take the address of non-reference expression [AddrOfNonRef]
// CHECK:STDERR:
var unused param_addr: i32* = &param;
}
+8 -12
View File
@@ -12,14 +12,10 @@
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/pointer/fail_deref_error.carbon
// CHECK:STDERR: fail_deref_error.carbon:[[@LINE+4]]:15: error: name `undeclared` not found [NameNotFound]
// CHECK:STDERR: let n: i32 = *undeclared;
// CHECK:STDERR: ^~~~~~~~~~
// CHECK:STDERR: fail_deref_error.carbon:[[@LINE+2]]:15-24: error: name `undeclared` not found [NameNotFound]
// CHECK:STDERR:
let n: i32 = *undeclared;
// CHECK:STDERR: fail_deref_error.carbon:[[@LINE+4]]:15: error: name `undeclared` not found [NameNotFound]
// CHECK:STDERR: let n2: i32 = undeclared->foo;
// CHECK:STDERR: ^~~~~~~~~~
// CHECK:STDERR: fail_deref_error.carbon:[[@LINE+2]]:15-24: error: name `undeclared` not found [NameNotFound]
// CHECK:STDERR:
let n2: i32 = undeclared->foo;
@@ -53,12 +49,12 @@ let n2: i32 = undeclared->foo;
// CHECK:STDOUT: .n2 = %n2
// CHECK:STDOUT: }
// CHECK:STDOUT: %Core.import = import Core
// CHECK:STDOUT: %i32.loc19: type = type_literal constants.%i32 [concrete = constants.%i32]
// CHECK:STDOUT: %i32.loc17: type = type_literal constants.%i32 [concrete = constants.%i32]
// CHECK:STDOUT: %n: %i32 = wrapper_binding n, <error> [concrete = <error>]
// CHECK:STDOUT: name_binding_decl {
// CHECK:STDOUT: %n.patt: %pattern_type.d94 = value_binding_pattern n [concrete = constants.%n.patt]
// CHECK:STDOUT: }
// CHECK:STDOUT: %i32.loc24: type = type_literal constants.%i32 [concrete = constants.%i32]
// CHECK:STDOUT: %i32.loc20: type = type_literal constants.%i32 [concrete = constants.%i32]
// CHECK:STDOUT: %n2: %i32 = wrapper_binding n2, <error> [concrete = <error>]
// CHECK:STDOUT: name_binding_decl {
// CHECK:STDOUT: %n2.patt: %pattern_type.d94 = value_binding_pattern n2 [concrete = constants.%n2.patt]
@@ -67,10 +63,10 @@ let n2: i32 = undeclared->foo;
// CHECK:STDOUT:
// CHECK:STDOUT: fn @__global_init() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %undeclared.ref.loc19: <error> = name_ref undeclared, <error> [concrete = <error>]
// CHECK:STDOUT: %.loc19: ref <error> = deref <error> [concrete = <error>]
// CHECK:STDOUT: %undeclared.ref.loc24: <error> = name_ref undeclared, <error> [concrete = <error>]
// CHECK:STDOUT: %.loc24: ref <error> = deref <error> [concrete = <error>]
// CHECK:STDOUT: %undeclared.ref.loc17: <error> = name_ref undeclared, <error> [concrete = <error>]
// CHECK:STDOUT: %.loc17: ref <error> = deref <error> [concrete = <error>]
// CHECK:STDOUT: %undeclared.ref.loc20: <error> = name_ref undeclared, <error> [concrete = <error>]
// CHECK:STDOUT: %.loc20: ref <error> = deref <error> [concrete = <error>]
// CHECK:STDOUT: %foo.ref: <error> = name_ref foo, <error> [concrete = <error>]
// CHECK:STDOUT: return
// CHECK:STDOUT: }
+6 -10
View File
@@ -13,14 +13,10 @@
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/pointer/fail_deref_function.carbon
fn A() {
// CHECK:STDERR: fail_deref_function.carbon:[[@LINE+4]]:3: error: cannot dereference operand of non-pointer type `<type of A>` [DerefOfNonPointer]
// CHECK:STDERR: *A;
// CHECK:STDERR: ^
// CHECK:STDERR: fail_deref_function.carbon:[[@LINE+2]]:3: error: cannot dereference operand of non-pointer type `<type of A>` [DerefOfNonPointer]
// CHECK:STDERR:
*A;
// CHECK:STDERR: fail_deref_function.carbon:[[@LINE+4]]:4: error: cannot apply `->` operator to non-pointer type `<type of A>` [ArrowOperatorOfNonPointer]
// CHECK:STDERR: A->foo;
// CHECK:STDERR: ^~
// CHECK:STDERR: fail_deref_function.carbon:[[@LINE+2]]:4-5: error: cannot apply `->` operator to non-pointer type `<type of A>` [ArrowOperatorOfNonPointer]
// CHECK:STDERR:
A->foo;
}
@@ -51,10 +47,10 @@ fn A() {
// CHECK:STDOUT:
// CHECK:STDOUT: fn @A() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %A.ref.loc20: %A.type = name_ref A, file.%A.decl [concrete = constants.%A]
// CHECK:STDOUT: %.loc20: ref <error> = deref %A.ref.loc20 [concrete = <error>]
// CHECK:STDOUT: %A.ref.loc25: %A.type = name_ref A, file.%A.decl [concrete = constants.%A]
// CHECK:STDOUT: %.loc25: ref <error> = deref %A.ref.loc25 [concrete = <error>]
// CHECK:STDOUT: %A.ref.loc18: %A.type = name_ref A, file.%A.decl [concrete = constants.%A]
// CHECK:STDOUT: %.loc18: ref <error> = deref %A.ref.loc18 [concrete = <error>]
// CHECK:STDOUT: %A.ref.loc21: %A.type = name_ref A, file.%A.decl [concrete = constants.%A]
// CHECK:STDOUT: %.loc21: ref <error> = deref %A.ref.loc21 [concrete = <error>]
// CHECK:STDOUT: %foo.ref: <error> = name_ref foo, <error> [concrete = <error>]
// CHECK:STDOUT: return
// CHECK:STDOUT: }
@@ -15,14 +15,10 @@
namespace A;
fn F() {
// CHECK:STDERR: fail_deref_namespace.carbon:[[@LINE+4]]:4: error: expression cannot be used as a value [UseOfNonExprAsValue]
// CHECK:STDERR: *A;
// CHECK:STDERR: ^
// CHECK:STDERR: fail_deref_namespace.carbon:[[@LINE+2]]:4: error: expression cannot be used as a value [UseOfNonExprAsValue]
// CHECK:STDERR:
*A;
// CHECK:STDERR: fail_deref_namespace.carbon:[[@LINE+4]]:3: error: expression cannot be used as a value [UseOfNonExprAsValue]
// CHECK:STDERR: A->foo;
// CHECK:STDERR: ^
// CHECK:STDERR: fail_deref_namespace.carbon:[[@LINE+2]]:3: error: expression cannot be used as a value [UseOfNonExprAsValue]
// CHECK:STDERR:
A->foo;
}
@@ -55,10 +51,10 @@ fn F() {
// CHECK:STDOUT:
// CHECK:STDOUT: fn @F() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %A.ref.loc22: <namespace> = name_ref A, file.%A [concrete = file.%A]
// CHECK:STDOUT: %.loc22: ref <error> = deref <error> [concrete = <error>]
// CHECK:STDOUT: %A.ref.loc27: <namespace> = name_ref A, file.%A [concrete = file.%A]
// CHECK:STDOUT: %.loc27: ref <error> = deref <error> [concrete = <error>]
// CHECK:STDOUT: %A.ref.loc20: <namespace> = name_ref A, file.%A [concrete = file.%A]
// CHECK:STDOUT: %.loc20: ref <error> = deref <error> [concrete = <error>]
// CHECK:STDOUT: %A.ref.loc23: <namespace> = name_ref A, file.%A [concrete = file.%A]
// CHECK:STDOUT: %.loc23: ref <error> = deref <error> [concrete = <error>]
// CHECK:STDOUT: %foo.ref: <error> = name_ref foo, <error> [concrete = <error>]
// CHECK:STDOUT: return
// CHECK:STDOUT: }
@@ -13,34 +13,22 @@
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/pointer/fail_deref_not_pointer.carbon
fn Deref(n: i32) {
// CHECK:STDERR: fail_deref_not_pointer.carbon:[[@LINE+4]]:3: error: cannot dereference operand of non-pointer type `i32` [DerefOfNonPointer]
// CHECK:STDERR: *n;
// CHECK:STDERR: ^
// CHECK:STDERR: fail_deref_not_pointer.carbon:[[@LINE+2]]:3: error: cannot dereference operand of non-pointer type `i32` [DerefOfNonPointer]
// CHECK:STDERR:
*n;
// CHECK:STDERR: fail_deref_not_pointer.carbon:[[@LINE+4]]:4: error: cannot apply `->` operator to non-pointer type `i32` [ArrowOperatorOfNonPointer]
// CHECK:STDERR: n->foo;
// CHECK:STDERR: ^~
// CHECK:STDERR: fail_deref_not_pointer.carbon:[[@LINE+2]]:4-5: error: cannot apply `->` operator to non-pointer type `i32` [ArrowOperatorOfNonPointer]
// CHECK:STDERR:
n->foo;
// CHECK:STDERR: fail_deref_not_pointer.carbon:[[@LINE+4]]:3: error: cannot dereference operand of non-pointer type `()` [DerefOfNonPointer]
// CHECK:STDERR: *();
// CHECK:STDERR: ^
// CHECK:STDERR: fail_deref_not_pointer.carbon:[[@LINE+2]]:3: error: cannot dereference operand of non-pointer type `()` [DerefOfNonPointer]
// CHECK:STDERR:
*();
// CHECK:STDERR: fail_deref_not_pointer.carbon:[[@LINE+4]]:5: error: cannot apply `->` operator to non-pointer type `()` [ArrowOperatorOfNonPointer]
// CHECK:STDERR: ()->foo;
// CHECK:STDERR: ^~
// CHECK:STDERR: fail_deref_not_pointer.carbon:[[@LINE+2]]:5-6: error: cannot apply `->` operator to non-pointer type `()` [ArrowOperatorOfNonPointer]
// CHECK:STDERR:
()->foo;
// CHECK:STDERR: fail_deref_not_pointer.carbon:[[@LINE+4]]:3: error: cannot dereference operand of non-pointer type `{}` [DerefOfNonPointer]
// CHECK:STDERR: *{};
// CHECK:STDERR: ^
// CHECK:STDERR: fail_deref_not_pointer.carbon:[[@LINE+2]]:3: error: cannot dereference operand of non-pointer type `{}` [DerefOfNonPointer]
// CHECK:STDERR:
*{};
// CHECK:STDERR: fail_deref_not_pointer.carbon:[[@LINE+4]]:5: error: cannot apply `->` operator to non-pointer type `{}` [ArrowOperatorOfNonPointer]
// CHECK:STDERR: {}->foo;
// CHECK:STDERR: ^~
// CHECK:STDERR: fail_deref_not_pointer.carbon:[[@LINE+2]]:5-6: error: cannot apply `->` operator to non-pointer type `{}` [ArrowOperatorOfNonPointer]
// CHECK:STDERR:
{}->foo;
}
@@ -91,29 +79,29 @@ fn Deref(n: i32) {
// CHECK:STDOUT:
// CHECK:STDOUT: fn @Deref(%n.param: %i32) {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %n.ref.loc20: %i32 = name_ref n, %n
// CHECK:STDOUT: %.loc20: ref <error> = deref %n.ref.loc20
// CHECK:STDOUT: %n.ref.loc25: %i32 = name_ref n, %n
// CHECK:STDOUT: %.loc25: ref <error> = deref %n.ref.loc25
// CHECK:STDOUT: %foo.ref.loc25: <error> = name_ref foo, <error> [concrete = <error>]
// CHECK:STDOUT: %.loc30_5.1: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
// CHECK:STDOUT: %empty_tuple.loc30: %empty_tuple.type = tuple_value () [concrete = constants.%empty_tuple]
// CHECK:STDOUT: %.loc30_5.2: %empty_tuple.type = converted %.loc30_5.1, %empty_tuple.loc30 [concrete = constants.%empty_tuple]
// CHECK:STDOUT: %n.ref.loc18: %i32 = name_ref n, %n
// CHECK:STDOUT: %.loc18: ref <error> = deref %n.ref.loc18
// CHECK:STDOUT: %n.ref.loc21: %i32 = name_ref n, %n
// CHECK:STDOUT: %.loc21: ref <error> = deref %n.ref.loc21
// CHECK:STDOUT: %foo.ref.loc21: <error> = name_ref foo, <error> [concrete = <error>]
// CHECK:STDOUT: %.loc24_5.1: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
// CHECK:STDOUT: %empty_tuple.loc24: %empty_tuple.type = tuple_value () [concrete = constants.%empty_tuple]
// CHECK:STDOUT: %.loc24_5.2: %empty_tuple.type = converted %.loc24_5.1, %empty_tuple.loc24 [concrete = constants.%empty_tuple]
// CHECK:STDOUT: %.loc24_3: ref <error> = deref %.loc24_5.2 [concrete = <error>]
// CHECK:STDOUT: %.loc27_4.1: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
// CHECK:STDOUT: %empty_tuple.loc27: %empty_tuple.type = tuple_value () [concrete = constants.%empty_tuple]
// CHECK:STDOUT: %.loc27_4.2: %empty_tuple.type = converted %.loc27_4.1, %empty_tuple.loc27 [concrete = constants.%empty_tuple]
// CHECK:STDOUT: %.loc27_5: ref <error> = deref %.loc27_4.2 [concrete = <error>]
// CHECK:STDOUT: %foo.ref.loc27: <error> = name_ref foo, <error> [concrete = <error>]
// CHECK:STDOUT: %.loc30_5.1: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
// CHECK:STDOUT: %empty_struct.loc30: %empty_struct_type = struct_value () [concrete = constants.%empty_struct]
// CHECK:STDOUT: %.loc30_5.2: %empty_struct_type = converted %.loc30_5.1, %empty_struct.loc30 [concrete = constants.%empty_struct]
// CHECK:STDOUT: %.loc30_3: ref <error> = deref %.loc30_5.2 [concrete = <error>]
// CHECK:STDOUT: %.loc35_4.1: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
// CHECK:STDOUT: %empty_tuple.loc35: %empty_tuple.type = tuple_value () [concrete = constants.%empty_tuple]
// CHECK:STDOUT: %.loc35_4.2: %empty_tuple.type = converted %.loc35_4.1, %empty_tuple.loc35 [concrete = constants.%empty_tuple]
// CHECK:STDOUT: %.loc35_5: ref <error> = deref %.loc35_4.2 [concrete = <error>]
// CHECK:STDOUT: %foo.ref.loc35: <error> = name_ref foo, <error> [concrete = <error>]
// CHECK:STDOUT: %.loc40_5.1: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
// CHECK:STDOUT: %empty_struct.loc40: %empty_struct_type = struct_value () [concrete = constants.%empty_struct]
// CHECK:STDOUT: %.loc40_5.2: %empty_struct_type = converted %.loc40_5.1, %empty_struct.loc40 [concrete = constants.%empty_struct]
// CHECK:STDOUT: %.loc40_3: ref <error> = deref %.loc40_5.2 [concrete = <error>]
// CHECK:STDOUT: %.loc45_4.1: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
// CHECK:STDOUT: %empty_struct.loc45: %empty_struct_type = struct_value () [concrete = constants.%empty_struct]
// CHECK:STDOUT: %.loc45_4.2: %empty_struct_type = converted %.loc45_4.1, %empty_struct.loc45 [concrete = constants.%empty_struct]
// CHECK:STDOUT: %.loc45_5: ref <error> = deref %.loc45_4.2 [concrete = <error>]
// CHECK:STDOUT: %foo.ref.loc45: <error> = name_ref foo, <error> [concrete = <error>]
// CHECK:STDOUT: %.loc33_4.1: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
// CHECK:STDOUT: %empty_struct.loc33: %empty_struct_type = struct_value () [concrete = constants.%empty_struct]
// CHECK:STDOUT: %.loc33_4.2: %empty_struct_type = converted %.loc33_4.1, %empty_struct.loc33 [concrete = constants.%empty_struct]
// CHECK:STDOUT: %.loc33_5: ref <error> = deref %.loc33_4.2 [concrete = <error>]
// CHECK:STDOUT: %foo.ref.loc33: <error> = name_ref foo, <error> [concrete = <error>]
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT:
+7 -13
View File
@@ -12,17 +12,11 @@
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/pointer/fail_deref_type.carbon
// CHECK:STDERR: fail_deref_type.carbon:[[@LINE+7]]:8: error: cannot dereference operand of non-pointer type `type` [DerefOfNonPointer]
// CHECK:STDERR: var p: *i32;
// CHECK:STDERR: ^
// CHECK:STDERR: fail_deref_type.carbon:[[@LINE+4]]:8: note: to form a pointer type, write the `*` after the pointee type [DerefOfType]
// CHECK:STDERR: var p: *i32;
// CHECK:STDERR: ^
// CHECK:STDERR: fail_deref_type.carbon:[[@LINE+3]]:8: error: cannot dereference operand of non-pointer type `type` [DerefOfNonPointer]
// CHECK:STDERR: fail_deref_type.carbon:[[@LINE+2]]:8: note: to form a pointer type, write the `*` after the pointee type [DerefOfType]
// CHECK:STDERR:
var p: *i32;
// CHECK:STDERR: fail_deref_type.carbon:[[@LINE+4]]:12: error: cannot apply `->` operator to non-pointer type `type` [ArrowOperatorOfNonPointer]
// CHECK:STDERR: var p2: i32->foo;
// CHECK:STDERR: ^~
// CHECK:STDERR: fail_deref_type.carbon:[[@LINE+2]]:12-13: error: cannot apply `->` operator to non-pointer type `type` [ArrowOperatorOfNonPointer]
// CHECK:STDERR:
var p2: i32->foo;
@@ -54,8 +48,8 @@ var p2: i32->foo;
// CHECK:STDOUT: %Core.import = import Core
// CHECK:STDOUT: %p.var: ref <error> = var_storage %p.var_patt [concrete = <error>]
// CHECK:STDOUT: %.1: <error> = splice_block <error> [concrete = <error>] {
// CHECK:STDOUT: %i32.loc22: type = type_literal constants.%i32 [concrete = constants.%i32]
// CHECK:STDOUT: %.loc22: ref <error> = deref %i32.loc22 [concrete = <error>]
// CHECK:STDOUT: %i32.loc18: type = type_literal constants.%i32 [concrete = constants.%i32]
// CHECK:STDOUT: %.loc18: ref <error> = deref %i32.loc18 [concrete = <error>]
// CHECK:STDOUT: }
// CHECK:STDOUT: %p: <error> = wrapper_binding p, <error> [concrete = <error>]
// CHECK:STDOUT: name_binding_decl {
@@ -64,8 +58,8 @@ var p2: i32->foo;
// CHECK:STDOUT: }
// CHECK:STDOUT: %p2.var: ref <error> = var_storage %p2.var_patt [concrete = <error>]
// CHECK:STDOUT: %.2: <error> = splice_block <error> [concrete = <error>] {
// CHECK:STDOUT: %i32.loc27: type = type_literal constants.%i32 [concrete = constants.%i32]
// CHECK:STDOUT: %.loc27: ref <error> = deref %i32.loc27 [concrete = <error>]
// CHECK:STDOUT: %i32.loc21: type = type_literal constants.%i32 [concrete = constants.%i32]
// CHECK:STDOUT: %.loc21: ref <error> = deref %i32.loc21 [concrete = <error>]
// CHECK:STDOUT: %foo.ref: <error> = name_ref foo, <error> [concrete = <error>]
// CHECK:STDOUT: }
// CHECK:STDOUT: %p2: <error> = wrapper_binding p2, <error> [concrete = <error>]
+3 -7
View File
@@ -13,12 +13,8 @@
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/pointer/fail_type_mismatch.carbon
fn ConstMismatch(p: const {}*) -> const ({}*) {
// CHECK:STDERR: fail_type_mismatch.carbon:[[@LINE+7]]:3: error: cannot implicitly convert expression of type `const {}*` to `const ({}*)` [ConversionFailure]
// CHECK:STDERR: return p;
// CHECK:STDERR: ^~~~~~~~~
// CHECK:STDERR: fail_type_mismatch.carbon:[[@LINE+4]]:3: note: type `const {}*` does not implement interface `Core.ImplicitAs(const ({}*))` [MissingImplInMemberAccessInContext]
// CHECK:STDERR: return p;
// CHECK:STDERR: ^~~~~~~~~
// CHECK:STDERR: fail_type_mismatch.carbon:[[@LINE+3]]:3-11: error: cannot implicitly convert expression of type `const {}*` to `const ({}*)` [ConversionFailure]
// CHECK:STDERR: fail_type_mismatch.carbon:[[@LINE+2]]:3-11: note: type `const {}*` does not implement interface `Core.ImplicitAs(const ({}*))` [MissingImplInMemberAccessInContext]
// CHECK:STDERR:
return p;
}
@@ -88,7 +84,7 @@ fn ConstMismatch(p: const {}*) -> const ({}*) {
// CHECK:STDOUT: fn @ConstMismatch(%p.param: %ptr.bf9) -> out %return.param: %const.987 {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %p.ref: %ptr.bf9 = name_ref p, %p
// CHECK:STDOUT: %.loc23: %const.987 = converted %p.ref, <error> [concrete = <error>]
// CHECK:STDOUT: %.loc19: %const.987 = converted %p.ref, <error> [concrete = <error>]
// CHECK:STDOUT: return <error>
// CHECK:STDOUT: }
// CHECK:STDOUT: