mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-22 10:42:38 +00:00
There were a number of iterations on the design that weren't reflected in the initial port to the terminal rendering library. This PR tries to complete the rendering side of things to match the design we landed on: code-focused, with messages attached by lines to the code, and condensed as much as possible to avoid the vertical space. It also improves the styling to make things more visually distinguishable such as adding a `->` to the main error line, and making the underlines and connectors for it have a heavy weight (when the font supports that). Another major change is having multiple messages on a single line be drawn in source lexical order. This requires the connectors to cross without joining, but makes it easier to read the messages. This PR also has some refactorings to enable these improvements, and a _number_ of improvements to comment prose and terminology to try and avoid jargon and make things read more naturally. Sorry for the fact that Claude left a bunch of this mannerly language in comments despite my efforts, but I'm continuing to try and drive the prose towards something direct and simple to read. Some of the terminology improvements also needed to be made in the design doc and those have been made here. Note that I don't think this rendering is perfect or should be viewed as final. I'm happy to iterate on it further, and have a few adjustments in mind already, but would like to focus this on getting the _implementation_ of the current rendering design in place, and then we can make targeted changes or tweaks as needed. For example, I'm not yet fully happy with the rendering when messages are too long and we move them all the way to the left, but am leaving that for a follow-up. Assisted-by: Claude Code
268 lines
8.8 KiB
Plaintext
268 lines
8.8 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/impl/redeclaration.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/redeclaration.carbon
|
|
|
|
// --- redeclaration_no_class.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
interface Z {}
|
|
|
|
impl {} as Z;
|
|
impl {} as Z {}
|
|
|
|
// --- redeclaration_in_class.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
interface Z {}
|
|
|
|
// `impl as Z` is normalized to `impl Self as Z` so they are treated as
|
|
// syntactically the same.
|
|
class C {
|
|
impl as Z;
|
|
impl as Z;
|
|
impl Self as Z {}
|
|
}
|
|
|
|
class D {
|
|
impl Self as Z;
|
|
impl Self as Z;
|
|
impl as Z {}
|
|
}
|
|
|
|
// --- fail_todo_redeclaration_reenter_class.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
interface Z {}
|
|
|
|
class C;
|
|
|
|
class C {
|
|
impl as Z;
|
|
}
|
|
|
|
// TODO: This should typecheck (see #5366).
|
|
// CHECK:STDERR: fail_todo_redeclaration_reenter_class.carbon:[[@LINE+6]]:9-10: error: expected expression [ExpectedExpr]
|
|
// CHECK:STDERR:
|
|
// CHECK:STDERR: fail_todo_redeclaration_reenter_class.carbon:[[@LINE+4]]:9-10: error: semantics TODO: `handle invalid parse trees in `check`` [SemanticsTodo]
|
|
// CHECK:STDERR:
|
|
// CHECK:STDERR: fail_todo_redeclaration_reenter_class.carbon:[[@LINE+2]]:15: error: expected `as` in `impl` declaration [ImplExpectedAs]
|
|
// CHECK:STDERR:
|
|
impl C.(as Z) {}
|
|
|
|
// --- fail_todo_redeclaration_reenter_class_explicit_self.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
interface Z {}
|
|
|
|
class C;
|
|
|
|
class C {
|
|
impl Self as Z;
|
|
}
|
|
|
|
// TODO: This should typecheck (see #5366).
|
|
// CHECK:STDERR: fail_todo_redeclaration_reenter_class_explicit_self.carbon:[[@LINE+6]]:9-12: error: name `Self` not found [NameNotFound]
|
|
// CHECK:STDERR:
|
|
// CHECK:STDERR: fail_todo_redeclaration_reenter_class_explicit_self.carbon:[[@LINE+4]]:20: error: expected `as` in `impl` declaration [ImplExpectedAs]
|
|
// CHECK:STDERR:
|
|
// CHECK:STDERR: fail_todo_redeclaration_reenter_class_explicit_self.carbon:[[@LINE+2]]:1-21: error: semantics TODO: `handle invalid parse trees in `check`` [SemanticsTodo]
|
|
// CHECK:STDERR:
|
|
impl C.(Self as Z) {}
|
|
|
|
// --- fail_todo_redeclaration_reenter_class_mixed_self_outside.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
interface Z {}
|
|
|
|
class C {
|
|
impl as Z;
|
|
}
|
|
|
|
// TODO: This should typecheck (see #5366).
|
|
// CHECK:STDERR: fail_todo_redeclaration_reenter_class_mixed_self_outside.carbon:[[@LINE+6]]:9-12: error: name `Self` not found [NameNotFound]
|
|
// CHECK:STDERR:
|
|
// CHECK:STDERR: fail_todo_redeclaration_reenter_class_mixed_self_outside.carbon:[[@LINE+4]]:20: error: expected `as` in `impl` declaration [ImplExpectedAs]
|
|
// CHECK:STDERR:
|
|
// CHECK:STDERR: fail_todo_redeclaration_reenter_class_mixed_self_outside.carbon:[[@LINE+2]]:1-21: error: semantics TODO: `handle invalid parse trees in `check`` [SemanticsTodo]
|
|
// CHECK:STDERR:
|
|
impl C.(Self as Z) {}
|
|
|
|
// --- fail_todo_redeclaration_reenter_class_mixed_self_inside.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
interface Z {}
|
|
|
|
class C {
|
|
impl Self as Z;
|
|
}
|
|
|
|
// TODO: This should typecheck (see #5366).
|
|
// CHECK:STDERR: fail_todo_redeclaration_reenter_class_mixed_self_inside.carbon:[[@LINE+6]]:9-10: error: expected expression [ExpectedExpr]
|
|
// CHECK:STDERR:
|
|
// CHECK:STDERR: fail_todo_redeclaration_reenter_class_mixed_self_inside.carbon:[[@LINE+4]]:9-10: error: semantics TODO: `handle invalid parse trees in `check`` [SemanticsTodo]
|
|
// CHECK:STDERR:
|
|
// CHECK:STDERR: fail_todo_redeclaration_reenter_class_mixed_self_inside.carbon:[[@LINE+2]]:15: error: expected `as` in `impl` declaration [ImplExpectedAs]
|
|
// CHECK:STDERR:
|
|
impl C.(as Z) {}
|
|
|
|
// --- fail_redeclaration_inside_class_is_separate_impl.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
interface Z {}
|
|
|
|
class C;
|
|
impl C as Z;
|
|
|
|
class C {
|
|
// CHECK:STDERR: fail_redeclaration_inside_class_is_separate_impl.carbon:[[@LINE+1]]:3-15: error: found non-final `impl` with the same type structure as another non-final `impl` [ImplNonFinalSameTypeStructure]
|
|
impl C as Z {}
|
|
}
|
|
|
|
// CHECK:STDERR: fail_redeclaration_inside_class_is_separate_impl.carbon:[[@LINE+2]]:1-13: note: other `impl` here [ImplNonFinalSameTypeStructureNote]
|
|
// CHECK:STDERR:
|
|
impl C as Z {}
|
|
|
|
// --- fail_redeclaration_outside_class_is_separate_impl.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
interface Z {}
|
|
|
|
class C {
|
|
impl C as Z {}
|
|
}
|
|
|
|
// CHECK:STDERR: fail_redeclaration_outside_class_is_separate_impl.carbon:[[@LINE+3]]:1-13: error: found non-final `impl` with the same type structure as another non-final `impl` [ImplNonFinalSameTypeStructure]
|
|
// CHECK:STDERR: fail_redeclaration_outside_class_is_separate_impl.carbon:[[@LINE-4]]:3-15: note: other `impl` here [ImplNonFinalSameTypeStructureNote]
|
|
// CHECK:STDERR:
|
|
impl C as Z {}
|
|
|
|
// --- fail_redeclaration_in_block_scope_is_separate_impl.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
interface Z {}
|
|
|
|
fn F() {
|
|
musteval fn G() -> auto {
|
|
class C {}
|
|
impl C as Z {}
|
|
return C;
|
|
}
|
|
// This is not a redeclaration, since it's in a different scope.
|
|
// CHECK:STDERR: fail_redeclaration_in_block_scope_is_separate_impl.carbon:[[@LINE+3]]:3-17: error: found non-final `impl` with the same type structure as another non-final `impl` [ImplNonFinalSameTypeStructure]
|
|
// CHECK:STDERR: fail_redeclaration_in_block_scope_is_separate_impl.carbon:[[@LINE-5]]:5-17: note: other `impl` here [ImplNonFinalSameTypeStructureNote]
|
|
// CHECK:STDERR:
|
|
impl G() as Z {}
|
|
}
|
|
|
|
// --- redecl_of_imported_impl.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
interface Z {}
|
|
class C {}
|
|
impl C as Z {}
|
|
|
|
// --- fail_redecl_of_imported_impl.impl.carbon
|
|
impl library "[[@TEST_NAME]]";
|
|
|
|
// CHECK:STDERR: fail_redecl_of_imported_impl.impl.carbon:[[@LINE+2]]:1-13: error: redeclaration of imported impl [RedeclImportedImpl]
|
|
// CHECK:STDERR:
|
|
impl C as Z {}
|
|
|
|
// --- decl_of_imported_impl_in_new_scope.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
interface Z {}
|
|
class C {}
|
|
impl C as Z {}
|
|
|
|
// --- fail_decl_of_imported_impl_in_new_scope.impl.carbon
|
|
impl library "[[@TEST_NAME]]";
|
|
|
|
class D {
|
|
// This is not treated as a redeclaration since it is in a different scope.
|
|
// But that means it overlaps fully with the impl from the api file, which is
|
|
// a separate error.
|
|
|
|
// CHECK:STDERR: fail_decl_of_imported_impl_in_new_scope.impl.carbon:[[@LINE+3]]:3-15: error: found non-final `impl` with the same type structure as another non-final `impl` [ImplNonFinalSameTypeStructure]
|
|
// CHECK:STDERR: decl_of_imported_impl_in_new_scope.carbon:5:1-13: note: other `impl` here [ImplNonFinalSameTypeStructureNote]
|
|
// CHECK:STDERR:
|
|
impl C as Z {}
|
|
}
|
|
|
|
// --- fail_redecl_in_fn_scope.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
interface Z {}
|
|
|
|
fn F() {
|
|
class C {}
|
|
impl C as Z;
|
|
// CHECK:STDERR: fail_redecl_in_fn_scope.carbon:[[@LINE+4]]:3-15: error: impl redeclaration not in a declarative scope; redeclaration is allowed only in a class or namespace [ImplDeclInInvalidScope]
|
|
// CHECK:STDERR:
|
|
// CHECK:STDERR: fail_redecl_in_fn_scope.carbon:[[@LINE-3]]:3-14: error: impl declared but not defined [ImplMissingDefinition]
|
|
// CHECK:STDERR:
|
|
impl C as Z {}
|
|
}
|
|
|
|
// --- fail_redecl_in_different_fn_scope.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
interface Z {}
|
|
class C {}
|
|
|
|
fn F() {
|
|
impl C as Z;
|
|
}
|
|
|
|
fn G() {
|
|
// CHECK:STDERR: fail_redecl_in_different_fn_scope.carbon:[[@LINE+4]]:3-15: error: impl redeclaration not in a declarative scope; redeclaration is allowed only in a class or namespace [ImplDeclInInvalidScope]
|
|
// CHECK:STDERR:
|
|
// CHECK:STDERR: fail_redecl_in_different_fn_scope.carbon:[[@LINE-6]]:3-14: error: impl declared but not defined [ImplMissingDefinition]
|
|
// CHECK:STDERR:
|
|
impl C as Z {}
|
|
}
|
|
|
|
// --- fail_redecl_in_block_scope.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
interface Z {}
|
|
|
|
fn F() {
|
|
if (true) {
|
|
class C {}
|
|
impl C as Z;
|
|
// CHECK:STDERR: fail_redecl_in_block_scope.carbon:[[@LINE+4]]:5-17: error: impl redeclaration not in a declarative scope; redeclaration is allowed only in a class or namespace [ImplDeclInInvalidScope]
|
|
// CHECK:STDERR:
|
|
// CHECK:STDERR: fail_redecl_in_block_scope.carbon:[[@LINE-3]]:5-16: error: impl declared but not defined [ImplMissingDefinition]
|
|
// CHECK:STDERR:
|
|
impl C as Z {}
|
|
}
|
|
}
|
|
|
|
// --- fail_redecl_in_different_block_scope.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
interface Z {}
|
|
class C {}
|
|
|
|
fn F() {
|
|
if (true) {
|
|
impl C as Z;
|
|
}
|
|
if (true) {
|
|
// CHECK:STDERR: fail_redecl_in_different_block_scope.carbon:[[@LINE+4]]:5-17: error: impl redeclaration not in a declarative scope; redeclaration is allowed only in a class or namespace [ImplDeclInInvalidScope]
|
|
// CHECK:STDERR:
|
|
// CHECK:STDERR: fail_redecl_in_different_block_scope.carbon:[[@LINE-5]]:5-16: error: impl declared but not defined [ImplMissingDefinition]
|
|
// CHECK:STDERR:
|
|
impl C as Z {}
|
|
}
|
|
}
|