Skip to content

Commit 0770037

Browse files
author
Brian King
committed
Only generate a warning for Swift 3 and 4 mode.
1 parent 1ab9e45 commit 0770037

File tree

3 files changed

+4
-13
lines changed

3 files changed

+4
-13
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,7 @@ class AttributeEarlyChecker : public AttributeVisitor<AttributeEarlyChecker> {
185185
// 'final' only makes sense in the context of a class declaration.
186186
// Reject it on global functions, protocols, structs, enums, etc.
187187
if (!D->getDeclContext()->getAsClassOrClassExtensionContext()) {
188-
if (TC.Context.isSwiftVersion3() &&
189-
D->getDeclContext()->getAsProtocolExtensionContext())
188+
if (D->getDeclContext()->getAsProtocolExtensionContext())
190189
TC.diagnose(attr->getLocation(),
191190
diag::protocol_extension_cannot_be_final)
192191
.fixItRemove(attr->getRange());

test/Compatibility/final_protocol_extension.swift

Lines changed: 0 additions & 8 deletions
This file was deleted.

test/attr/attr_final.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -swift-version 4
1+
// RUN: %target-typecheck-verify-swift
22

33
class Super {
44
final var i: Int { get { return 5 } } // expected-note{{overridden declaration is here}}
@@ -40,8 +40,8 @@ protocol SomeProtocol {
4040
}
4141

4242
extension SomeProtocol {
43-
final var i: Int { return 1 } // expected-error {{only classes and class members may be marked with 'final'}}
44-
final func protoExtensionFunc() {} // expected-error {{only classes and class members may be marked with 'final'}} {{3-9=}}
43+
final var i: Int { return 1 } // expected-warning {{functions in a protocol extension do not need to be marked with 'final'}}
44+
final func protoExtensionFunc() {} // expected-warning {{functions in a protocol extension do not need to be marked with 'final'}} {{3-9=}}
4545
}
4646

4747
extension SomeStruct {

0 commit comments

Comments
 (0)