Use identified facet type to get impl-as target (#7519)

This supports impl lookup choosing an impl that targets a generic
interface through a named constraint, without crashing.

Instead of assuming the impl's target is a facet type containing an
interface, we use the identified facet type to find the specific
interface it targets.
This commit is contained in:
Dana Jansens
2026-07-16 19:11:23 +00:00
committed by GitHub
parent 0848cf941d
commit 2d9e3fee67
2 changed files with 46 additions and 26 deletions
+20 -11
View File
@@ -185,8 +185,7 @@ impl C as N where .I1 = C {}
fn F(generic _: I where .I1 = .Self) {}
fn G() {
// TODO: This crashes.
// F(C);
F(C);
}
// --- impl_as_concrete_generic_constraint_where_rewrite.carbon
@@ -206,11 +205,10 @@ impl C as N where .I1 = C {}
fn F(generic _: I(.Self) where .I1 = .Self) {}
fn G() {
// TODO: This crashes.
// F(C);
F(C);
}
// --- todo_impl_as_symbolic_generic_constraint_where_rewrite.carbon
// --- impl_as_symbolic_generic_constraint_where_rewrite.carbon
library "[[@TEST_NAME]]";
interface I(T: type) {
@@ -226,8 +224,7 @@ impl C as N where .I1 = C {}
fn F(generic _: I(.Self) where .I1 = .Self) {}
fn G() {
// TODO: This crashes.
// F(C);
F(C);
}
// --- fail_todo_impl_as_constraint_containing_rewrite_for_concrete_interface.carbon
@@ -253,8 +250,14 @@ impl C as N {}
fn F(generic _: I where .I1 = .Self) {}
fn G() {
// TODO: This crashes.
// F(C);
// CHECK:STDERR: fail_todo_impl_as_constraint_containing_rewrite_for_concrete_interface.carbon:[[@LINE+7]]:3: error: cannot convert type `C` into type implementing `I where .(I.I1) = .Self` [ConversionFailureTypeToFacet]
// CHECK:STDERR: F(C);
// CHECK:STDERR: ^~~~
// CHECK:STDERR: fail_todo_impl_as_constraint_containing_rewrite_for_concrete_interface.carbon:[[@LINE-5]]:14: note: initializing generic parameter `_` declared here [InitializingGenericParam]
// CHECK:STDERR: fn F(generic _: I where .I1 = .Self) {}
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR:
F(C);
}
// --- fail_todo_impl_as_constraint_containing_rewrite_for_generic_interface.carbon
@@ -280,8 +283,14 @@ impl C as N {}
fn F(generic _: I(.Self) where .I1 = .Self) {}
fn G() {
// TODO: This crashes.
// F(C);
// CHECK:STDERR: fail_todo_impl_as_constraint_containing_rewrite_for_generic_interface.carbon:[[@LINE+7]]:3: error: cannot convert type `C` into type implementing `I(.Self) where .(I(.Self).I1) = .Self` [ConversionFailureTypeToFacet]
// CHECK:STDERR: F(C);
// CHECK:STDERR: ^~~~
// CHECK:STDERR: fail_todo_impl_as_constraint_containing_rewrite_for_generic_interface.carbon:[[@LINE-5]]:1: note: while deducing parameters of generic declared here [DeductionGenericHere]
// CHECK:STDERR: fn F(generic _: I(.Self) where .I1 = .Self) {}
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR:
F(C);
}
// --- fail_no_require_self.carbon