Skip to content

[4.0 2017-07-11] Upgrade some deprecation warnings from Swift 3 to errors in Swift 4 #10924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions include/swift/AST/DiagnosticsParse.def
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,12 @@ ERROR(static_func_decl_global_scope,none,
(StaticSpellingKind))
ERROR(func_decl_expected_arrow,none,
"expected '->' after function parameter tuple", ())
WARNING(operator_static_in_protocol,none,
WARNING(swift3_operator_static_in_protocol,none,
"operator '%0' declared in protocol must be 'static'",
(StringRef))
ERROR(operator_static_in_protocol,none,
"operator '%0' declared in protocol must be 'static'",
(StringRef))

// Enum
ERROR(expected_lbrace_enum,PointsToFirstBadToken,
Expand Down Expand Up @@ -410,11 +413,16 @@ ERROR(expected_operator_name_after_operator,PointsToFirstBadToken,
ERROR(identifier_when_expecting_operator,PointsToFirstBadToken,
"%0 is considered to be an identifier, not an operator", (Identifier))

WARNING(deprecated_operator_body,PointsToFirstBadToken,
WARNING(swift3_deprecated_operator_body,PointsToFirstBadToken,
"operator should no longer be declared with body", ())
WARNING(deprecated_operator_body_use_group,PointsToFirstBadToken,
ERROR(deprecated_operator_body,PointsToFirstBadToken,
"operator should no longer be declared with body", ())
WARNING(swift3_deprecated_operator_body_use_group,PointsToFirstBadToken,
"operator should no longer be declared with body; "
"use a precedence group instead", ())
ERROR(deprecated_operator_body_use_group,PointsToFirstBadToken,
"operator should no longer be declared with body; "
"use a precedence group instead", ())
ERROR(operator_decl_no_fixity,none,
"operator must be declared as 'prefix', 'postfix', or 'infix'", ())

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

WARNING(deprecated_protocol_composition,none,
WARNING(swift3_deprecated_protocol_composition,none,
"'protocol<...>' composition syntax is deprecated; join the protocols using '&'", ())
WARNING(deprecated_protocol_composition_single,none,
ERROR(deprecated_protocol_composition,none,
"'protocol<...>' composition syntax has been removed; join the protocols using '&'", ())
WARNING(swift3_deprecated_protocol_composition_single,none,
"'protocol<...>' composition syntax is deprecated and not needed here", ())
WARNING(deprecated_any_composition,none,
ERROR(deprecated_protocol_composition_single,none,
"'protocol<...>' composition syntax has been removed and is not needed here", ())
WARNING(swift3_deprecated_any_composition,none,
"'protocol<>' syntax is deprecated; use 'Any' instead", ())
ERROR(deprecated_any_composition,none,
"'protocol<>' syntax has been removed; use 'Any' instead", ())

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

WARNING(unlabeled_parameter_following_variadic_parameter,none,
WARNING(swift3_unlabeled_parameter_following_variadic_parameter,none,
"a parameter following a variadic parameter requires a label", ())
ERROR(unlabeled_parameter_following_variadic_parameter,none,
"a parameter following a variadic parameter requires a label", ())

//------------------------------------------------------------------------------
// Statement parsing diagnostics
Expand Down Expand Up @@ -1298,12 +1314,18 @@ ERROR(attr_noescape_conflicts_escaping_autoclosure,none,
ERROR(attr_noescape_implied_by_autoclosure,none,
"@noescape is implied by @autoclosure and should not be "
"redundantly specified", ())
WARNING(attr_autoclosure_escaping_deprecated,none,
WARNING(swift3_attr_autoclosure_escaping_deprecated,none,
"@autoclosure(escaping) is deprecated; use @autoclosure @escaping instead",
())
WARNING(attr_noescape_deprecated,none,
ERROR(attr_autoclosure_escaping_deprecated,none,
"@autoclosure(escaping) has been removed; use @autoclosure @escaping instead",
())
WARNING(swift3_attr_noescape_deprecated,none,
"@noescape is the default and is deprecated",
())
ERROR(attr_noescape_deprecated,none,
"@noescape is the default and has been removed",
())

// convention
ERROR(convention_attribute_expected_lparen,none,
Expand Down
30 changes: 22 additions & 8 deletions lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1677,7 +1677,9 @@ bool Parser::parseTypeAttribute(TypeAttributes &Attributes, bool justChecking) {
if (Attributes.has(TAK_noescape)) {
diagnose(Loc, diag::attr_noescape_conflicts_escaping_autoclosure);
} else {
diagnose(Loc, diag::attr_autoclosure_escaping_deprecated)
diagnose(Loc, Context.isSwiftVersion3()
? diag::swift3_attr_autoclosure_escaping_deprecated
: diag::attr_autoclosure_escaping_deprecated)
.fixItReplace(autoclosureEscapingParenRange, " @escaping ");
}
Attributes.setAttr(TAK_escaping, Loc);
Expand All @@ -1699,8 +1701,10 @@ bool Parser::parseTypeAttribute(TypeAttributes &Attributes, bool justChecking) {
}

// @noescape is deprecated and no longer used
diagnose(Loc, diag::attr_noescape_deprecated)
.fixItRemove({Attributes.AtLoc,Loc});
diagnose(Loc, Context.isSwiftVersion3()
? diag::swift3_attr_noescape_deprecated
: diag::attr_noescape_deprecated)
.fixItRemove({Attributes.AtLoc, Loc});

break;
case TAK_escaping:
Expand Down Expand Up @@ -4722,11 +4726,15 @@ Parser::parseDeclFunc(SourceLoc StaticLoc, StaticSpellingKind StaticSpelling,
// Within a protocol, recover from a missing 'static'.
if (Flags & PD_InProtocol) {
switch (StaticSpelling) {
case StaticSpellingKind::None:
diagnose(NameLoc, diag::operator_static_in_protocol, SimpleName.str())
.fixItInsert(FuncLoc, "static ");
case StaticSpellingKind::None: {
auto Message = Context.isSwiftVersion3()
? diag::swift3_operator_static_in_protocol
: diag::operator_static_in_protocol;
diagnose(NameLoc, Message, SimpleName.str())
.fixItInsert(FuncLoc, "static ");
StaticSpelling = StaticSpellingKind::KeywordStatic;
break;
}

case StaticSpellingKind::KeywordStatic:
// Okay, this is correct.
Expand Down Expand Up @@ -5846,9 +5854,15 @@ Parser::parseDeclOperatorImpl(SourceLoc OperatorLoc, Identifier Name,
SourceLoc lBraceLoc;
if (consumeIf(tok::l_brace, lBraceLoc)) {
if (isInfix && !Tok.is(tok::r_brace)) {
diagnose(lBraceLoc, diag::deprecated_operator_body_use_group);
auto message = Context.isSwiftVersion3()
? diag::swift3_deprecated_operator_body_use_group
: diag::deprecated_operator_body_use_group;
diagnose(lBraceLoc, message);
} else {
auto Diag = diagnose(lBraceLoc, diag::deprecated_operator_body);
auto message = Context.isSwiftVersion3()
? diag::swift3_deprecated_operator_body
: diag::deprecated_operator_body;
auto Diag = diagnose(lBraceLoc, message);
if (Tok.is(tok::r_brace)) {
SourceLoc lastGoodLoc = precedenceGroupNameLoc;
if (lastGoodLoc.isInvalid())
Expand Down
7 changes: 5 additions & 2 deletions lib/Parse/ParsePattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,11 @@ mapParsedParameters(Parser &parser,
// Warn when an unlabeled parameter follows a variadic parameter
if (ellipsisLoc.isValid() && elements.back()->isVariadic() &&
param.FirstName.empty()) {
parser.diagnose(param.FirstNameLoc,
diag::unlabeled_parameter_following_variadic_parameter);
auto message =
parser.Context.isSwiftVersion3()
? diag::swift3_unlabeled_parameter_following_variadic_parameter
: diag::unlabeled_parameter_following_variadic_parameter;
parser.diagnose(param.FirstNameLoc, message);
}

// If this parameter had an ellipsis, check whether it's the last parameter.
Expand Down
9 changes: 6 additions & 3 deletions lib/Parse/ParseType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,13 +753,16 @@ ParserResult<TypeRepr> Parser::parseOldStyleProtocolComposition() {
replacement += TrailingContent;
}

auto isThree = Context.isSwiftVersion3();
#define THREEIFY(MESSAGE) (isThree ? diag::swift3_##MESSAGE : diag::MESSAGE)
// Replace 'protocol<T1, T2>' with 'T1 & T2'
diagnose(ProtocolLoc,
IsEmpty ? diag::deprecated_any_composition :
Protocols.size() > 1 ? diag::deprecated_protocol_composition :
diag::deprecated_protocol_composition_single)
IsEmpty ? THREEIFY(deprecated_any_composition) :
Protocols.size() > 1 ? THREEIFY(deprecated_protocol_composition) :
THREEIFY(deprecated_protocol_composition_single))
.highlight(composition->getSourceRange())
.fixItReplace(composition->getSourceRange(), replacement);
#undef THREEIFY
}

return makeParserResult(Status, composition);
Expand Down
4 changes: 2 additions & 2 deletions test/Parse/deprecated_where.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func testCombinedConstraints<T: ProtoA & ProtoB where T: ProtoC>(x: T) {} // exp
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,}}

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}}
// expected-warning@-1 {{'protocol<...>' composition syntax is deprecated}}
// expected-error@-1 {{'protocol<...>' composition syntax has been removed}}
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,}}
// expected-warning@-1 {{'protocol<...>' composition syntax is deprecated}}
// expected-error@-1 {{'protocol<...>' composition syntax has been removed}}

26 changes: 26 additions & 0 deletions test/Parse/swift3_warnings_swift4_errors_version_3.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// RUN: %target-swift-frontend -typecheck -verify -swift-version 3 %s

protocol Operator {
func +(lhs: Self, rhs: Self) -> Self // expected-warning {{operator '+' declared in protocol must be 'static'}}
}

func foo(x: Int..., _: String) {} // expected-warning {{a parameter following a variadic parameter requires a label}}

protocol P1 {}
protocol P2 {}

let x: protocol<> // expected-warning {{'protocol<>' syntax is deprecated; use 'Any' instead}}
let y: protocol<P1> // expected-warning {{'protocol<...>' composition syntax is deprecated and not needed here}}}
let z: protocol<P1, P2> // expected-warning {{'protocol<...>' composition syntax is deprecated; join the protocols using '&'}}

func bar(f: @noescape () -> ()) {} // expected-warning {{@noescape is the default and is deprecated}}

func baz(f: @autoclosure(escaping) () -> ()) {} // expected-warning {{@autoclosure(escaping) is deprecated; use @autoclosure @escaping instead}}

prefix operator +++ {} // expected-warning {{operator should no longer be declared with body}}
postfix operator +++ {} // expected-warning {{operator should no longer be declared with body}}
infix operator +++ {} // expected-warning {{operator should no longer be declared with body}}
infix operator +++* { // expected-warning {{operator should no longer be declared with body; use a precedence group instead}}
associativity right
}

25 changes: 25 additions & 0 deletions test/Parse/swift3_warnings_swift4_errors_version_4.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// RUN: %target-swift-frontend -typecheck -verify -swift-version 4 %s

protocol Operator {
func +(lhs: Self, rhs: Self) -> Self // expected-error {{operator '+' declared in protocol must be 'static'}}
}

func foo(x: Int..., _: String) {} // expected-error {{a parameter following a variadic parameter requires a label}}

protocol P1 {}
protocol P2 {}

let x: protocol<> // expected-error {{'protocol<>' syntax has been removed; use 'Any' instead}}
let y: protocol<P1> // expected-error {{'protocol<...>' composition syntax has been removed and is not needed here}}}
let z: protocol<P1, P2> // expected-error {{'protocol<...>' composition syntax has been removed; join the protocols using '&'}}

func bar(f: @noescape () -> ()) {} // expected-error {{@noescape is the default and has been removed}}

func baz(f: @autoclosure(escaping) () -> ()) {} // expected-error {{@autoclosure(escaping) has been removed; use @autoclosure @escaping instead}}

prefix operator +++ {} // expected-error {{operator should no longer be declared with body}}
postfix operator +++ {} // expected-error {{operator should no longer be declared with body}}
infix operator +++ {} // expected-error {{operator should no longer be declared with body}}
infix operator +++* { // expected-error {{operator should no longer be declared with body; use a precedence group instead}}
associativity right
}
2 changes: 1 addition & 1 deletion test/SILOptimizer/devirt_static_witness_method.sil
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Swift
import SwiftShims

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

extension Int64 : CanAdd {
Expand Down
2 changes: 1 addition & 1 deletion test/Serialization/Inputs/has_xref.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public func numericArray(_ x: IntSlice) {}


public protocol ExtraIncrementable {
prefix func +++(base: inout Self)
static prefix func +++(base: inout Self)
}

extension SpecialInt : ExtraIncrementable {}
Expand Down
2 changes: 1 addition & 1 deletion test/attr/attr_escaping.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ func paramDeclEscaping(@escaping fn: (Int) -> Void) {} // expected-error {{attri
func wrongParamType(a: @escaping Int) {} // expected-error {{@escaping attribute only applies to function types}}

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

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

Expand Down
Loading