Skip to content

Commit 4c0b391

Browse files
committed
Sema: Ensure that even invalid extensions still have a generic parameter list
This helps maintain invariants, such as the presence of a generic parameter list implying the presence of a generic signature. Fixes <rdar://problem/45317855>.
1 parent 78e5607 commit 4c0b391

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4673,27 +4673,18 @@ void TypeChecker::validateExtension(ExtensionDecl *ext) {
46734673

46744674
validateExtendedType(ext, *this);
46754675

4676-
// Extensions nested inside other declarations are invalid and we
4677-
// do not bind them.
4678-
if (!isa<SourceFile>(ext->getDeclContext()))
4679-
return;
4680-
4681-
// If this is not bound to any decls at this point, this extension is in
4682-
// inactive coditional compilation block. It's not safe to typecheck this
4683-
// extension. This happens if code completion is triggered in inactive
4684-
// conditional complation block.
4685-
if (!ext->alreadyBoundToNominal())
4686-
return;
4687-
46884676
if (auto *nominal = ext->getExtendedNominal()) {
4677+
// If this extension was not already bound, it means it is either in an
4678+
// inactive conditional compilation block, or otherwise (incorrectly)
4679+
// nested inside of some other declaration. Make sure the generic
4680+
// parameter list of the extension exists to maintain invariants.
4681+
if (!ext->alreadyBoundToNominal())
4682+
ext->createGenericParamsIfMissing(nominal);
4683+
46894684
// Validate the nominal type declaration being extended.
46904685
validateDecl(nominal);
46914686

4692-
if (nominal->getGenericParamsOfContext()) {
4693-
auto genericParams = ext->getGenericParams();
4694-
assert(genericParams && "bindExtensionDecl didn't set generic params?");
4695-
4696-
// Check generic parameters.
4687+
if (auto *genericParams = ext->getGenericParams()) {
46974688
GenericEnvironment *env;
46984689
Type extendedType = ext->getExtendedType();
46994690
std::tie(env, extendedType) = checkExtensionGenericParams(
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: not %target-swift-frontend -emit-ir %s
2+
3+
public final class Action<Input, Error: Swift.Error> {
4+
5+
extension Action {
6+
7+
public enum ActionError<Error: Swift.Error>: Swift.Error {
8+
case disabled

0 commit comments

Comments
 (0)