mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-21 14:46:37 +00:00
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
147 lines
7.7 KiB
Plaintext
147 lines
7.7 KiB
Plaintext
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/none.carbon
|
|
// TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
|
|
// EXTRA-ARGS: --dump-sem-ir-ranges=if-present
|
|
//
|
|
// AUTOUPDATE
|
|
// TIP: To test this file alone, run:
|
|
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interface/fail_add_member_outside_definition.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interface/fail_add_member_outside_definition.carbon
|
|
|
|
interface Interface { }
|
|
|
|
// CHECK:STDERR: fail_add_member_outside_definition.carbon:[[@LINE+2]]:14: error: out-of-line declaration requires a declaration in scoped entity [QualifiedDeclOutsideScopeEntity]
|
|
// CHECK:STDERR:
|
|
fn Interface.F() {}
|
|
|
|
// Nesting interfaces like this is not valid, but make sure we don't crash.
|
|
interface Outer {
|
|
interface Inner {
|
|
// CHECK:STDERR: fail_add_member_outside_definition.carbon:[[@LINE+2]]:8-12: error: name `Outer` not found [NameNotFound]
|
|
// CHECK:STDERR:
|
|
fn Outer.F();
|
|
}
|
|
// CHECK:STDERR: fail_add_member_outside_definition.carbon:[[@LINE+2]]:12: error: out-of-line declaration requires a declaration in scoped entity [QualifiedDeclOutsideScopeEntity]
|
|
// CHECK:STDERR:
|
|
fn Inner.F();
|
|
}
|
|
|
|
// CHECK:STDOUT: --- fail_add_member_outside_definition.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
|
// CHECK:STDOUT: %Interface.type: type = facet_type <@Interface> [concrete]
|
|
// CHECK:STDOUT: %Self.3ce: %Interface.type = symbolic_binding Self, 0 [symbolic]
|
|
// CHECK:STDOUT: %Interface.WithSelf.F.type: type = fn_type @Interface.WithSelf.F, @Interface.WithSelf(%Self.3ce) [symbolic]
|
|
// CHECK:STDOUT: %Interface.WithSelf.F: %Interface.WithSelf.F.type = struct_value () [symbolic]
|
|
// CHECK:STDOUT: %Outer.type: type = facet_type <@Outer> [concrete]
|
|
// CHECK:STDOUT: %Self.a58: %Outer.type = symbolic_binding Self, 0 [symbolic]
|
|
// CHECK:STDOUT: %Inner.type: type = facet_type <@Inner, @Inner(%Self.a58)> [symbolic]
|
|
// CHECK:STDOUT: %Self.4ae: %Inner.type = symbolic_binding Self, 1 [symbolic]
|
|
// CHECK:STDOUT: %Inner.WithSelf.F.type.3f066d.1: type = fn_type @Inner.WithSelf.F.loc26, @Inner.WithSelf(%Self.a58, %Self.4ae) [symbolic]
|
|
// CHECK:STDOUT: %Inner.WithSelf.F.3cb3ec.1: %Inner.WithSelf.F.type.3f066d.1 = struct_value () [symbolic]
|
|
// CHECK:STDOUT: %Inner.WithSelf.F.type.3f066d.2: type = fn_type @Inner.WithSelf.F.loc30, @Inner.WithSelf(%Self.a58, %Self.4ae) [symbolic]
|
|
// CHECK:STDOUT: %Inner.WithSelf.F.3cb3ec.2: %Inner.WithSelf.F.type.3f066d.2 = struct_value () [symbolic]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
|
|
// CHECK:STDOUT: .Interface = %Interface.decl
|
|
// CHECK:STDOUT: .Outer = %Outer.decl
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %Interface.decl: type = interface_decl @Interface [concrete = constants.%Interface.type] {} {}
|
|
// CHECK:STDOUT: %Interface.WithSelf.F.decl: %Interface.WithSelf.F.type = fn_decl @Interface.WithSelf.F [symbolic = constants.%Interface.WithSelf.F] {} {}
|
|
// CHECK:STDOUT: %Outer.decl: type = interface_decl @Outer [concrete = constants.%Outer.type] {} {}
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: interface @Interface {
|
|
// CHECK:STDOUT: %Self: %Interface.type = symbolic_binding Self, 0 [symbolic = constants.%Self.3ce]
|
|
// CHECK:STDOUT: %Interface.WithSelf.decl = interface_with_self_decl @Interface [concrete]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .Self = %Self
|
|
// CHECK:STDOUT: .F = file.%Interface.WithSelf.F.decl
|
|
// CHECK:STDOUT: witness = ()
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !requires:
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: interface @Outer {
|
|
// CHECK:STDOUT: %Self: %Outer.type = symbolic_binding Self, 0 [symbolic = constants.%Self.a58]
|
|
// CHECK:STDOUT: %Outer.WithSelf.decl = interface_with_self_decl @Outer [concrete]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !with Self:
|
|
// CHECK:STDOUT: %Inner.decl: type = interface_decl @Inner [symbolic = @Outer.WithSelf.%Inner.type (constants.%Inner.type)] {} {}
|
|
// CHECK:STDOUT: %Inner.WithSelf.F.decl: @Outer.WithSelf.%Inner.WithSelf.F.type (%Inner.WithSelf.F.type.3f066d.2) = fn_decl @Inner.WithSelf.F.loc30 [symbolic = @Outer.WithSelf.%Inner.WithSelf.F (constants.%Inner.WithSelf.F.3cb3ec.2)] {} {}
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .Self = %Self
|
|
// CHECK:STDOUT: .Inner = @Outer.WithSelf.%Inner.decl
|
|
// CHECK:STDOUT: witness = ()
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !requires:
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: generic interface @Inner(@Outer.%Self: %Outer.type) {
|
|
// CHECK:STDOUT: !definition:
|
|
// CHECK:STDOUT: %Self.loc23_19.2: %Outer.type = symbolic_binding Self, 0 [symbolic = %Self.loc23_19.2 (constants.%Self.a58)]
|
|
// CHECK:STDOUT: %Inner.type: type = facet_type <@Inner, @Inner(%Self.loc23_19.2)> [symbolic = %Inner.type (constants.%Inner.type)]
|
|
// CHECK:STDOUT: %Self.loc23_19.3: @Inner.%Inner.type (%Inner.type) = symbolic_binding Self, 1 [symbolic = %Self.loc23_19.3 (constants.%Self.4ae)]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: interface {
|
|
// CHECK:STDOUT: %Self.loc23_19.1: @Inner.%Inner.type (%Inner.type) = symbolic_binding Self, 1 [symbolic = %Self.loc23_19.3 (constants.%Self.4ae)]
|
|
// CHECK:STDOUT: %Inner.WithSelf.decl = interface_with_self_decl @Inner [concrete]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !with Self:
|
|
// CHECK:STDOUT: %Inner.WithSelf.F.decl: @Inner.WithSelf.%Inner.WithSelf.F.type (%Inner.WithSelf.F.type.3f066d.1) = fn_decl @Inner.WithSelf.F.loc26 [symbolic = @Inner.WithSelf.%Inner.WithSelf.F (constants.%Inner.WithSelf.F.3cb3ec.1)] {} {}
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .Self = %Self.loc23_19.1
|
|
// CHECK:STDOUT: .F = @Outer.WithSelf.%Inner.WithSelf.F.decl
|
|
// CHECK:STDOUT: witness = ()
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !requires:
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: generic fn @Interface.WithSelf.F(@Interface.%Self: %Interface.type) {
|
|
// CHECK:STDOUT: !definition:
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn() {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: return
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: generic fn @Inner.WithSelf.F.loc26(@Outer.%Self: %Outer.type, @Inner.%Self.loc23_19.1: @Inner.%Inner.type (%Inner.type)) {
|
|
// CHECK:STDOUT: fn();
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: generic fn @Inner.WithSelf.F.loc30(@Outer.%Self: %Outer.type, @Inner.%Self.loc23_19.1: @Inner.%Inner.type (%Inner.type)) {
|
|
// CHECK:STDOUT: fn();
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @Interface.WithSelf(constants.%Self.3ce) {}
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @Interface.WithSelf.F(constants.%Self.3ce) {}
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @Outer.WithSelf(constants.%Self.a58) {}
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @Inner(constants.%Self.a58) {
|
|
// CHECK:STDOUT: !definition:
|
|
// CHECK:STDOUT: %Self.loc23_19.2 => constants.%Self.a58
|
|
// CHECK:STDOUT: %Inner.type => constants.%Inner.type
|
|
// CHECK:STDOUT: %Self.loc23_19.3 => constants.%Self.4ae
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @Inner.WithSelf(constants.%Self.a58, constants.%Self.4ae) {}
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @Inner.WithSelf.F.loc26(constants.%Self.a58, constants.%Self.4ae) {}
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: specific @Inner.WithSelf.F.loc30(constants.%Self.a58, constants.%Self.4ae) {}
|
|
// CHECK:STDOUT:
|