Skip to content

Commit 00cb08d

Browse files
committed
Parse: Only diagnose renamed @_inlineable and @_versioned in -swift-version 4.2
Normally we don't gate *warnings* on -swift-version flags, but SwiftNIO makes use of @_inlineable / @_versioned and wants to continue building with Swift 4.1 until 4.2 is released. Fixes <https://bugs.swift.org/browse/SR-7578>, <rdar://problem/40717640>.
1 parent d5ec182 commit 00cb08d

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,15 +1537,17 @@ bool Parser::parseDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc) {
15371537
// over to the alternate parsing path.
15381538
DeclAttrKind DK = DeclAttribute::getAttrKindFromString(Tok.getText());
15391539

1540-
auto checkInvalidAttrName = [&](StringRef invalidName, StringRef correctName,
1541-
DeclAttrKind kind, Diag<StringRef, StringRef> diag) {
1540+
auto checkInvalidAttrName = [&](StringRef invalidName,
1541+
StringRef correctName,
1542+
DeclAttrKind kind,
1543+
Optional<Diag<StringRef, StringRef>> diag = None) {
15421544
if (DK == DAK_Count && Tok.getText() == invalidName) {
1543-
// We renamed @availability to @available, so if we see the former,
1544-
// treat it as the latter and emit a Fix-It.
15451545
DK = kind;
1546-
1547-
diagnose(Tok, diag, invalidName, correctName)
1546+
1547+
if (diag) {
1548+
diagnose(Tok, *diag, invalidName, correctName)
15481549
.fixItReplace(Tok.getLoc(), correctName);
1550+
}
15491551
}
15501552
};
15511553

@@ -1556,14 +1558,17 @@ bool Parser::parseDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc) {
15561558
// Check if attr is inlineable, and suggest inlinable instead
15571559
checkInvalidAttrName("inlineable", "inlinable", DAK_Inlinable, diag::attr_name_close_match);
15581560

1559-
// In Swift 5 and above, these become hard errors. Otherwise, emit a
1560-
// warning for compatibility.
1561-
if (!Context.isSwiftVersionAtLeast(5)) {
1561+
// In Swift 5 and above, these become hard errors. In Swift 4.2, emit a
1562+
// warning for compatibility. Otherwise, don't diagnose at all.
1563+
if (Context.isSwiftVersionAtLeast(5)) {
1564+
checkInvalidAttrName("_versioned", "usableFromInline", DAK_UsableFromInline, diag::attr_renamed);
1565+
checkInvalidAttrName("_inlineable", "inlinable", DAK_Inlinable, diag::attr_renamed);
1566+
} else if (Context.isSwiftVersionAtLeast(4, 2)) {
15621567
checkInvalidAttrName("_versioned", "usableFromInline", DAK_UsableFromInline, diag::attr_renamed_warning);
15631568
checkInvalidAttrName("_inlineable", "inlinable", DAK_Inlinable, diag::attr_renamed_warning);
15641569
} else {
1565-
checkInvalidAttrName("_versioned", "usableFromInline", DAK_UsableFromInline, diag::attr_renamed);
1566-
checkInvalidAttrName("_inlineable", "inlinable", DAK_Inlinable, diag::attr_renamed);
1570+
checkInvalidAttrName("_versioned", "usableFromInline", DAK_UsableFromInline);
1571+
checkInvalidAttrName("_inlineable", "inlinable", DAK_Inlinable);
15671572
}
15681573

15691574
if (DK == DAK_Count && Tok.getText() == "warn_unused_result") {
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 3
2+
// RUN: %target-typecheck-verify-swift -swift-version 4
3+
4+
// In -swift-version 4 mode, the old spelling is silently parsed as the new spelling.
5+
6+
@_inlineable public func oldInlinableFunction() {}
7+
@_versioned func oldVersionedFunction() {}

test/Compatibility/attr_inlinable_old_spelling.swift renamed to test/Compatibility/attr_inlinable_old_spelling_42.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
// RUN: %target-typecheck-verify-swift -swift-version 3
2-
// RUN: %target-typecheck-verify-swift -swift-version 4
31
// RUN: %target-typecheck-verify-swift -swift-version 4.2
42

5-
// Until -swift-version 5 mode, the old spelling only produces a warning.
3+
// In -swift-version 4.2 mode, the old spelling produces a warning.
64

75
@_inlineable public func oldInlinableFunction() {}
86
// expected-warning@-1 {{'@_inlineable' has been renamed to '@inlinable'}}{{2-13=inlinable}}

0 commit comments

Comments
 (0)