mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 08:44:41 +01:00
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:
@@ -301,6 +301,21 @@ auto HandleParseNode(Context& context, Parse::RequireDeclId node_id) -> bool {
|
||||
})) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 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 require declaration's
|
||||
// specific along with the facet type.
|
||||
auto constraint_id_in_self_specific = AddTypeInst<SemIR::SpecificConstant>(
|
||||
context, node_id,
|
||||
{.type_id = SemIR::TypeType::TypeId,
|
||||
.inst_id = constraint_inst_id,
|
||||
.specific_id = context.generics().GetSelfSpecific(
|
||||
context.require_impls().Get(require_impls_id).generic_id)});
|
||||
auto enclosing_scope_id = context.scope_stack().PeekNameScopeId();
|
||||
auto& enclosing_scope = context.name_scopes().Get(enclosing_scope_id);
|
||||
enclosing_scope.AddExtendedScope(constraint_id_in_self_specific);
|
||||
}
|
||||
|
||||
context.require_impls_stack().AppendToTop(require_impls_id);
|
||||
|
||||
Reference in New Issue
Block a user