Skip to content

Commit f3236ed

Browse files
authored
Merge pull request #8890 from KingOfBrian/bugfix/SR-1762-error-in-swift-4
Emit error in Swift 4 mode for final protocol extensions
2 parents a477006 + 37266d8 commit f3236ed

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ class AttributeEarlyChecker : public AttributeVisitor<AttributeEarlyChecker> {
187187
// 'final' only makes sense in the context of a class declaration.
188188
// Reject it on global functions, protocols, structs, enums, etc.
189189
if (!D->getDeclContext()->getAsClassOrClassExtensionContext()) {
190-
if (D->getDeclContext()->getAsProtocolExtensionContext())
190+
if (TC.Context.isSwiftVersion3() &&
191+
D->getDeclContext()->getAsProtocolExtensionContext())
191192
TC.diagnose(attr->getLocation(),
192193
diag::protocol_extension_cannot_be_final)
193194
.fixItRemove(attr->getRange());
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %target-typecheck-verify-swift -swift-version 3
2+
// Generate a swift 3 compatible warning if final is specified in an extension
3+
4+
protocol P {}
5+
6+
extension P {
7+
final func inExtension() {} // expected-warning{{functions in a protocol extension do not need to be marked with 'final'}} {{3-9=}}
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %target-typecheck-verify-swift -swift-version 4
2+
3+
protocol P {}
4+
5+
extension P {
6+
final func inExtension() {} // expected-error {{only classes and class members may be marked with 'final'}} {{3-9=}}
7+
}

0 commit comments

Comments
 (0)