mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Fix crash when importing an invalid impl (#5875)
Dropping this in with basic.carbon as an aspirational way to encourage more tests there. This currently crashes because `CollectCandidateImplsForQuery` tries building a type structure which cannot contain `ErrorInst`.
This commit is contained in:
+40
-44
@@ -3,8 +3,6 @@
|
||||
// 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:
|
||||
@@ -12,41 +10,67 @@
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/basic.carbon
|
||||
|
||||
// --- basic.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
interface Simple {
|
||||
fn F();
|
||||
}
|
||||
|
||||
class C {}
|
||||
|
||||
//@dump-sem-ir-begin
|
||||
impl C as Simple {
|
||||
fn F() {}
|
||||
}
|
||||
//@dump-sem-ir-end
|
||||
|
||||
// --- fail_invalid_impl.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
interface I {
|
||||
fn Op[self: Self]();
|
||||
}
|
||||
|
||||
class C {}
|
||||
|
||||
// This produces an invalid impl.
|
||||
// CHECK:STDERR: fail_invalid_impl.carbon:[[@LINE+4]]:6: error: name `Unknown` not found [NameNotFound]
|
||||
// CHECK:STDERR: impl Unknown as I {
|
||||
// CHECK:STDERR: ^~~~~~~
|
||||
// CHECK:STDERR:
|
||||
impl Unknown as I {
|
||||
fn Op[self: Self]() {}
|
||||
}
|
||||
|
||||
// --- fail_import_invalid_impl.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
import library "invalid_impl";
|
||||
|
||||
fn F() {
|
||||
// This impl doesn't exist, but it still tests that we can ignore the
|
||||
// `impl Unknown as I` on import.
|
||||
// CHECK:STDERR: fail_import_invalid_impl.carbon:[[@LINE+4]]:3: error: cannot access member of interface `I` in type `type` that does not implement that interface [MissingImplInMemberAccess]
|
||||
// CHECK:STDERR: C.(I.Op)();
|
||||
// CHECK:STDERR: ^~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
C.(I.Op)();
|
||||
}
|
||||
|
||||
// CHECK:STDOUT: --- basic.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: %Simple.type: type = facet_type <@Simple> [concrete]
|
||||
// CHECK:STDOUT: %Self: %Simple.type = bind_symbolic_name Self, 0 [symbolic]
|
||||
// CHECK:STDOUT: %Simple.F.type: type = fn_type @Simple.F [concrete]
|
||||
// CHECK:STDOUT: %Simple.F: %Simple.F.type = struct_value () [concrete]
|
||||
// CHECK:STDOUT: %Simple.assoc_type: type = assoc_entity_type @Simple [concrete]
|
||||
// CHECK:STDOUT: %assoc0: %Simple.assoc_type = assoc_entity element0, @Simple.%Simple.F.decl [concrete]
|
||||
// CHECK:STDOUT: %C: type = class_type @C [concrete]
|
||||
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
|
||||
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
|
||||
// CHECK:STDOUT: %Simple.impl_witness: <witness> = impl_witness file.%Simple.impl_witness_table [concrete]
|
||||
// CHECK:STDOUT: %C.as.Simple.impl.F.type: type = fn_type @C.as.Simple.impl.F [concrete]
|
||||
// CHECK:STDOUT: %C.as.Simple.impl.F: %C.as.Simple.impl.F.type = struct_value () [concrete]
|
||||
// CHECK:STDOUT: %Simple.facet: %Simple.type = facet_value %C, (%Simple.impl_witness) [concrete]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: file {
|
||||
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
|
||||
// CHECK:STDOUT: .Simple = %Simple.decl
|
||||
// CHECK:STDOUT: .C = %C.decl
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %Simple.decl: type = interface_decl @Simple [concrete = constants.%Simple.type] {} {}
|
||||
// CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
|
||||
// CHECK:STDOUT: impl_decl @C.as.Simple.impl [concrete] {} {
|
||||
// CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
|
||||
// CHECK:STDOUT: %Simple.ref: type = name_ref Simple, file.%Simple.decl [concrete = constants.%Simple.type]
|
||||
@@ -55,17 +79,6 @@ impl C as Simple {
|
||||
// CHECK:STDOUT: %Simple.impl_witness: <witness> = impl_witness %Simple.impl_witness_table [concrete = constants.%Simple.impl_witness]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: interface @Simple {
|
||||
// CHECK:STDOUT: %Self: %Simple.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
|
||||
// CHECK:STDOUT: %Simple.F.decl: %Simple.F.type = fn_decl @Simple.F [concrete = constants.%Simple.F] {} {}
|
||||
// CHECK:STDOUT: %assoc0: %Simple.assoc_type = assoc_entity element0, %Simple.F.decl [concrete = constants.%assoc0]
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: !members:
|
||||
// CHECK:STDOUT: .Self = %Self
|
||||
// CHECK:STDOUT: .F = %assoc0
|
||||
// CHECK:STDOUT: witness = (%Simple.F.decl)
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: impl @C.as.Simple.impl: %C.ref as %Simple.ref {
|
||||
// CHECK:STDOUT: %C.as.Simple.impl.F.decl: %C.as.Simple.impl.F.type = fn_decl @C.as.Simple.impl.F [concrete = constants.%C.as.Simple.impl.F] {} {}
|
||||
// CHECK:STDOUT:
|
||||
@@ -74,25 +87,8 @@ impl C as Simple {
|
||||
// CHECK:STDOUT: witness = file.%Simple.impl_witness
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: class @C {
|
||||
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
|
||||
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
|
||||
// CHECK:STDOUT: complete_type_witness = %complete_type
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: !members:
|
||||
// CHECK:STDOUT: .Self = constants.%C
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: generic fn @Simple.F(@Simple.%Self: %Simple.type) {
|
||||
// CHECK:STDOUT: fn();
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: fn @C.as.Simple.impl.F() {
|
||||
// CHECK:STDOUT: !entry:
|
||||
// CHECK:STDOUT: return
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: specific @Simple.F(constants.%Self) {}
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: specific @Simple.F(constants.%Simple.facet) {}
|
||||
// CHECK:STDOUT:
|
||||
|
||||
@@ -79,6 +79,7 @@ auto TypeIterator::Next() -> Step {
|
||||
|
||||
case SemIR::AssociatedEntityType::Kind:
|
||||
case SemIR::BoolType::Kind:
|
||||
case SemIR::ErrorInst::Kind:
|
||||
case SemIR::FacetType::Kind:
|
||||
case SemIR::FloatType::Kind:
|
||||
case SemIR::FunctionType::Kind:
|
||||
|
||||
Reference in New Issue
Block a user