Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion toolchain/check/impl_validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,20 @@ static auto ImportFinalImplsWithImplInFile(Context& context) -> void {
if (!import_ir_id.has_value()) {
continue;
}
auto interface_owning_decl_id = interface.first_owning_decl_id;
if (!interface_owning_decl_id.has_value()) {
continue;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If first_owning_decl_id was None, the import_ir_id returned from GetIRId would be None, and we would have returned above, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, right, sorry - had meant to clean up/remove the GetIRId call, since this one caller now needs both parts of the ImportIRInst (both the ImportIRId, and the InstId).

Done that (though it did mean needing two !has_value() -> continue blocks) in 7558fe5

const auto& import_ir_inst =
GetCanonicalImportIRInst(context, interface.first_owning_decl_id);
interfaces_to_import.push_back(
{.ir_id = import_ir_id, .interface_id = interface_id});
{.ir_id = import_ir_inst.ir_id(),
.interface_id =
context.import_irs()
.Get(import_ir_inst.ir_id())
.sem_ir->insts()
.GetAs<SemIR::InterfaceDecl>(import_ir_inst.inst_id())
.interface_id});
}

llvm::sort(interfaces_to_import);
Expand Down
8 changes: 5 additions & 3 deletions toolchain/check/testdata/impl/lookup/impl_overlap.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ interface Z(T:! type) {}
// --- interface_z_with_impl.carbon
library "[[@TEST_NAME]]";

interface Other(T:! type) {}

interface Z(T:! type) {}

final impl forall [T:! type] T as Z(T) {}
Expand Down Expand Up @@ -176,7 +178,7 @@ class C;
// CHECK:STDERR: final impl C as Z(()) {}
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR: fail_final_impl_with_both_interface_and_self_but_different_files.carbon:[[@LINE-10]]:1: in import [InImport]
// CHECK:STDERR: interface_z_with_impl.carbon:5:1: note: imported `final impl` here [FinalImplOverlapsDifferentFileNote]
// CHECK:STDERR: interface_z_with_impl.carbon:7:1: note: imported `final impl` here [FinalImplOverlapsDifferentFileNote]
// CHECK:STDERR: final impl forall [T:! type] T as Z(T) {}
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR:
Expand All @@ -196,7 +198,7 @@ class C;
// CHECK:STDERR: final impl C as Z(C) {}
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR: fail_final_overlaps_final_from_other_file.carbon:[[@LINE-10]]:1: in import [InImport]
// CHECK:STDERR: interface_z_with_impl.carbon:5:1: note: imported `final impl` here [FinalImplOverlapsDifferentFileNote]
// CHECK:STDERR: interface_z_with_impl.carbon:7:1: note: imported `final impl` here [FinalImplOverlapsDifferentFileNote]
// CHECK:STDERR: final impl forall [T:! type] T as Z(T) {}
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR:
Expand All @@ -215,7 +217,7 @@ class C;
// CHECK:STDERR: impl C as Z(C) {}
// CHECK:STDERR: ^~~~~~~~~~~~~~~~
// CHECK:STDERR: fail_final_overlaps_non_final_from_other_file.carbon:[[@LINE-9]]:1: in import [InImport]
// CHECK:STDERR: interface_z_with_impl.carbon:5:1: note: `final impl` declared here would always be used instead [ImplFinalOverlapsNonFinalNote]
// CHECK:STDERR: interface_z_with_impl.carbon:7:1: note: `final impl` declared here would always be used instead [ImplFinalOverlapsNonFinalNote]
// CHECK:STDERR: final impl forall [T:! type] T as Z(T) {}
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR:
Expand Down
Loading