Skip to content

Commit 2e952d2

Browse files
authored
Merge pull request #10908 from huonw/swift3-is-behind-us-now
Upgrade some deprecation warnings from Swift 3 to errors in Swift 4.
2 parents ce53a65 + f8a523b commit 2e952d2

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
@@ -325,9 +325,12 @@ ERROR(static_func_decl_global_scope,none,
325325
(StaticSpellingKind))
326326
ERROR(func_decl_expected_arrow,none,
327327
"expected '->' after function parameter tuple", ())
328-
WARNING(operator_static_in_protocol,none,
328+
WARNING(swift3_operator_static_in_protocol,none,
329329
"operator '%0' declared in protocol must be 'static'",
330330
(StringRef))
331+
ERROR(operator_static_in_protocol,none,
332+
"operator '%0' declared in protocol must be 'static'",
333+
(StringRef))
331334

332335
// Enum
333336
ERROR(expected_lbrace_enum,PointsToFirstBadToken,
@@ -415,11 +418,16 @@ ERROR(expected_operator_name_after_operator,PointsToFirstBadToken,
415418
ERROR(identifier_when_expecting_operator,PointsToFirstBadToken,
416419
"%0 is considered to be an identifier, not an operator", (Identifier))
417420

418-
WARNING(deprecated_operator_body,PointsToFirstBadToken,
421+
WARNING(swift3_deprecated_operator_body,PointsToFirstBadToken,
419422
"operator should no longer be declared with body", ())
420-
WARNING(deprecated_operator_body_use_group,PointsToFirstBadToken,
423+
ERROR(deprecated_operator_body,PointsToFirstBadToken,
424+
"operator should no longer be declared with body", ())
425+
WARNING(swift3_deprecated_operator_body_use_group,PointsToFirstBadToken,
421426
"operator should no longer be declared with body; "
422427
"use a precedence group instead", ())
428+
ERROR(deprecated_operator_body_use_group,PointsToFirstBadToken,
429+
"operator should no longer be declared with body; "
430+
"use a precedence group instead", ())
423431
ERROR(operator_decl_no_fixity,none,
424432
"operator must be declared as 'prefix', 'postfix', or 'infix'", ())
425433

@@ -736,12 +744,18 @@ ERROR(expected_rangle_protocol,PointsToFirstBadToken,
736744
ERROR(disallowed_protocol_composition,PointsToFirstBadToken,
737745
"protocol-constrained type is neither allowed nor needed here", ())
738746

739-
WARNING(deprecated_protocol_composition,none,
747+
WARNING(swift3_deprecated_protocol_composition,none,
740748
"'protocol<...>' composition syntax is deprecated; join the protocols using '&'", ())
741-
WARNING(deprecated_protocol_composition_single,none,
749+
ERROR(deprecated_protocol_composition,none,
750+
"'protocol<...>' composition syntax has been removed; join the protocols using '&'", ())
751+
WARNING(swift3_deprecated_protocol_composition_single,none,
742752
"'protocol<...>' composition syntax is deprecated and not needed here", ())
743-
WARNING(deprecated_any_composition,none,
753+
ERROR(deprecated_protocol_composition_single,none,
754+
"'protocol<...>' composition syntax has been removed and is not needed here", ())
755+
WARNING(swift3_deprecated_any_composition,none,
744756
"'protocol<>' syntax is deprecated; use 'Any' instead", ())
757+
ERROR(deprecated_any_composition,none,
758+
"'protocol<>' syntax has been removed; use 'Any' instead", ())
745759

746760
// SIL box Types
747761
ERROR(sil_box_expected_var_or_let,none,
@@ -842,8 +856,10 @@ ERROR(parameter_curry_syntax_removed,none,
842856
ERROR(initializer_as_typed_pattern,none,
843857
"unexpected initializer in pattern; did you mean to use '='?", ())
844858

845-
WARNING(unlabeled_parameter_following_variadic_parameter,none,
859+
WARNING(swift3_unlabeled_parameter_following_variadic_parameter,none,
846860
"a parameter following a variadic parameter requires a label", ())
861+
ERROR(unlabeled_parameter_following_variadic_parameter,none,
862+
"a parameter following a variadic parameter requires a label", ())
847863

848864
//------------------------------------------------------------------------------
849865
// Statement parsing diagnostics
@@ -1303,12 +1319,18 @@ ERROR(attr_noescape_conflicts_escaping_autoclosure,none,
13031319
ERROR(attr_noescape_implied_by_autoclosure,none,
13041320
"@noescape is implied by @autoclosure and should not be "
13051321
"redundantly specified", ())
1306-
WARNING(attr_autoclosure_escaping_deprecated,none,
1322+
WARNING(swift3_attr_autoclosure_escaping_deprecated,none,
13071323
"@autoclosure(escaping) is deprecated; use @autoclosure @escaping instead",
13081324
())
1309-
WARNING(attr_noescape_deprecated,none,
1325+
ERROR(attr_autoclosure_escaping_deprecated,none,
1326+
"@autoclosure(escaping) has been removed; use @autoclosure @escaping instead",
1327+
())
1328+
WARNING(swift3_attr_noescape_deprecated,none,
13101329
"@noescape is the default and is deprecated",
13111330
())
1331+
ERROR(attr_noescape_deprecated,none,
1332+
"@noescape is the default and has been removed",
1333+
())
13121334

13131335
// convention
13141336
ERROR(convention_attribute_expected_lparen,none,

lib/Parse/ParseDecl.cpp

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,7 +1647,9 @@ bool Parser::parseTypeAttribute(TypeAttributes &Attributes, bool justChecking) {
16471647
if (Attributes.has(TAK_noescape)) {
16481648
diagnose(Loc, diag::attr_noescape_conflicts_escaping_autoclosure);
16491649
} else {
1650-
diagnose(Loc, diag::attr_autoclosure_escaping_deprecated)
1650+
diagnose(Loc, Context.isSwiftVersion3()
1651+
? diag::swift3_attr_autoclosure_escaping_deprecated
1652+
: diag::attr_autoclosure_escaping_deprecated)
16511653
.fixItReplace(autoclosureEscapingParenRange, " @escaping ");
16521654
}
16531655
Attributes.setAttr(TAK_escaping, Loc);
@@ -1669,8 +1671,10 @@ bool Parser::parseTypeAttribute(TypeAttributes &Attributes, bool justChecking) {
16691671
}
16701672

16711673
// @noescape is deprecated and no longer used
1672-
diagnose(Loc, diag::attr_noescape_deprecated)
1673-
.fixItRemove({Attributes.AtLoc,Loc});
1674+
diagnose(Loc, Context.isSwiftVersion3()
1675+
? diag::swift3_attr_noescape_deprecated
1676+
: diag::attr_noescape_deprecated)
1677+
.fixItRemove({Attributes.AtLoc, Loc});
16741678

16751679
break;
16761680
case TAK_escaping:
@@ -4719,11 +4723,15 @@ Parser::parseDeclFunc(SourceLoc StaticLoc, StaticSpellingKind StaticSpelling,
47194723
// Within a protocol, recover from a missing 'static'.
47204724
if (Flags & PD_InProtocol) {
47214725
switch (StaticSpelling) {
4722-
case StaticSpellingKind::None:
4723-
diagnose(NameLoc, diag::operator_static_in_protocol, SimpleName.str())
4724-
.fixItInsert(FuncLoc, "static ");
4726+
case StaticSpellingKind::None: {
4727+
auto Message = Context.isSwiftVersion3()
4728+
? diag::swift3_operator_static_in_protocol
4729+
: diag::operator_static_in_protocol;
4730+
diagnose(NameLoc, Message, SimpleName.str())
4731+
.fixItInsert(FuncLoc, "static ");
47254732
StaticSpelling = StaticSpellingKind::KeywordStatic;
47264733
break;
4734+
}
47274735

47284736
case StaticSpellingKind::KeywordStatic:
47294737
// Okay, this is correct.
@@ -5844,9 +5852,15 @@ Parser::parseDeclOperatorImpl(SourceLoc OperatorLoc, Identifier Name,
58445852
SourceLoc lBraceLoc;
58455853
if (consumeIf(tok::l_brace, lBraceLoc)) {
58465854
if (isInfix && !Tok.is(tok::r_brace)) {
5847-
diagnose(lBraceLoc, diag::deprecated_operator_body_use_group);
5855+
auto message = Context.isSwiftVersion3()
5856+
? diag::swift3_deprecated_operator_body_use_group
5857+
: diag::deprecated_operator_body_use_group;
5858+
diagnose(lBraceLoc, message);
58485859
} else {
5849-
auto Diag = diagnose(lBraceLoc, diag::deprecated_operator_body);
5860+
auto message = Context.isSwiftVersion3()
5861+
? diag::swift3_deprecated_operator_body
5862+
: diag::deprecated_operator_body;
5863+
auto Diag = diagnose(lBraceLoc, message);
58505864
if (Tok.is(tok::r_brace)) {
58515865
SourceLoc lastGoodLoc = precedenceGroupNameLoc;
58525866
if (lastGoodLoc.isInvalid())

lib/Parse/ParsePattern.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,11 @@ mapParsedParameters(Parser &parser,
439439
// Warn when an unlabeled parameter follows a variadic parameter
440440
if (ellipsisLoc.isValid() && elements.back()->isVariadic() &&
441441
param.FirstName.empty()) {
442-
parser.diagnose(param.FirstNameLoc,
443-
diag::unlabeled_parameter_following_variadic_parameter);
442+
auto message =
443+
parser.Context.isSwiftVersion3()
444+
? diag::swift3_unlabeled_parameter_following_variadic_parameter
445+
: diag::unlabeled_parameter_following_variadic_parameter;
446+
parser.diagnose(param.FirstNameLoc, message);
444447
}
445448

446449
// 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 obsolete}} {{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 obsolete}} {{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 obsolete}} {{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)