mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Look for final impl when accessing associated constant in facet (#5269)
While facets may come with a rewrite for an associated constant, they are symbolic. A final impl has the ability to provide a concrete value instead, which allows generic code to use the concrete value in place of the associated constant's (fully qualified) name. For instance, instead of `I.Type`, the concrete type `()` can be used if there is an `impl final [T:! type] T as I where .Type = ()` impl. This does not yet cache the result of the lookups. Depends on https://github.com/carbon-language/carbon-lang/pull/5255 --------- Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
co-authored by
Richard Smith
parent
68111a994c
commit
76c68153a2
@@ -364,11 +364,12 @@ static auto BuildImplDecl(Context& context, Parse::AnyImplDeclId node_id,
|
||||
|
||||
// Process modifiers.
|
||||
// TODO: Should we somehow permit access specifiers on `impl`s?
|
||||
// TODO: Handle `final` modifier.
|
||||
auto introducer =
|
||||
context.decl_introducer_state_stack().Pop<Lex::TokenKind::Impl>();
|
||||
LimitModifiersOnDecl(context, introducer, KeywordModifierSet::ImplDecl);
|
||||
|
||||
bool is_final = introducer.modifier_set.HasAnyOf(KeywordModifierSet::Final);
|
||||
|
||||
// Finish processing the name, which should be empty, but might have
|
||||
// parameters.
|
||||
auto name_context = context.decl_name_stack().FinishImplName();
|
||||
@@ -387,7 +388,8 @@ static auto BuildImplDecl(Context& context, Parse::AnyImplDeclId node_id,
|
||||
{.self_id = self_inst_id,
|
||||
.constraint_id = constraint_inst_id,
|
||||
.interface = CheckConstraintIsInterface(
|
||||
context, impl_decl_id, constraint_inst_id)}};
|
||||
context, impl_decl_id, constraint_inst_id),
|
||||
.is_final = is_final}};
|
||||
// Add the impl declaration.
|
||||
bool invalid_redeclaration = false;
|
||||
auto lookup_bucket_ref = context.impls().GetOrAddLookupBucket(impl_info);
|
||||
|
||||
Reference in New Issue
Block a user