Skip to content

Commit f747e4c

Browse files
authored
Merge pull request #10924 from huonw/swift3-is-behind-us-now-4.0-earlier
[4.0 2017-07-11] Upgrade some deprecation warnings from Swift 3 to errors in Swift 4
2 parents b6a58cd + d294f30 commit f747e4c

11 files changed

+148
-55
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,12 @@ ERROR(static_func_decl_global_scope,none,
320320
(StaticSpellingKind))
321321
ERROR(func_decl_expected_arrow,none,
322322
"expected '->' after function parameter tuple", ())
323-
WARNING(operator_static_in_protocol,none,
323+
WARNING(swift3_operator_static_in_protocol,none,
324324
"operator '%0' declared in protocol must be 'static'",
325325
(StringRef))
326+
ERROR(operator_static_in_protocol,none,
327+
"operator '%0' declared in protocol must be 'static'",
328+
(StringRef))
326329

327330
// Enum
328331
ERROR(expected_lbrace_enum,PointsToFirstBadToken,
@@ -410,11 +413,16 @@ ERROR(expected_operator_name_after_operator,PointsToFirstBadToken,
410413
ERROR(identifier_when_expecting_operator,PointsToFirstBadToken,
411414
"%0 is considered to be an identifier, not an operator", (Identifier))
412415

413-
WARNING(deprecated_operator_body,PointsToFirstBadToken,
416+
WARNING(swift3_deprecated_operator_body,PointsToFirstBadToken,
414417
"operator should no longer be declared with body", ())
415-
WARNING(deprecated_operator_body_use_group,PointsToFirstBadToken,
418+
ERROR(deprecated_operator_body,PointsToFirstBadToken,
419+
"operator should no longer be declared with body", ())
420+
WARNING(swift3_deprecated_operator_body_use_group,PointsToFirstBadToken,
416421
"operator should no longer be declared with body; "
417422
"use a precedence group instead", ())
423+
ERROR(deprecated_operator_body_use_group,PointsToFirstBadToken,
424+
"operator should no longer be declared with body; "
425+
"use a precedence group instead", ())
418426
ERROR(operator_decl_no_fixity,none,
419427
"operator must be declared as 'prefix', 'postfix', or 'infix'", ())
420428

@@ -731,12 +739,18 @@ ERROR(expected_rangle_protocol,PointsToFirstBadToken,
731739
ERROR(disallowed_protocol_composition,PointsToFirstBadToken,
732740
"protocol-constrained type is neither allowed nor needed here", ())
733741

734-
WARNING(deprecated_protocol_composition,none,
742+
WARNING(swift3_deprecated_protocol_composition,none,
735743
"'protocol<...>' composition syntax is deprecated; join the protocols using '&'", ())
736-
WARNING(deprecated_protocol_composition_single,none,
744+
ERROR(deprecated_protocol_composition,none,
745+
"'protocol<...>' composition syntax has been removed; join the protocols using '&'", ())
746+
WARNING(swift3_deprecated_protocol_composition_single,none,
737747
"'protocol<...>' composition syntax is deprecated and not needed here", ())
738-
WARNING(deprecated_any_composition,none,
748+
ERROR(deprecated_protocol_composition_single,none,
749+
"'protocol<...>' composition syntax has been removed and is not needed here", ())
750+
WARNING(swift3_deprecated_any_composition,none,
739751
"'protocol<>' syntax is deprecated; use 'Any' instead", ())
752+
ERROR(deprecated_any_composition,none,
753+
"'protocol<>' syntax has been removed; use 'Any' instead", ())
740754

741755
// SIL box Types
742756
ERROR(sil_box_expected_var_or_let,none,
@@ -837,8 +851,10 @@ ERROR(parameter_curry_syntax_removed,none,
837851
ERROR(initializer_as_typed_pattern,none,
838852
"unexpected initializer in pattern; did you mean to use '='?", ())
839853

840-
WARNING(unlabeled_parameter_following_variadic_parameter,none,
854+
WARNING(swift3_unlabeled_parameter_following_variadic_parameter,none,
841855
"a parameter following a variadic parameter requires a label", ())
856+
ERROR(unlabeled_parameter_following_variadic_parameter,none,
857+
"a parameter following a variadic parameter requires a label", ())
842858

843859
//------------------------------------------------------------------------------
844860
// Statement parsing diagnostics
@@ -1298,12 +1314,18 @@ ERROR(attr_noescape_conflicts_escaping_autoclosure,none,
12981314
ERROR(attr_noescape_implied_by_autoclosure,none,
12991315
"@noescape is implied by @autoclosure and should not be "
13001316
"redundantly specified", ())
1301-
WARNING(attr_autoclosure_escaping_deprecated,none,
1317+
WARNING(swift3_attr_autoclosure_escaping_deprecated,none,
13021318
"@autoclosure(escaping) is deprecated; use @autoclosure @escaping instead",
13031319
())
1304-
WARNING(attr_noescape_deprecated,none,
1320+
ERROR(attr_autoclosure_escaping_deprecated,none,
1321+
"@autoclosure(escaping) has been removed; use @autoclosure @escaping instead",
1322+
())
1323+
WARNING(swift3_attr_noescape_deprecated,none,
13051324
"@noescape is the default and is deprecated",
13061325
())
1326+
ERROR(attr_noescape_deprecated,none,
1327+
"@noescape is the default and has been removed",
1328+
())
13071329

13081330
// convention
13091331
ERROR(convention_attribute_expected_lparen,none,

lib/Parse/ParseDecl.cpp

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,7 +1677,9 @@ bool Parser::parseTypeAttribute(TypeAttributes &Attributes, bool justChecking) {
16771677
if (Attributes.has(TAK_noescape)) {
16781678
diagnose(Loc, diag::attr_noescape_conflicts_escaping_autoclosure);
16791679
} else {
1680-
diagnose(Loc, diag::attr_autoclosure_escaping_deprecated)
1680+
diagnose(Loc, Context.isSwiftVersion3()
1681+
? diag::swift3_attr_autoclosure_escaping_deprecated
1682+
: diag::attr_autoclosure_escaping_deprecated)
16811683
.fixItReplace(autoclosureEscapingParenRange, " @escaping ");
16821684
}
16831685
Attributes.setAttr(TAK_escaping, Loc);
@@ -1699,8 +1701,10 @@ bool Parser::parseTypeAttribute(TypeAttributes &Attributes, bool justChecking) {
16991701
}
17001702

17011703
// @noescape is deprecated and no longer used
1702-
diagnose(Loc, diag::attr_noescape_deprecated)
1703-
.fixItRemove({Attributes.AtLoc,Loc});
1704+
diagnose(Loc, Context.isSwiftVersion3()
1705+
? diag::swift3_attr_noescape_deprecated
1706+
: diag::attr_noescape_deprecated)
1707+
.fixItRemove({Attributes.AtLoc, Loc});
17041708

17051709
break;
17061710
case TAK_escaping:
@@ -4722,11 +4726,15 @@ Parser::parseDeclFunc(SourceLoc StaticLoc, StaticSpellingKind StaticSpelling,
47224726
// Within a protocol, recover from a missing 'static'.
47234727
if (Flags & PD_InProtocol) {
47244728
switch (StaticSpelling) {
4725-
case StaticSpellingKind::None:
4726-
diagnose(NameLoc, diag::operator_static_in_protocol, SimpleName.str())
4727-
.fixItInsert(FuncLoc, "static ");
4729+
case StaticSpellingKind::None: {
4730+
auto Message = Context.isSwiftVersion3()
4731+
? diag::swift3_operator_static_in_protocol
4732+
: diag::operator_static_in_protocol;
4733+
diagnose(NameLoc, Message, SimpleName.str())
4734+
.fixItInsert(FuncLoc, "static ");
47284735
StaticSpelling = StaticSpellingKind::KeywordStatic;
47294736
break;
4737+
}
47304738

47314739
case StaticSpellingKind::KeywordStatic:
47324740
// Okay, this is correct.
@@ -5846,9 +5854,15 @@ Parser::parseDeclOperatorImpl(SourceLoc OperatorLoc, Identifier Name,
58465854
SourceLoc lBraceLoc;
58475855
if (consumeIf(tok::l_brace, lBraceLoc)) {
58485856
if (isInfix && !Tok.is(tok::r_brace)) {
5849-
diagnose(lBraceLoc, diag::deprecated_operator_body_use_group);
5857+
auto message = Context.isSwiftVersion3()
5858+
? diag::swift3_deprecated_operator_body_use_group
5859+
: diag::deprecated_operator_body_use_group;
5860+
diagnose(lBraceLoc, message);
58505861
} else {
5851-
auto Diag = diagnose(lBraceLoc, diag::deprecated_operator_body);
5862+
auto message = Context.isSwiftVersion3()
5863+
? diag::swift3_deprecated_operator_body
5864+
: diag::deprecated_operator_body;
5865+
auto Diag = diagnose(lBraceLoc, message);
58525866
if (Tok.is(tok::r_brace)) {
58535867
SourceLoc lastGoodLoc = precedenceGroupNameLoc;
58545868
if (lastGoodLoc.isInvalid())

lib/Parse/ParsePattern.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,11 @@ mapParsedParameters(Parser &parser,
442442
// Warn when an unlabeled parameter follows a variadic parameter
443443
if (ellipsisLoc.isValid() && elements.back()->isVariadic() &&
444444
param.FirstName.empty()) {
445-
parser.diagnose(param.FirstNameLoc,
446-
diag::unlabeled_parameter_following_variadic_parameter);
445+
auto message =
446+
parser.Context.isSwiftVersion3()
447+
? diag::swift3_unlabeled_parameter_following_variadic_parameter
448+
: diag::unlabeled_parameter_following_variadic_parameter;
449+
parser.diagnose(param.FirstNameLoc, message);
447450
}
448451

449452
// If this parameter had an ellipsis, check whether it's the last parameter.

lib/Parse/ParseType.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -753,13 +753,16 @@ ParserResult<TypeRepr> Parser::parseOldStyleProtocolComposition() {
753753
replacement += TrailingContent;
754754
}
755755

756+
auto isThree = Context.isSwiftVersion3();
757+
#define THREEIFY(MESSAGE) (isThree ? diag::swift3_##MESSAGE : diag::MESSAGE)
756758
// Replace 'protocol<T1, T2>' with 'T1 & T2'
757759
diagnose(ProtocolLoc,
758-
IsEmpty ? diag::deprecated_any_composition :
759-
Protocols.size() > 1 ? diag::deprecated_protocol_composition :
760-
diag::deprecated_protocol_composition_single)
760+
IsEmpty ? THREEIFY(deprecated_any_composition) :
761+
Protocols.size() > 1 ? THREEIFY(deprecated_protocol_composition) :
762+
THREEIFY(deprecated_protocol_composition_single))
761763
.highlight(composition->getSourceRange())
762764
.fixItReplace(composition->getSourceRange(), replacement);
765+
#undef THREEIFY
763766
}
764767

765768
return makeParserResult(Status, composition);

test/Parse/deprecated_where.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func testCombinedConstraints<T: ProtoA & ProtoB where T: ProtoC>(x: T) {} // exp
7676
func testCombinedConstraints<T: ProtoA & ProtoB where T: ProtoC>(x: T) where T: ProtoD {} // expected-error {{'where' clause next to generic parameters is obsoleted}} {{48-64=}} {{72-77=where T: ProtoC,}}
7777

7878
func testCombinedConstraintsOld<T: protocol<ProtoA, ProtoB> where T: ProtoC>(x: T) {} // expected-error {{'where' clause next to generic parameters is obsoleted}} {{60-76=}} {{83-83= where T: ProtoC}}
79-
// expected-warning@-1 {{'protocol<...>' composition syntax is deprecated}}
79+
// expected-error@-1 {{'protocol<...>' composition syntax has been removed}}
8080
func testCombinedConstraintsOld<T: protocol<ProtoA, ProtoB> where T: ProtoC>(x: T) where T: ProtoD {} // expected-error {{'where' clause next to generic parameters is obsoleted}} {{60-76=}} {{84-89=where T: ProtoC,}}
81-
// expected-warning@-1 {{'protocol<...>' composition syntax is deprecated}}
81+
// expected-error@-1 {{'protocol<...>' composition syntax has been removed}}
8282

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %target-swift-frontend -typecheck -verify -swift-version 3 %s
2+
3+
protocol Operator {
4+
func +(lhs: Self, rhs: Self) -> Self // expected-warning {{operator '+' declared in protocol must be 'static'}}
5+
}
6+
7+
func foo(x: Int..., _: String) {} // expected-warning {{a parameter following a variadic parameter requires a label}}
8+
9+
protocol P1 {}
10+
protocol P2 {}
11+
12+
let x: protocol<> // expected-warning {{'protocol<>' syntax is deprecated; use 'Any' instead}}
13+
let y: protocol<P1> // expected-warning {{'protocol<...>' composition syntax is deprecated and not needed here}}}
14+
let z: protocol<P1, P2> // expected-warning {{'protocol<...>' composition syntax is deprecated; join the protocols using '&'}}
15+
16+
func bar(f: @noescape () -> ()) {} // expected-warning {{@noescape is the default and is deprecated}}
17+
18+
func baz(f: @autoclosure(escaping) () -> ()) {} // expected-warning {{@autoclosure(escaping) is deprecated; use @autoclosure @escaping instead}}
19+
20+
prefix operator +++ {} // expected-warning {{operator should no longer be declared with body}}
21+
postfix operator +++ {} // expected-warning {{operator should no longer be declared with body}}
22+
infix operator +++ {} // expected-warning {{operator should no longer be declared with body}}
23+
infix operator +++* { // expected-warning {{operator should no longer be declared with body; use a precedence group instead}}
24+
associativity right
25+
}
26+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %target-swift-frontend -typecheck -verify -swift-version 4 %s
2+
3+
protocol Operator {
4+
func +(lhs: Self, rhs: Self) -> Self // expected-error {{operator '+' declared in protocol must be 'static'}}
5+
}
6+
7+
func foo(x: Int..., _: String) {} // expected-error {{a parameter following a variadic parameter requires a label}}
8+
9+
protocol P1 {}
10+
protocol P2 {}
11+
12+
let x: protocol<> // expected-error {{'protocol<>' syntax has been removed; use 'Any' instead}}
13+
let y: protocol<P1> // expected-error {{'protocol<...>' composition syntax has been removed and is not needed here}}}
14+
let z: protocol<P1, P2> // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}}
15+
16+
func bar(f: @noescape () -> ()) {} // expected-error {{@noescape is the default and has been removed}}
17+
18+
func baz(f: @autoclosure(escaping) () -> ()) {} // expected-error {{@autoclosure(escaping) has been removed; use @autoclosure @escaping instead}}
19+
20+
prefix operator +++ {} // expected-error {{operator should no longer be declared with body}}
21+
postfix operator +++ {} // expected-error {{operator should no longer be declared with body}}
22+
infix operator +++ {} // expected-error {{operator should no longer be declared with body}}
23+
infix operator +++* { // expected-error {{operator should no longer be declared with body; use a precedence group instead}}
24+
associativity right
25+
}

test/SILOptimizer/devirt_static_witness_method.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Swift
66
import SwiftShims
77

88
protocol CanAdd {
9-
func +(lhs: Self, rhs: Self) -> Self
9+
static func +(lhs: Self, rhs: Self) -> Self
1010
}
1111

1212
extension Int64 : CanAdd {

test/Serialization/Inputs/has_xref.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public func numericArray(_ x: IntSlice) {}
1010

1111

1212
public protocol ExtraIncrementable {
13-
prefix func +++(base: inout Self)
13+
static prefix func +++(base: inout Self)
1414
}
1515

1616
extension SpecialInt : ExtraIncrementable {}

test/attr/attr_escaping.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ func paramDeclEscaping(@escaping fn: (Int) -> Void) {} // expected-error {{attri
66
func wrongParamType(a: @escaping Int) {} // expected-error {{@escaping attribute only applies to function types}}
77

88
func conflictingAttrs(_ fn: @noescape @escaping () -> Int) {} // expected-error {{@escaping conflicts with @noescape}}
9-
// expected-warning@-1{{@noescape is the default and is deprecated}} {{29-39=}}
9+
// expected-error@-1{{@noescape is the default and has been removed}} {{29-39=}}
1010

1111
func takesEscaping(_ fn: @escaping () -> Int) {} // ok
1212

0 commit comments

Comments
 (0)