Skip to content

Commit cef38cf

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 f13acdd commit cef38cf

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
@@ -1466,15 +1466,17 @@ bool Parser::parseDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc) {
14661466
// over to the alternate parsing path.
14671467
DeclAttrKind DK = DeclAttribute::getAttrKindFromString(Tok.getText());
14681468

1469-
auto checkInvalidAttrName = [&](StringRef invalidName, StringRef correctName,
1470-
DeclAttrKind kind, Diag<StringRef, StringRef> diag) {
1469+
auto checkInvalidAttrName = [&](StringRef invalidName,
1470+
StringRef correctName,
1471+
DeclAttrKind kind,
1472+
Optional<Diag<StringRef, StringRef>> diag = None) {
14711473
if (DK == DAK_Count && Tok.getText() == invalidName) {
1472-
// We renamed @availability to @available, so if we see the former,
1473-
// treat it as the latter and emit a Fix-It.
14741474
DK = kind;
1475-
1476-
diagnose(Tok, diag, invalidName, correctName)
1475+
1476+
if (diag) {
1477+
diagnose(Tok, *diag, invalidName, correctName)
14771478
.fixItReplace(Tok.getLoc(), correctName);
1479+
}
14781480
}
14791481
};
14801482

@@ -1485,14 +1487,17 @@ bool Parser::parseDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc) {
14851487
// Check if attr is inlineable, and suggest inlinable instead
14861488
checkInvalidAttrName("inlineable", "inlinable", DAK_Inlinable, diag::attr_name_close_match);
14871489

1488-
// In Swift 5 and above, these become hard errors. Otherwise, emit a
1489-
// warning for compatibility.
1490-
if (!Context.isSwiftVersionAtLeast(5)) {
1490+
// In Swift 5 and above, these become hard errors. In Swift 4.2, emit a
1491+
// warning for compatibility. Otherwise, don't diagnose at all.
1492+
if (Context.isSwiftVersionAtLeast(5)) {
1493+
checkInvalidAttrName("_versioned", "usableFromInline", DAK_UsableFromInline, diag::attr_renamed);
1494+
checkInvalidAttrName("_inlineable", "inlinable", DAK_Inlinable, diag::attr_renamed);
1495+
} else if (Context.isSwiftVersionAtLeast(4, 2)) {
14911496
checkInvalidAttrName("_versioned", "usableFromInline", DAK_UsableFromInline, diag::attr_renamed_warning);
14921497
checkInvalidAttrName("_inlineable", "inlinable", DAK_Inlinable, diag::attr_renamed_warning);
14931498
} else {
1494-
checkInvalidAttrName("_versioned", "usableFromInline", DAK_UsableFromInline, diag::attr_renamed);
1495-
checkInvalidAttrName("_inlineable", "inlinable", DAK_Inlinable, diag::attr_renamed);
1499+
checkInvalidAttrName("_versioned", "usableFromInline", DAK_UsableFromInline);
1500+
checkInvalidAttrName("_inlineable", "inlinable", DAK_Inlinable);
14961501
}
14971502

14981503
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)