mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-10 12:28:25 +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
203 lines
8.0 KiB
Plaintext
203 lines
8.0 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/convert.carbon
|
|
//
|
|
// AUTOUPDATE
|
|
// TIP: To test this file alone, run:
|
|
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/alias/basics.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/alias/basics.carbon
|
|
|
|
// --- alias.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class C {};
|
|
|
|
//@dump-sem-ir-begin
|
|
alias c = C;
|
|
//@dump-sem-ir-end
|
|
|
|
let l: c = {};
|
|
|
|
// --- alias_of_alias.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class C {}
|
|
|
|
//@dump-sem-ir-begin
|
|
alias a = C;
|
|
alias b = a;
|
|
alias c = b;
|
|
let d: c = {};
|
|
//@dump-sem-ir-end
|
|
|
|
// --- alias_to_generic.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class A(T: type) {}
|
|
|
|
//@dump-sem-ir-begin
|
|
alias a = A({});
|
|
//@dump-sem-ir-end
|
|
|
|
let v: a = {} as A({});
|
|
|
|
// --- fail_control_flow.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
// CHECK:STDERR: fail_control_flow.carbon:[[@LINE+4]]:11-17: error: semantics TODO: `Control flow expressions are currently only supported inside functions.` [SemanticsTodo]
|
|
// CHECK:STDERR:
|
|
// CHECK:STDERR: fail_control_flow.carbon:[[@LINE+2]]:11-23: error: semantics TODO: `Control flow expressions are currently only supported inside functions.` [SemanticsTodo]
|
|
// CHECK:STDERR:
|
|
alias a = true or false;
|
|
|
|
// --- fail_name_conflict.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class C {}
|
|
|
|
alias a = C;
|
|
// CHECK:STDERR: fail_name_conflict.carbon:[[@LINE+3]]:5: error: duplicate name `a` being declared in the same scope [NameDeclDuplicate]
|
|
// CHECK:STDERR: fail_name_conflict.carbon:[[@LINE-2]]:7: note: name is previously declared here [NameDeclPrevious]
|
|
// CHECK:STDERR:
|
|
var a: C = {};
|
|
|
|
var b: C = {};
|
|
// CHECK:STDERR: fail_name_conflict.carbon:[[@LINE+3]]:7: error: duplicate name `b` being declared in the same scope [NameDeclDuplicate]
|
|
// CHECK:STDERR: fail_name_conflict.carbon:[[@LINE-2]]:5-8: note: name is previously declared here [NameDeclPrevious]
|
|
// CHECK:STDERR:
|
|
alias b = C;
|
|
|
|
// --- fail_not_constant.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
var a: () = ();
|
|
var b: ()* = &a;
|
|
|
|
// CHECK:STDERR: fail_not_constant.carbon:[[@LINE+2]]:11-12: error: alias refers to a runtime value [AliasRequiresConstantValue]
|
|
// CHECK:STDERR:
|
|
alias c = *b;
|
|
|
|
// --- fail_params.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
// CHECK:STDERR: fail_params.carbon:[[@LINE+2]]:8-16: error: `alias` declaration cannot have parameters [UnexpectedDeclNameParams]
|
|
// CHECK:STDERR:
|
|
alias A(T: type) = T*;
|
|
|
|
// --- fail_modifiers.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class Class {}
|
|
|
|
// CHECK:STDERR: fail_modifiers.carbon:[[@LINE+11]]:10-13: error: `base` not allowed on declaration with `abstract` [ModifierNotAllowedWith]
|
|
// CHECK:STDERR: fail_modifiers.carbon:[[@LINE+10]]:1-8: note: `abstract` previously appeared here [ModifierPrevious]
|
|
// CHECK:STDERR:
|
|
// CHECK:STDERR: fail_modifiers.carbon:[[@LINE+8]]:15-21: error: `default` not allowed on declaration with `abstract` [ModifierNotAllowedWith]
|
|
// CHECK:STDERR: fail_modifiers.carbon:[[@LINE+7]]:1-8: note: `abstract` previously appeared here [ModifierPrevious]
|
|
// CHECK:STDERR:
|
|
// CHECK:STDERR: fail_modifiers.carbon:[[@LINE+5]]:23-27: error: `final` not allowed on declaration with `abstract` [ModifierNotAllowedWith]
|
|
// CHECK:STDERR: fail_modifiers.carbon:[[@LINE+4]]:1-8: note: `abstract` previously appeared here [ModifierPrevious]
|
|
// CHECK:STDERR:
|
|
// CHECK:STDERR: fail_modifiers.carbon:[[@LINE+2]]:1-8: error: `abstract` not allowed on `alias` declaration [ModifierNotAllowedOnDeclaration]
|
|
// CHECK:STDERR:
|
|
abstract base default final alias A = Class;
|
|
|
|
// CHECK:STDERR: fail_modifiers.carbon:[[@LINE+2]]:1-4: error: `impl` not allowed on `alias` declaration [ModifierNotAllowedOnDeclaration]
|
|
// CHECK:STDERR:
|
|
impl alias B = Class;
|
|
|
|
// CHECK:STDERR: fail_modifiers.carbon:[[@LINE+2]]:1-6: error: `extern` not allowed on `alias` declaration [ModifierNotAllowedOnDeclaration]
|
|
// CHECK:STDERR:
|
|
extern alias C = Class;
|
|
|
|
// CHECK:STDOUT: --- alias.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
|
// CHECK:STDOUT: %C: type = class_type @C [concrete]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: %C.ref: type = name_ref C, %C.decl [concrete = constants.%C]
|
|
// CHECK:STDOUT: %c: type = alias_binding c, %C.ref [concrete = constants.%C]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @__global_init() {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: <elided>
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: --- alias_of_alias.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
|
// CHECK:STDOUT: %C: type = class_type @C [concrete]
|
|
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
|
|
// CHECK:STDOUT: %pattern_type: type = pattern_type %C [concrete]
|
|
// CHECK:STDOUT: %d.patt: %pattern_type = value_binding_pattern d [concrete]
|
|
// CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %C.val: %C = struct_value () [concrete]
|
|
// CHECK:STDOUT: %.115: ref %C = temporary invalid, %C.val [concrete]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: %C.ref: type = name_ref C, %C.decl [concrete = constants.%C]
|
|
// CHECK:STDOUT: %a: type = alias_binding a, %C.ref [concrete = constants.%C]
|
|
// CHECK:STDOUT: %a.ref: type = name_ref a, %a [concrete = constants.%C]
|
|
// CHECK:STDOUT: %b: type = alias_binding b, %a.ref [concrete = constants.%C]
|
|
// CHECK:STDOUT: %b.ref: type = name_ref b, %b [concrete = constants.%C]
|
|
// CHECK:STDOUT: %c: type = alias_binding c, %b.ref [concrete = constants.%C]
|
|
// CHECK:STDOUT: %.loc10_13.1: ref %C = temporary_storage
|
|
// CHECK:STDOUT: %.loc10_13.2: init %C to %.loc10_13.1 = class_init () [concrete = constants.%C.val]
|
|
// CHECK:STDOUT: %.loc10_13.3: init %C = converted @__global_init.%.loc10, %.loc10_13.2 [concrete = constants.%C.val]
|
|
// CHECK:STDOUT: %.loc10_13.4: ref %C = temporary %.loc10_13.1, %.loc10_13.3 [concrete = constants.%.115]
|
|
// CHECK:STDOUT: %.loc10_13.5: %C = acquire_value %.loc10_13.4 [concrete = constants.%C.val]
|
|
// CHECK:STDOUT: %c.ref: type = name_ref c, %c [concrete = constants.%C]
|
|
// CHECK:STDOUT: %d: %C = wrapper_binding d, %.loc10_13.5
|
|
// CHECK:STDOUT: name_binding_decl {
|
|
// CHECK:STDOUT: %d.patt: %pattern_type = value_binding_pattern d [concrete = constants.%d.patt]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @__global_init() {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %.loc10: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
|
|
// CHECK:STDOUT: <elided>
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: --- alias_to_generic.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: type: type = facet_type <type> [concrete]
|
|
// CHECK:STDOUT: %A.type: type = parameterized_class_name_type @A [concrete]
|
|
// CHECK:STDOUT: %A.generic: %A.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
|
|
// CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %A.e9e: type = class_type @A, @A(%empty_struct_type) [concrete]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: %A.ref: %A.type = name_ref A, %A.decl [concrete = constants.%A.generic]
|
|
// CHECK:STDOUT: %.loc7_14: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
|
|
// CHECK:STDOUT: %.loc7_15: type = converted %.loc7_14, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
|
|
// CHECK:STDOUT: %A: type = class_type @A, @A(constants.%empty_struct_type) [concrete = constants.%A.e9e]
|
|
// CHECK:STDOUT: %a: type = alias_binding a, %A [concrete = constants.%A.e9e]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @__global_init() {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: <elided>
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|