From 572ca38ba5fdfa4a70097939e7c1c88a4b92b276 Mon Sep 17 00:00:00 2001 From: Josh L Date: Tue, 5 Nov 2024 01:38:37 +0000 Subject: [PATCH] Add test coverage for `ImplOfUndefinedInterface` diagnostic --- .../fail_undefined_interface.carbon | 102 ++++++++++++++++++ toolchain/diagnostics/coverage_test.cpp | 1 - 2 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 toolchain/check/testdata/impl/no_prelude/fail_undefined_interface.carbon diff --git a/toolchain/check/testdata/impl/no_prelude/fail_undefined_interface.carbon b/toolchain/check/testdata/impl/no_prelude/fail_undefined_interface.carbon new file mode 100644 index 0000000000000..07f5a6967d18d --- /dev/null +++ b/toolchain/check/testdata/impl/no_prelude/fail_undefined_interface.carbon @@ -0,0 +1,102 @@ +// 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 +// +// AUTOUPDATE +// TIP: To test this file alone, run: +// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/impl/no_prelude/fail_undefined_interface.carbon +// TIP: To dump output, run: +// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/no_prelude/fail_undefined_interface.carbon + +// --- fail_empty_struct.carbon + +library "[[@TEST_NAME]]"; + +interface I; +// CHECK:STDERR: fail_empty_struct.carbon:[[@LINE+7]]:1: error: implementation of undefined interface I [ImplOfUndefinedInterface] +// CHECK:STDERR: impl {} as I {} +// CHECK:STDERR: ^~~~~~~~~~~~~~ +// CHECK:STDERR: fail_empty_struct.carbon:[[@LINE-4]]:1: note: interface was forward declared here [InterfaceForwardDeclaredHere] +// CHECK:STDERR: interface I; +// CHECK:STDERR: ^~~~~~~~~~~~ +// CHECK:STDERR: +impl {} as I {} + +// --- fail_class.carbon + +library "[[@TEST_NAME]]"; + +interface J; +class C {} +// CHECK:STDERR: fail_class.carbon:[[@LINE+6]]:1: error: implementation of undefined interface J [ImplOfUndefinedInterface] +// CHECK:STDERR: impl C as J {} +// CHECK:STDERR: ^~~~~~~~~~~~~ +// CHECK:STDERR: fail_class.carbon:[[@LINE-5]]:1: note: interface was forward declared here [InterfaceForwardDeclaredHere] +// CHECK:STDERR: interface J; +// CHECK:STDERR: ^~~~~~~~~~~~ +impl C as J {} + +// CHECK:STDOUT: --- fail_empty_struct.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: constants { +// CHECK:STDOUT: %I.type: type = interface_type @I [template] +// CHECK:STDOUT: %.1: type = struct_type {} [template] +// CHECK:STDOUT: %.2: type = tuple_type () [template] +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: package: = namespace [template] { +// CHECK:STDOUT: .I = %I.decl +// CHECK:STDOUT: } +// CHECK:STDOUT: %I.decl: type = interface_decl @I [template = constants.%I.type] {} {} +// CHECK:STDOUT: impl_decl @impl [template] {} { +// CHECK:STDOUT: %.loc12_7.1: %.1 = struct_literal () +// CHECK:STDOUT: %.loc12_7.2: type = converted %.loc12_7.1, constants.%.1 [template = constants.%.1] +// CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [template = constants.%I.type] +// CHECK:STDOUT: } +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: interface @I; +// CHECK:STDOUT: +// CHECK:STDOUT: impl @impl: %.loc12_7.2 as %I.ref { +// CHECK:STDOUT: !members: +// CHECK:STDOUT: witness = +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: --- fail_class.carbon +// CHECK:STDOUT: +// CHECK:STDOUT: constants { +// CHECK:STDOUT: %J.type: type = interface_type @J [template] +// CHECK:STDOUT: %C: type = class_type @C [template] +// CHECK:STDOUT: %.1: type = struct_type {} [template] +// CHECK:STDOUT: %.2: = complete_type_witness %.1 [template] +// CHECK:STDOUT: %.3: type = tuple_type () [template] +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: file { +// CHECK:STDOUT: package: = namespace [template] { +// CHECK:STDOUT: .J = %J.decl +// CHECK:STDOUT: .C = %C.decl +// CHECK:STDOUT: } +// CHECK:STDOUT: %J.decl: type = interface_decl @J [template = constants.%J.type] {} {} +// CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {} +// CHECK:STDOUT: impl_decl @impl [template] {} { +// CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C] +// CHECK:STDOUT: %J.ref: type = name_ref J, file.%J.decl [template = constants.%J.type] +// CHECK:STDOUT: } +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: interface @J; +// CHECK:STDOUT: +// CHECK:STDOUT: impl @impl: %C.ref as %J.ref { +// CHECK:STDOUT: !members: +// CHECK:STDOUT: witness = +// CHECK:STDOUT: } +// CHECK:STDOUT: +// CHECK:STDOUT: class @C { +// CHECK:STDOUT: %.loc5: = complete_type_witness %.1 [template = constants.%.2] +// CHECK:STDOUT: +// CHECK:STDOUT: !members: +// CHECK:STDOUT: .Self = constants.%C +// CHECK:STDOUT: } +// CHECK:STDOUT: diff --git a/toolchain/diagnostics/coverage_test.cpp b/toolchain/diagnostics/coverage_test.cpp index 26076d8b6cb37..9f857641a552a 100644 --- a/toolchain/diagnostics/coverage_test.cpp +++ b/toolchain/diagnostics/coverage_test.cpp @@ -43,7 +43,6 @@ constexpr DiagnosticKind UntestedDiagnosticKinds[] = { DiagnosticKind::ExternLibraryInImporter, DiagnosticKind::ExternLibraryOnDefinition, DiagnosticKind::HexadecimalEscapeMissingDigits, - DiagnosticKind::ImplOfUndefinedInterface, DiagnosticKind::IncompleteTypeInFunctionParam, DiagnosticKind::InvalidDigit, DiagnosticKind::InvalidDigitSeparator,