Look through extend require in an interface or named constraint in name lookup (#6630)

Add the required facet type as an extended scope of the containing
interface/named constraint, and teach name lookup to look for extended
scopes in named constraints.

This makes name lookup work properly when the facet type does not have a
specific that involves `Self`. Support for `Self` needs further work in
another PR.

Note that when an _interface_ requires another interface, this PR lets
us find the name, but we still fail to find a witness for the interface
named through `extend require`, and this is future work. For a named
constraint, things work correctly as the identified facet type chases
through the named constraint and includes the required interface, so
impl lookup is able to provide a witness.
This commit is contained in:
Dana Jansens
2026-01-20 22:26:10 +00:00
committed by GitHub
parent c0e7198995
commit 4bb2935770
9 changed files with 134 additions and 23 deletions
+14 -2
View File
@@ -23,8 +23,12 @@ interface Z {
}
//@dump-sem-ir-end
fn F(T:! Z) {
// CHECK:STDERR: fail_todo_extend.carbon:[[@LINE+4]]:3: error: member name `YY` not found in `Z` [MemberNameNotFoundInInstScope]
fn F(T:! Z, t:! T) {
// TODO: We find the name `YY`, but then fail to do impl lookup for `Y` in
// `T:! Z` since the identified facet type doesn't include `Y`. The
// identified facet type needs to include extends inside interfaces?
// CHECK:STDERR: fail_todo_extend.carbon:[[@LINE+4]]:3: error: cannot access member of interface `Y` in type `T` that does not implement that interface [MissingImplInMemberAccess]
// CHECK:STDERR: T.YY();
// CHECK:STDERR: ^~~~
// CHECK:STDERR:
@@ -34,6 +38,12 @@ fn F(T:! Z) {
// CHECK:STDERR: ^~~~~~~~
// CHECK:STDERR:
T.(Y.YY)();
// CHECK:STDERR: fail_todo_extend.carbon:[[@LINE+4]]:3: error: cannot access member of interface `Y` in type `T` that does not implement that interface [MissingImplInMemberAccess]
// CHECK:STDERR: t.YY();
// CHECK:STDERR: ^~~~
// CHECK:STDERR:
t.YY();
}
// --- fail_todo_implicit_self_impls.carbon
@@ -293,11 +303,13 @@ interface Z(T:! type) {
// CHECK:STDOUT: %Self.as_type: type = facet_access_type @Z.%Self [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)]
// CHECK:STDOUT: %Y.ref: type = name_ref Y, file.%Y.decl [concrete = constants.%Y.type]
// CHECK:STDOUT: }
// CHECK:STDOUT: %.loc9: type = specific_constant @Z.Self.binding.as_type.impls.Y.type.require.%Y.ref, @Z.Self.binding.as_type.impls.Y.type.require(constants.%Self.c59) [concrete = constants.%Y.type]
// CHECK:STDOUT:
// CHECK:STDOUT: !members:
// CHECK:STDOUT: .Self = %Self
// CHECK:STDOUT: .Y = <poisoned>
// CHECK:STDOUT: .YY = <poisoned>
// CHECK:STDOUT: extend %.loc9
// CHECK:STDOUT: witness = ()
// CHECK:STDOUT:
// CHECK:STDOUT: !requires: