Skip to content

Commit 09bd4c3

Browse files
authored
Merge pull request #10443 from slavapestov/fix-extension-sillyness-4.0
Fix a couple of silly problems with extensions [4.0]
2 parents 157bee9 + 0fcd8fc commit 09bd4c3

File tree

6 files changed

+12
-27
lines changed

6 files changed

+12
-27
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,9 +1337,6 @@ ERROR(extension_constrained_inheritance,none,
13371337
"inheritance clause", (Type))
13381338
ERROR(extension_protocol_inheritance,none,
13391339
"extension of protocol %0 cannot have an inheritance clause", (Type))
1340-
ERROR(extension_protocol_via_typealias,none,
1341-
"protocol %0 in the module being compiled cannot be extended via a "
1342-
"type alias", (Type))
13431340
ERROR(objc_generic_extension_using_type_parameter,none,
13441341
"extension of a generic Objective-C class cannot access the class's "
13451342
"generic parameters at runtime", ())

lib/AST/DeclContext.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,10 @@ DeclContext::getAsTypeOrTypeExtensionContext() const {
6161
auto ED = cast<ExtensionDecl>(this);
6262
auto type = ED->getExtendedType();
6363

64-
if (type.isNull() || type->hasError())
64+
if (!type)
6565
return nullptr;
6666

67-
if (auto ND = type->getNominalOrBoundGenericNominal())
68-
return ND;
69-
70-
if (auto unbound = dyn_cast<UnboundGenericType>(type.getPointer())) {
71-
return unbound->getDecl();
72-
}
73-
74-
return nullptr;
67+
return type->getAnyNominal();
7568
}
7669

7770
case DeclContextKind::GenericTypeDecl:

lib/Sema/TypeCheckDecl.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7804,18 +7804,6 @@ void TypeChecker::validateExtension(ExtensionDecl *ext) {
78047804
// FIXME: Probably the above comes up elsewhere, perhaps getAs<>()
78057805
// should be fixed.
78067806
if (auto proto = extendedType->getCanonicalType()->getAs<ProtocolType>()) {
7807-
if (!isa<ProtocolType>(extendedType.getPointer()) &&
7808-
proto->getDecl()->getParentModule() == ext->getParentModule()) {
7809-
// Protocols in the same module cannot be extended via a typealias;
7810-
// we could end up being unable to resolve the generic signature.
7811-
diagnose(ext->getLoc(), diag::extension_protocol_via_typealias, proto)
7812-
.fixItReplace(ext->getExtendedTypeLoc().getSourceRange(),
7813-
proto->getDecl()->getName().str());
7814-
ext->setInvalid();
7815-
ext->getExtendedTypeLoc().setInvalidType(Context);
7816-
return;
7817-
}
7818-
78197807
GenericEnvironment *env;
78207808
std::tie(env, extendedType) =
78217809
checkExtensionGenericParams(*this, ext, proto, ext->getGenericParams());

test/decl/ext/generic.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,9 @@ struct S5<Q> {
158158
}
159159

160160
extension S5 : P4 {}
161+
162+
// rdar://problem/21607421
163+
public typealias Array2 = Array
164+
extension Array2 where QQQ : VVV {}
165+
// expected-error@-1 {{use of undeclared type 'QQQ'}}
166+
// expected-error@-2 {{use of undeclared type 'VVV'}}

test/decl/ext/protocol.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -921,9 +921,10 @@ extension BadProto1 {
921921
}
922922
}
923923

924+
// rdar://problem/20756244
924925
protocol BadProto3 { }
925926
typealias BadProto4 = BadProto3
926-
extension BadProto4 { } // expected-error{{protocol 'BadProto3' in the module being compiled cannot be extended via a type alias}}{{11-20=BadProto3}}
927+
extension BadProto4 { } // okay
927928

928929
typealias RawRepresentableAlias = RawRepresentable
929930
extension RawRepresentableAlias { } // okay
@@ -948,6 +949,6 @@ class BadClass5 : BadProto5 {} // expected-error{{type 'BadClass5' does not conf
948949
typealias A = BadProto1
949950
typealias B = BadProto1
950951

951-
extension A & B { // expected-error{{protocol 'BadProto1' in the module being compiled cannot be extended via a type alias}}
952+
extension A & B { // okay
952953

953954
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

88
// REQUIRES: asserts
9-
// RUN: not --crash %target-swift-frontend %s -emit-ir
9+
// RUN: not %target-swift-frontend %s -emit-ir
1010
protocol P}extension P{{}typealias a:P}extension P.a{protocol P

0 commit comments

Comments
 (0)