Skip to content

Commit 0fcd8fc

Browse files
committed
Sema: Lift obsolete restriction on protocol extensions via typealias
1 parent aef9f8f commit 0fcd8fc

File tree

3 files changed

+3
-17
lines changed

3 files changed

+3
-17
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/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/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
}

0 commit comments

Comments
 (0)