mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-21 16:36:41 +00:00
Historically, we disabled the rendered form in tests outside of `toolchain/diagnostics`. The idea was to keep tests shorter and avoid very long chains of autoupdate before stabilizing due to all the line numbers and other artifacts in the rendered form. This PR adds `--diagnostic-line-numbers=[all|first]` and defaults to `first` in tests. This keeps the rendered form so that we can easily code review that form and the visual cues it does or doesn't provide. But it removes all but the first location's line numbers to provide significantly more stability in tests. By default, tests get the full unicode line-drawing form of diagnostics so we can ensure all of the artifacts there make sense with the specific case being diagnosed, but we do retain some focused ASCII-rendering tests to ensure that fallback remains usable. There are some issues here that will be fixed in subsequent PRs. Notably, we try to keep the frame together in the check lines, and so force some parts to use the first location. This largely works, but fails in some edge cases, causing the entire frame to be located incorrectly. There is a TODO about this that we need to fix, and it only occurs 6 times across the test suite, so it didn't seem worth front-loading a fix for here. Assisted-by: Claude Code
183 lines
10 KiB
Plaintext
183 lines
10 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/interop/cpp/class/import/override.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/class/import/override.carbon
|
|
|
|
// --- overload.h
|
|
|
|
struct X {};
|
|
struct Y {};
|
|
|
|
struct OverloadedBase {
|
|
virtual void f(X x);
|
|
virtual void f(Y y);
|
|
virtual void f(X x, Y y);
|
|
};
|
|
|
|
// --- overload_arity.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
import Cpp library "overload.h";
|
|
|
|
class Overload2Params {
|
|
extend base: Cpp.OverloadedBase;
|
|
override fn f(self, x: Cpp.X, y: Cpp.Y);
|
|
}
|
|
|
|
// --- fail_overload_no_matching_arity.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
import Cpp library "overload.h";
|
|
|
|
class Overload0Params {
|
|
extend base: Cpp.OverloadedBase;
|
|
//
|
|
// CHECK:STDERR: ╭─┤ fail_overload_no_matching_arity.carbon:[[@LINE+24]]:3
|
|
// CHECK:STDERR: -> │ override fn f(self);
|
|
// CHECK:STDERR: · ━━━━━━━━━━┳━━━━━━━━━
|
|
// CHECK:STDERR: · ┗━━┫ error: override without compatible virtual in base class
|
|
// CHECK:STDERR: · ┃ [OverrideWithoutVirtualInBase]
|
|
// CHECK:STDERR: ┆
|
|
// CHECK:STDERR: ├─┤ ./overload.h
|
|
// CHECK:STDERR: │ virtual void f(X x);
|
|
// CHECK:STDERR: · ┬
|
|
// CHECK:STDERR: · ╰──┤ base class function has more parameters (1 vs 0 excluding
|
|
// CHECK:STDERR: · │ `self`)
|
|
// CHECK:STDERR: · │ [OverrideCandidateArityMismatch]
|
|
// CHECK:STDERR: │ virtual void f(Y y);
|
|
// CHECK:STDERR: · ┬
|
|
// CHECK:STDERR: · ╰──┤ base class function has more parameters (1 vs 0 excluding
|
|
// CHECK:STDERR: · │ `self`)
|
|
// CHECK:STDERR: · │ [OverrideCandidateArityMismatch]
|
|
// CHECK:STDERR: │ virtual void f(X x, Y y);
|
|
// CHECK:STDERR: · ┬
|
|
// CHECK:STDERR: · ╰──┤ base class function has more parameters (2 vs 0 excluding
|
|
// CHECK:STDERR: · │ `self`)
|
|
// CHECK:STDERR: · │ [OverrideCandidateArityMismatch]
|
|
// CHECK:STDERR: ╰────
|
|
// CHECK:STDERR:
|
|
override fn f(self);
|
|
}
|
|
|
|
class Overload3Params {
|
|
extend base: Cpp.OverloadedBase;
|
|
//
|
|
// CHECK:STDERR: ╭─┤ fail_overload_no_matching_arity.carbon:[[@LINE+24]]:3
|
|
// CHECK:STDERR: -> │ override fn f(self, x: Cpp.X, y: Cpp.Y, z: Cpp.X);
|
|
// CHECK:STDERR: · ━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
// CHECK:STDERR: · ┗━━┫ error: override without compatible virtual in base class
|
|
// CHECK:STDERR: · ┃ [OverrideWithoutVirtualInBase]
|
|
// CHECK:STDERR: ┆
|
|
// CHECK:STDERR: ├─┤ ./overload.h
|
|
// CHECK:STDERR: │ virtual void f(X x);
|
|
// CHECK:STDERR: · ┬
|
|
// CHECK:STDERR: · ╰──┤ base class function has fewer parameters (1 vs 3 excluding
|
|
// CHECK:STDERR: · │ `self`)
|
|
// CHECK:STDERR: · │ [OverrideCandidateArityMismatch]
|
|
// CHECK:STDERR: │ virtual void f(Y y);
|
|
// CHECK:STDERR: · ┬
|
|
// CHECK:STDERR: · ╰──┤ base class function has fewer parameters (1 vs 3 excluding
|
|
// CHECK:STDERR: · │ `self`)
|
|
// CHECK:STDERR: · │ [OverrideCandidateArityMismatch]
|
|
// CHECK:STDERR: │ virtual void f(X x, Y y);
|
|
// CHECK:STDERR: · ┬
|
|
// CHECK:STDERR: · ╰──┤ base class function has fewer parameters (2 vs 3 excluding
|
|
// CHECK:STDERR: · │ `self`)
|
|
// CHECK:STDERR: · │ [OverrideCandidateArityMismatch]
|
|
// CHECK:STDERR: ╰────
|
|
// CHECK:STDERR:
|
|
override fn f(self, x: Cpp.X, y: Cpp.Y, z: Cpp.X);
|
|
}
|
|
|
|
// --- fail_overload_type.carbon
|
|
// TODO: The conversion diagnostics here should have a location.
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
import Cpp library "overload.h";
|
|
|
|
class OverloadX {
|
|
extend base: Cpp.OverloadedBase;
|
|
//
|
|
// CHECK:STDERR: ╭─┤ fail_overload_type.carbon:[[@LINE+32]]:3
|
|
// CHECK:STDERR: -> │ override fn f(self, x: Cpp.X);
|
|
// CHECK:STDERR: · ━━━━━━━━━━━━━━━┳━━━━┯━━━━━━━━━
|
|
// CHECK:STDERR: · ┗━━━━━━━┫ error: cannot implicitly convert expression of type
|
|
// CHECK:STDERR: · │ │ ┃ `Cpp.Y` to `Cpp.X`
|
|
// CHECK:STDERR: · │ │ ┃ [ConversionFailure]
|
|
// CHECK:STDERR: · ╰─────────┤ type `Cpp.Y` does not implement interface
|
|
// CHECK:STDERR: · │ │ `Core.ImplicitAs(Cpp.X)`
|
|
// CHECK:STDERR: · │ │ [MissingImplInMemberAccessInContext]
|
|
// CHECK:STDERR: · ╰──────┤ initializing function parameter
|
|
// CHECK:STDERR: · │ [InCallToFunctionParam]
|
|
// CHECK:STDERR: ╰────
|
|
// CHECK:STDERR:
|
|
// CHECK:STDERR: ╭─┤ fail_overload_type.carbon:[[@LINE+19]]:3
|
|
// CHECK:STDERR: -> │ override fn f(self, x: Cpp.X);
|
|
// CHECK:STDERR: · ━━━━━━━━━━━━━━━┳━━━━┯━━━━━━━━━
|
|
// CHECK:STDERR: · ┗━━━━━━━┫ error: cannot implicitly convert expression of type
|
|
// CHECK:STDERR: · │ │ ┃ `Cpp.Y` to `Cpp.X`
|
|
// CHECK:STDERR: · │ │ ┃ [ConversionFailure]
|
|
// CHECK:STDERR: · ╰─────────┤ type `Cpp.Y` does not implement interface
|
|
// CHECK:STDERR: · │ │ `Core.ImplicitAs(Cpp.X)`
|
|
// CHECK:STDERR: · │ │ [MissingImplInMemberAccessInContext]
|
|
// CHECK:STDERR: · ╰──────┤ initializing function parameter
|
|
// CHECK:STDERR: · │ [InCallToFunctionParam]
|
|
// CHECK:STDERR: ┆
|
|
// CHECK:STDERR: ├─┤ ./overload.h
|
|
// CHECK:STDERR: │ virtual void f(Y y);
|
|
// CHECK:STDERR: · ┬
|
|
// CHECK:STDERR: · ╰──┤ while building thunk to match the signature of this function
|
|
// CHECK:STDERR: · │ [ThunkSignature]
|
|
// CHECK:STDERR: ╰────
|
|
// CHECK:STDERR:
|
|
override fn f(self, x: Cpp.X);
|
|
}
|
|
|
|
class OverloadY {
|
|
extend base: Cpp.OverloadedBase;
|
|
//
|
|
// CHECK:STDERR: ╭─┤ fail_overload_type.carbon:[[@LINE+32]]:3
|
|
// CHECK:STDERR: -> │ override fn f(self, y: Cpp.Y);
|
|
// CHECK:STDERR: · ━━━━━━━━━━━━━━━┳━━━━┯━━━━━━━━━
|
|
// CHECK:STDERR: · ┗━━━━━━━┫ error: cannot implicitly convert expression of type
|
|
// CHECK:STDERR: · │ │ ┃ `Cpp.X` to `Cpp.Y`
|
|
// CHECK:STDERR: · │ │ ┃ [ConversionFailure]
|
|
// CHECK:STDERR: · ╰─────────┤ type `Cpp.X` does not implement interface
|
|
// CHECK:STDERR: · │ │ `Core.ImplicitAs(Cpp.Y)`
|
|
// CHECK:STDERR: · │ │ [MissingImplInMemberAccessInContext]
|
|
// CHECK:STDERR: · ╰──────┤ initializing function parameter
|
|
// CHECK:STDERR: · │ [InCallToFunctionParam]
|
|
// CHECK:STDERR: ╰────
|
|
// CHECK:STDERR:
|
|
// CHECK:STDERR: ╭─┤ fail_overload_type.carbon:[[@LINE+19]]:3
|
|
// CHECK:STDERR: -> │ override fn f(self, y: Cpp.Y);
|
|
// CHECK:STDERR: · ━━━━━━━━━━━━━━━┳━━━━┯━━━━━━━━━
|
|
// CHECK:STDERR: · ┗━━━━━━━┫ error: cannot implicitly convert expression of type
|
|
// CHECK:STDERR: · │ │ ┃ `Cpp.X` to `Cpp.Y`
|
|
// CHECK:STDERR: · │ │ ┃ [ConversionFailure]
|
|
// CHECK:STDERR: · ╰─────────┤ type `Cpp.X` does not implement interface
|
|
// CHECK:STDERR: · │ │ `Core.ImplicitAs(Cpp.Y)`
|
|
// CHECK:STDERR: · │ │ [MissingImplInMemberAccessInContext]
|
|
// CHECK:STDERR: · ╰──────┤ initializing function parameter
|
|
// CHECK:STDERR: · │ [InCallToFunctionParam]
|
|
// CHECK:STDERR: ┆
|
|
// CHECK:STDERR: ├─┤ ./overload.h
|
|
// CHECK:STDERR: │ virtual void f(X x);
|
|
// CHECK:STDERR: · ┬
|
|
// CHECK:STDERR: · ╰──┤ while building thunk to match the signature of this function
|
|
// CHECK:STDERR: · │ [ThunkSignature]
|
|
// CHECK:STDERR: ╰────
|
|
// CHECK:STDERR:
|
|
override fn f(self, y: Cpp.Y);
|
|
}
|