mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-16 05:38:10 +00:00
We allow using `InstId` as a `LocId` for diagnostics, which works great in `handle_*` functions, where we are working with non-canonical insts. And convert and pattern matching often are given non-canonical insts, which they can use, or pull apart to find some other inst, and use those as a location for diagnostics. However these operations can also be called with canonical insts, which have no location. In that case if we need to diagnose an error, it ends up not being attached to any code at all. Since we always have a `LocId` somewhere up the call stack, pass it along and in these places that handle canonical instructions too, use `GetInstLocationOrFallback()` to get a valid location for diagnostics. This is also similar to what eval does with its fallback `LocId`. The result is that many diagnostics now have a location where they had none before. It also means some insts don't get `<elided>` in formatted semir for not having a location at all and thus not being in range.
103 lines
5.3 KiB
Plaintext
103 lines
5.3 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+6]]:3-22: error: override without compatible virtual in base class [OverrideWithoutVirtualInBase]
|
|
// CHECK:STDERR: included from: fail_overload_no_matching_arity.carbon:[[@LINE-6]]:10 [InCppInclude]
|
|
// CHECK:STDERR: ./overload.h:6:16: note: base class function has more parameters (1 vs 0 excluding `self`) [OverrideCandidateArityMismatch]
|
|
// CHECK:STDERR: ./overload.h:7:16: note: base class function has more parameters (1 vs 0 excluding `self`) [OverrideCandidateArityMismatch]
|
|
// CHECK:STDERR: ./overload.h:8:16: note: base class function has more parameters (2 vs 0 excluding `self`) [OverrideCandidateArityMismatch]
|
|
// CHECK:STDERR:
|
|
override fn f(self);
|
|
}
|
|
|
|
class Overload3Params {
|
|
extend base: Cpp.OverloadedBase;
|
|
//
|
|
// CHECK:STDERR: fail_overload_no_matching_arity.carbon:[[@LINE+6]]:3-52: error: override without compatible virtual in base class [OverrideWithoutVirtualInBase]
|
|
// CHECK:STDERR: included from: fail_overload_no_matching_arity.carbon:[[@LINE-18]]:10 [InCppInclude]
|
|
// CHECK:STDERR: ./overload.h:6:16: note: base class function has fewer parameters (1 vs 3 excluding `self`) [OverrideCandidateArityMismatch]
|
|
// CHECK:STDERR: ./overload.h:7:16: note: base class function has fewer parameters (1 vs 3 excluding `self`) [OverrideCandidateArityMismatch]
|
|
// CHECK:STDERR: ./overload.h:8:16: note: base class function has fewer parameters (2 vs 3 excluding `self`) [OverrideCandidateArityMismatch]
|
|
// 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+10]]:3-32: error: cannot implicitly convert expression of type `Cpp.Y` to `Cpp.X` [ConversionFailure]
|
|
// CHECK:STDERR: fail_overload_type.carbon:[[@LINE+9]]:3-32: note: type `Cpp.Y` does not implement interface `Core.ImplicitAs(Cpp.X)` [MissingImplInMemberAccessInContext]
|
|
// CHECK:STDERR: fail_overload_type.carbon:[[@LINE+8]]:23-30: note: initializing function parameter [InCallToFunctionParam]
|
|
// CHECK:STDERR:
|
|
// CHECK:STDERR: fail_overload_type.carbon:[[@LINE+6]]:3-32: error: cannot implicitly convert expression of type `Cpp.Y` to `Cpp.X` [ConversionFailure]
|
|
// CHECK:STDERR: fail_overload_type.carbon:[[@LINE+5]]:3-32: note: type `Cpp.Y` does not implement interface `Core.ImplicitAs(Cpp.X)` [MissingImplInMemberAccessInContext]
|
|
// CHECK:STDERR: fail_overload_type.carbon:[[@LINE+4]]:23-30: note: initializing function parameter [InCallToFunctionParam]
|
|
// CHECK:STDERR: included from: fail_overload_type.carbon:[[@LINE-12]]:10 [InCppInclude]
|
|
// CHECK:STDERR: ./overload.h:7:16: note: while building thunk to match the signature of this function [ThunkSignature]
|
|
// CHECK:STDERR:
|
|
override fn f(self, x: Cpp.X);
|
|
}
|
|
|
|
class OverloadY {
|
|
extend base: Cpp.OverloadedBase;
|
|
//
|
|
// CHECK:STDERR: fail_overload_type.carbon:[[@LINE+10]]:3-32: error: cannot implicitly convert expression of type `Cpp.X` to `Cpp.Y` [ConversionFailure]
|
|
// CHECK:STDERR: fail_overload_type.carbon:[[@LINE+9]]:3-32: note: type `Cpp.X` does not implement interface `Core.ImplicitAs(Cpp.Y)` [MissingImplInMemberAccessInContext]
|
|
// CHECK:STDERR: fail_overload_type.carbon:[[@LINE+8]]:23-30: note: initializing function parameter [InCallToFunctionParam]
|
|
// CHECK:STDERR:
|
|
// CHECK:STDERR: fail_overload_type.carbon:[[@LINE+6]]:3-32: error: cannot implicitly convert expression of type `Cpp.X` to `Cpp.Y` [ConversionFailure]
|
|
// CHECK:STDERR: fail_overload_type.carbon:[[@LINE+5]]:3-32: note: type `Cpp.X` does not implement interface `Core.ImplicitAs(Cpp.Y)` [MissingImplInMemberAccessInContext]
|
|
// CHECK:STDERR: fail_overload_type.carbon:[[@LINE+4]]:23-30: note: initializing function parameter [InCallToFunctionParam]
|
|
// CHECK:STDERR: included from: fail_overload_type.carbon:[[@LINE-28]]:10 [InCppInclude]
|
|
// CHECK:STDERR: ./overload.h:6:16: note: while building thunk to match the signature of this function [ThunkSignature]
|
|
// CHECK:STDERR:
|
|
override fn f(self, y: Cpp.Y);
|
|
}
|