Skip to content

Commit fdd0259

Browse files
committed
Sema: Lift obsolete restriction on protocol extensions via typealias
1 parent 151f386 commit fdd0259

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
@@ -1347,9 +1347,6 @@ ERROR(extension_constrained_inheritance,none,
13471347
"inheritance clause", (Type))
13481348
ERROR(extension_protocol_inheritance,none,
13491349
"extension of protocol %0 cannot have an inheritance clause", (Type))
1350-
ERROR(extension_protocol_via_typealias,none,
1351-
"protocol %0 in the module being compiled cannot be extended via a "
1352-
"type alias", (Type))
13531350
ERROR(objc_generic_extension_using_type_parameter,none,
13541351
"extension of a generic Objective-C class cannot access the class's "
13551352
"generic parameters at runtime", ())

lib/Sema/TypeCheckDecl.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7808,18 +7808,6 @@ void TypeChecker::validateExtension(ExtensionDecl *ext) {
78087808
// FIXME: Probably the above comes up elsewhere, perhaps getAs<>()
78097809
// should be fixed.
78107810
if (auto proto = extendedType->getCanonicalType()->getAs<ProtocolType>()) {
7811-
if (!isa<ProtocolType>(extendedType.getPointer()) &&
7812-
proto->getDecl()->getParentModule() == ext->getParentModule()) {
7813-
// Protocols in the same module cannot be extended via a typealias;
7814-
// we could end up being unable to resolve the generic signature.
7815-
diagnose(ext->getLoc(), diag::extension_protocol_via_typealias, proto)
7816-
.fixItReplace(ext->getExtendedTypeLoc().getSourceRange(),
7817-
proto->getDecl()->getName().str());
7818-
ext->setInvalid();
7819-
ext->getExtendedTypeLoc().setInvalidType(Context);
7820-
return;
7821-
}
7822-
78237811
GenericEnvironment *env;
78247812
std::tie(env, extendedType) =
78257813
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)