mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Diagnose impl method without matching virtual function in base class (#5817)
Also update `RequestVtableIfVirtual` to strip `impl` from functions in classes without a base class - this avoids a duplicate diagnostic where they're diagnosed as being in a class without a base class, then diagnosed again because they don't have a matching function in a base class.
This commit is contained in:
+10
-12
@@ -130,7 +130,7 @@ fn F() {
|
||||
b1.m2 = 4;
|
||||
}
|
||||
|
||||
// --- todo_fail_impl_without_base_declaration.carbon
|
||||
// --- fail_impl_without_base_declaration.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
@@ -139,6 +139,10 @@ base class Base {
|
||||
|
||||
class Derived {
|
||||
extend base: Base;
|
||||
// CHECK:STDERR: fail_impl_without_base_declaration.carbon:[[@LINE+4]]:3: error: impl without compatible virtual in base class [ImplWithoutVirtualInBase]
|
||||
// CHECK:STDERR: impl fn F[self: Self]();
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
impl fn F[self: Self]();
|
||||
}
|
||||
|
||||
@@ -1252,10 +1256,8 @@ var v: Base(T1) = {};
|
||||
// CHECK:STDOUT: %pattern_type: type = pattern_type %C [concrete]
|
||||
// CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
|
||||
// CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
|
||||
// CHECK:STDOUT: %ptr: type = ptr_type <vtable> [concrete]
|
||||
// CHECK:STDOUT: %C.vtable_ptr: ref %ptr = vtable_ptr @C.vtable [concrete]
|
||||
// CHECK:STDOUT: %struct_type.vptr: type = struct_type {.<vptr>: %ptr} [concrete]
|
||||
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.vptr [concrete]
|
||||
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
|
||||
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: imports {
|
||||
@@ -1283,19 +1285,15 @@ var v: Base(T1) = {};
|
||||
// CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [concrete = constants.%C]
|
||||
// CHECK:STDOUT: %self: %C = bind_name self, %self.param
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %vtable_ptr: ref %ptr = vtable_ptr @C.vtable [concrete = constants.%C.vtable_ptr]
|
||||
// CHECK:STDOUT: %struct_type.vptr: type = struct_type {.<vptr>: %ptr} [concrete = constants.%struct_type.vptr]
|
||||
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.vptr [concrete = constants.%complete_type]
|
||||
// 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: vtable_ptr = %vtable_ptr
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: !members:
|
||||
// CHECK:STDOUT: .Self = constants.%C
|
||||
// CHECK:STDOUT: .F = %F.decl
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: vtable @C.vtable {}
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: impl fn @F(%self.param: %C);
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: --- init_members.carbon
|
||||
@@ -1518,7 +1516,7 @@ var v: Base(T1) = {};
|
||||
// CHECK:STDOUT: return
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: --- todo_fail_impl_without_base_declaration.carbon
|
||||
// CHECK:STDOUT: --- fail_impl_without_base_declaration.carbon
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: constants {
|
||||
// CHECK:STDOUT: %Base: type = class_type @Base [concrete]
|
||||
|
||||
Reference in New Issue
Block a user