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
+5
View File
@@ -238,6 +238,11 @@ static auto ApplyExtendImplAs(Context& context, SemIR::LocId loc_id,
if (!impl.generic_id.has_value()) {
parent_scope.AddExtendedScope(impl.constraint_id);
} else {
// The extended scope instruction must be part of the enclosing scope (and
// generic). A specific for the enclosing scope will be applied to it when
// using the instruction later. To do so, we wrap the constraint facet type
// it in a SpecificConstant, which preserves the impl declaration's
// specific along with the facet type.
auto constraint_id_in_self_specific = AddTypeInst<SemIR::SpecificConstant>(
context, SemIR::LocId(impl.constraint_id),
{.type_id = SemIR::TypeType::TypeId,