Initial, extern-ignoring support for extern class decls. (#3891)

This doesn't actually track whether a declaration is `extern`. It does,
however:

- Factor out and expand merge support for classes, sharing handling with
functions.
- This makes the ClassRedefinition diagnostic redundant, as the
redeclaration checking overlaps.
- Add partial `extern` handling to class handling; just some
verifications of correct use.
- Factor out `extern` on member handling for sharing with `fn`.
- Fixes a bug in import_ref where a class's definition_id wasn't
assigned when defining.

This changes how a redefinition is handled (replaced, rather than
merged). I don't know whether that's ideal, but I think it results in
easy-to-understand consequences, and it's more consistent with how `fn`
works.

There's enough work here that this felt like a decent cut point,
particularly as the amount of work to actually add `extern` tracking
will be significant.
This commit is contained in:
Jon Ross-Perkins
2024-04-19 16:08:29 +00:00
committed by GitHub
parent 3776c068de
commit db324c7247
16 changed files with 1119 additions and 193 deletions
+15 -4
View File
@@ -136,10 +136,21 @@ auto CheckMethodModifiersOnFunction(Context& context,
" outside of a class");
}
auto ForbidExternModifierOnDefinition(Context& context,
Lex::TokenKind decl_kind) -> void {
ForbidModifiersOnDecl(context, KeywordModifierSet::Extern, decl_kind,
" that provides a definition");
auto RestrictExternModifierOnDecl(Context& context, Lex::TokenKind decl_kind,
SemIR::NameScopeId target_scope_id,
bool is_definition) -> void {
if (is_definition) {
ForbidModifiersOnDecl(context, KeywordModifierSet::Extern, decl_kind,
" that provides a definition");
}
if (target_scope_id.is_valid()) {
auto target_id = context.name_scopes().Get(target_scope_id).inst_id;
if (target_id.is_valid() &&
!context.insts().Is<SemIR::Namespace>(target_id)) {
ForbidModifiersOnDecl(context, KeywordModifierSet::Extern, decl_kind,
" that is a member");
}
}
}
auto RequireDefaultFinalOnlyInInterfaces(Context& context,