Skip to content

Commit 8e12008

Browse files
committed
Mark tuple splat and ++/-- as errors instead of warnings. This
wraps up SE-0004 and SE-0029. I consider the diagnostic changes in Constraints/lvalues.swift to be indicative of a QoI regression, but I'll deal with that separately.
1 parent ae5f67c commit 8e12008

12 files changed

+81
-91
lines changed

include/swift/AST/DiagnosticsSema.def

+2-2
Original file line numberDiff line numberDiff line change
@@ -2059,8 +2059,8 @@ WARNING(store_in_willset,none,
20592059
"attempting to store to property %0 within its own willSet, which is "
20602060
"about to be overwritten by the new value", (Identifier))
20612061

2062-
WARNING(tuple_splat_use,none,
2063-
"passing %0 arguments to a callee as a single tuple value is deprecated",
2062+
ERROR(tuple_splat_use,none,
2063+
"passing %0 arguments to a callee as a single tuple value has been removed in Swift 3",
20642064
(unsigned))
20652065

20662066

lib/Sema/CSDiag.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -4209,9 +4209,9 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
42094209
// Get the expression result of type checking the arguments to the call
42104210
// independently, so we have some idea of what we're working with.
42114211
//
4212-
auto argExpr = typeCheckArgumentChildIndependently(callExpr->getArg(), argType,
4213-
calleeInfo,
4214-
TCC_AllowUnresolvedTypeVariables);
4212+
auto argExpr = typeCheckArgumentChildIndependently(callExpr->getArg(),
4213+
argType, calleeInfo,
4214+
TCC_AllowUnresolvedTypeVariables);
42154215
if (!argExpr)
42164216
return true; // already diagnosed.
42174217

lib/Sema/MiscDiagnostics.cpp

+22-20
Original file line numberDiff line numberDiff line change
@@ -973,8 +973,8 @@ class AvailabilityWalker : public ASTWalker {
973973

974974
private:
975975
bool diagAvailability(const ValueDecl *D, SourceRange R);
976-
bool diagnoseIncDecDeprecation(const ValueDecl *D, SourceRange R,
977-
const AvailableAttr *Attr);
976+
bool diagnoseIncDecRemoval(const ValueDecl *D, SourceRange R,
977+
const AvailableAttr *Attr);
978978

979979
/// Walk an assignment expression, checking for availability.
980980
void walkAssignExpr(AssignExpr *E) {
@@ -1090,13 +1090,16 @@ bool AvailabilityWalker::diagAvailability(const ValueDecl *D, SourceRange R) {
10901090
if (!D)
10911091
return false;
10921092

1093+
if (auto *attr = AvailableAttr::isUnavailable(D))
1094+
if (diagnoseIncDecRemoval(D, R, attr))
1095+
return true;
1096+
10931097
if (TC.diagnoseExplicitUnavailability(D, R, DC))
10941098
return true;
10951099

10961100
// Diagnose for deprecation
10971101
if (const AvailableAttr *Attr = TypeChecker::getDeprecated(D)) {
1098-
if (!diagnoseIncDecDeprecation(D, R, Attr))
1099-
TC.diagnoseDeprecated(R, DC, Attr, D->getFullName());
1102+
TC.diagnoseDeprecated(R, DC, Attr, D->getFullName());
11001103
}
11011104

11021105
if (TC.getLangOpts().DisableAvailabilityChecking)
@@ -1132,11 +1135,11 @@ static bool isIntegerOrFloatingPointType(Type ty, DeclContext *DC,
11321135
}
11331136

11341137

1135-
/// If this is a call to a deprecated ++ / -- operator, try to diagnose it with
1136-
/// a fixit hint and return true. If not, or if we fail, return false.
1137-
bool AvailabilityWalker::diagnoseIncDecDeprecation(const ValueDecl *D,
1138-
SourceRange R,
1139-
const AvailableAttr *Attr) {
1138+
/// If this is a call to an unavailable ++ / -- operator, try to diagnose it
1139+
/// with a fixit hint and return true. If not, or if we fail, return false.
1140+
bool AvailabilityWalker::diagnoseIncDecRemoval(const ValueDecl *D,
1141+
SourceRange R,
1142+
const AvailableAttr *Attr) {
11401143
// We can only produce a fixit if we're talking about ++ or --.
11411144
bool isInc = D->getNameStr() == "++";
11421145
if (!isInc && D->getNameStr() != "--")
@@ -1171,17 +1174,16 @@ bool AvailabilityWalker::diagnoseIncDecDeprecation(const ValueDecl *D,
11711174

11721175
if (!replacement.empty()) {
11731176
// If we emit a deprecation diagnostic, produce a fixit hint as well.
1174-
TC.diagnoseDeprecated(R, DC, Attr, D->getFullName(),
1175-
[&](InFlightDiagnostic &diag) {
1176-
if (isa<PrefixUnaryExpr>(call)) {
1177-
// Prefix: remove the ++ or --.
1178-
diag.fixItRemove(call->getFn()->getSourceRange());
1179-
diag.fixItInsertAfter(call->getArg()->getEndLoc(), replacement);
1180-
} else {
1181-
// Postfix: replace the ++ or --.
1182-
diag.fixItReplace(call->getFn()->getSourceRange(), replacement);
1183-
}
1184-
});
1177+
auto diag = TC.diagnose(R.Start, diag::availability_decl_unavailable_msg,
1178+
D->getFullName(), "it has been removed in Swift 3");
1179+
if (isa<PrefixUnaryExpr>(call)) {
1180+
// Prefix: remove the ++ or --.
1181+
diag.fixItRemove(call->getFn()->getSourceRange());
1182+
diag.fixItInsertAfter(call->getArg()->getEndLoc(), replacement);
1183+
} else {
1184+
// Postfix: replace the ++ or --.
1185+
diag.fixItReplace(call->getFn()->getSourceRange(), replacement);
1186+
}
11851187

11861188
return true;
11871189
}

lib/Sema/TypeChecker.cpp

+13-20
Original file line numberDiff line numberDiff line change
@@ -2244,8 +2244,7 @@ static bool isInsideDeprecatedDeclaration(SourceRange ReferenceRange,
22442244
void TypeChecker::diagnoseDeprecated(SourceRange ReferenceRange,
22452245
const DeclContext *ReferenceDC,
22462246
const AvailableAttr *Attr,
2247-
DeclName Name,
2248-
std::function<void(InFlightDiagnostic&)> extraInfoHandler) {
2247+
DeclName Name) {
22492248
// We match the behavior of clang to not report deprecation warnings
22502249
// inside declarations that are themselves deprecated on all deployment
22512250
// targets.
@@ -2270,30 +2269,24 @@ void TypeChecker::diagnoseDeprecated(SourceRange ReferenceRange,
22702269
DeprecatedVersion = Attr->Deprecated.getValue();
22712270

22722271
if (Attr->Message.empty() && Attr->Rename.empty()) {
2273-
auto diagValue = std::move(
2274-
diagnose(ReferenceRange.Start, diag::availability_deprecated, Name,
2275-
Attr->hasPlatform(), Platform, Attr->Deprecated.hasValue(),
2276-
DeprecatedVersion)
2277-
.highlight(Attr->getRange()));
2278-
extraInfoHandler(diagValue);
2272+
diagnose(ReferenceRange.Start, diag::availability_deprecated, Name,
2273+
Attr->hasPlatform(), Platform, Attr->Deprecated.hasValue(),
2274+
DeprecatedVersion)
2275+
.highlight(Attr->getRange());
22792276
return;
22802277
}
22812278

22822279
if (Attr->Message.empty()) {
2283-
auto diagValue = std::move(
2284-
diagnose(ReferenceRange.Start, diag::availability_deprecated_rename, Name,
2285-
Attr->hasPlatform(), Platform, Attr->Deprecated.hasValue(),
2286-
DeprecatedVersion, Attr->Rename)
2287-
.highlight(Attr->getRange()));
2288-
extraInfoHandler(diagValue);
2280+
diagnose(ReferenceRange.Start, diag::availability_deprecated_rename, Name,
2281+
Attr->hasPlatform(), Platform, Attr->Deprecated.hasValue(),
2282+
DeprecatedVersion, Attr->Rename)
2283+
.highlight(Attr->getRange());
22892284
} else {
22902285
EncodedDiagnosticMessage EncodedMessage(Attr->Message);
2291-
auto diagValue = std::move(
2292-
diagnose(ReferenceRange.Start, diag::availability_deprecated_msg, Name,
2293-
Attr->hasPlatform(), Platform, Attr->Deprecated.hasValue(),
2294-
DeprecatedVersion, EncodedMessage.Message)
2295-
.highlight(Attr->getRange()));
2296-
extraInfoHandler(diagValue);
2286+
diagnose(ReferenceRange.Start, diag::availability_deprecated_msg, Name,
2287+
Attr->hasPlatform(), Platform, Attr->Deprecated.hasValue(),
2288+
DeprecatedVersion, EncodedMessage.Message)
2289+
.highlight(Attr->getRange());
22972290
}
22982291

22992292
if (!Attr->Rename.empty()) {

lib/Sema/TypeChecker.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -1757,9 +1757,7 @@ class TypeChecker final : public LazyResolver {
17571757
void diagnoseDeprecated(SourceRange SourceRange,
17581758
const DeclContext *ReferenceDC,
17591759
const AvailableAttr *Attr,
1760-
DeclName Name,
1761-
std::function<void(InFlightDiagnostic&)> extraInfoHandler =
1762-
[](InFlightDiagnostic&){});
1760+
DeclName Name);
17631761
/// @}
17641762

17651763
/// If LangOptions::DebugForbidTypecheckPrefix is set and the given decl

stdlib/public/core/FixedPoint.swift.gyb

+4-6
Original file line numberDiff line numberDiff line change
@@ -619,32 +619,30 @@ public func ${op}=(lhs: inout ${Self}, rhs: ${Self}) {
619619

620620
// Prefix and postfix increment and decrement.
621621

622-
// FIXME: After <rdar://problem/20226526> is fixed, we should be able
623-
// to remove these.
624622
@_transparent
625-
@available(*, deprecated, message: "it will be removed in Swift 3")
623+
@available(*, unavailable, message: "it has been removed in Swift 3")
626624
public prefix func ++ (x: inout ${Self}) -> ${Self} {
627625
x = x + 1
628626
return x
629627
}
630628

631629
@_transparent
632-
@available(*, deprecated, message: "it will be removed in Swift 3")
630+
@available(*, unavailable, message: "it has been removed in Swift 3")
633631
public postfix func ++ (x: inout ${Self}) -> ${Self} {
634632
let ret = x
635633
x = x + 1
636634
return ret
637635
}
638636

639637
@_transparent
640-
@available(*, deprecated, message: "it will be removed in Swift 3")
638+
@available(*, unavailable, message: "it has been removed in Swift 3")
641639
public prefix func -- (x: inout ${Self}) -> ${Self} {
642640
x = x - 1
643641
return x
644642
}
645643

646644
@_transparent
647-
@available(*, deprecated, message: "it will be removed in Swift 3")
645+
@available(*, unavailable, message: "it has been removed in Swift 3")
648646
public postfix func -- (x: inout ${Self}) -> ${Self} {
649647
let ret = x
650648
x = x - 1

stdlib/public/core/FloatingPoint.swift.gyb

+4-4
Original file line numberDiff line numberDiff line change
@@ -564,16 +564,16 @@ extension ${Self} {
564564
//===----------------------------------------------------------------------===//
565565

566566
@_transparent
567-
@available(*, deprecated, message: "it will be removed in Swift 3")
567+
@available(*, unavailable, message: "it has been removed in Swift 3")
568568
public prefix func ++ (rhs: inout ${Self}) -> ${Self} { rhs += 1.0; return rhs }
569569
@_transparent
570-
@available(*, deprecated, message: "it will be removed in Swift 3")
570+
@available(*, unavailable, message: "it has been removed in Swift 3")
571571
public prefix func -- (rhs: inout ${Self}) -> ${Self} { rhs -= 1.0; return rhs }
572572
@_transparent
573-
@available(*, deprecated, message: "it will be removed in Swift 3")
573+
@available(*, unavailable, message: "it has been removed in Swift 3")
574574
public postfix func ++ (lhs: inout ${Self}) -> ${Self} { let tmp = lhs; lhs += 1.0; return tmp }
575575
@_transparent
576-
@available(*, deprecated, message: "it will be removed in Swift 3")
576+
@available(*, unavailable, message: "it has been removed in Swift 3")
577577
public postfix func -- (lhs: inout ${Self}) -> ${Self} { let tmp = lhs; lhs -= 1.0; return tmp }
578578

579579

stdlib/public/core/Index.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public struct _DisabledRangeIndex_ {
5454
/// Replace `i` with its `successor()` and return the updated value of
5555
/// `i`.
5656
@_transparent
57-
@available(*, deprecated, message: "it will be removed in Swift 3")
57+
@available(*, unavailable, message: "it has been removed in Swift 3")
5858
public prefix func ++ <T : _Incrementable> (i: inout T) -> T {
5959
i._successorInPlace()
6060
return i
@@ -63,7 +63,7 @@ public prefix func ++ <T : _Incrementable> (i: inout T) -> T {
6363
/// Replace `i` with its `successor()` and return the original
6464
/// value of `i`.
6565
@_transparent
66-
@available(*, deprecated, message: "it will be removed in Swift 3")
66+
@available(*, unavailable, message: "it has been removed in Swift 3")
6767
public postfix func ++ <T : _Incrementable> (i: inout T) -> T {
6868
let ret = i
6969
i._successorInPlace()
@@ -308,7 +308,7 @@ extension BidirectionalIndex {
308308
/// Replace `i` with its `predecessor()` and return the updated value
309309
/// of `i`.
310310
@_transparent
311-
@available(*, deprecated, message: "it will be removed in Swift 3")
311+
@available(*, unavailable, message: "it has been removed in Swift 3")
312312
public prefix func -- <T : BidirectionalIndex> (i: inout T) -> T {
313313
i._predecessorInPlace()
314314
return i
@@ -318,7 +318,7 @@ public prefix func -- <T : BidirectionalIndex> (i: inout T) -> T {
318318
/// Replace `i` with its `predecessor()` and return the original
319319
/// value of `i`.
320320
@_transparent
321-
@available(*, deprecated, message: "it will be removed in Swift 3")
321+
@available(*, unavailable, message: "it has been removed in Swift 3")
322322
public postfix func -- <T : BidirectionalIndex> (i: inout T) -> T {
323323
let ret = i
324324
i._predecessorInPlace()

test/Constraints/lvalues.swift

+5-6
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ x += x
4949
var yi = y[i]
5050

5151
// Non-settable lvalues
52-
// FIXME: better diagnostic!
5352

5453
var non_settable_x : X {
5554
return x
@@ -78,28 +77,28 @@ f2(&non_settable_x) // expected-error{{cannot pass immutable value as inout argu
7877
f1(&non_settable_x) // expected-error{{cannot pass immutable value as inout argument: 'non_settable_x' is a get-only property}}
7978
// - inout assignment
8079
non_settable_x += x // expected-error{{left side of mutating operator isn't mutable: 'non_settable_x' is a get-only property}}
81-
++non_settable_x // expected-error{{cannot pass immutable value to mutating operator: 'non_settable_x' is a get-only property}}
80+
++non_settable_x // expected-error{{cannot pass immutable value as inout argument: 'non_settable_x' is a get-only property}}
8281

8382
// non-settable property is non-settable:
8483
z.non_settable_x = x // expected-error{{cannot assign to property: 'non_settable_x' is a get-only property}}
8584
f2(&z.non_settable_x) // expected-error{{cannot pass immutable value as inout argument: 'non_settable_x' is a get-only property}}
8685
f1(&z.non_settable_x) // expected-error{{cannot pass immutable value as inout argument: 'non_settable_x' is a get-only property}}
8786
z.non_settable_x += x // expected-error{{left side of mutating operator isn't mutable: 'non_settable_x' is a get-only property}}
88-
++z.non_settable_x // expected-error{{cannot pass immutable value to mutating operator: 'non_settable_x' is a get-only property}}
87+
++z.non_settable_x // expected-error{{cannot pass immutable value as inout argument: 'non_settable_x' is a get-only property}}
8988

9089
// non-settable subscript is non-settable:
9190
z[0] = 0.0 // expected-error{{cannot assign through subscript: subscript is get-only}}
9291
f2(&z[0]) // expected-error{{cannot pass immutable value as inout argument: subscript is get-only}}
9392
f1(&z[0]) // expected-error{{cannot pass immutable value as inout argument: subscript is get-only}}
9493
z[0] += 0.0 // expected-error{{left side of mutating operator isn't mutable: subscript is get-only}}
95-
++z[0] // expected-error{{cannot pass immutable value to mutating operator: subscript is get-only}}
94+
++z[0] // expected-error{{cannot pass immutable value as inout argument: subscript is get-only}}
9695

9796
// settable property of an rvalue value type is non-settable:
9897
fz().settable_x = x // expected-error{{cannot assign to property: 'fz' returns immutable value}}
9998
f2(&fz().settable_x) // expected-error{{cannot pass immutable value as inout argument: 'fz' returns immutable value}}
10099
f1(&fz().settable_x) // expected-error{{cannot pass immutable value as inout argument: 'fz' returns immutable value}}
101100
fz().settable_x += x // expected-error{{left side of mutating operator isn't mutable: 'fz' returns immutable value}}
102-
++fz().settable_x // expected-error{{cannot pass immutable value to mutating operator: 'fz' returns immutable value}}
101+
++fz().settable_x // expected-error{{cannot pass immutable value as inout argument: 'fz' returns immutable value}}
103102

104103
// settable property of an rvalue reference type IS SETTABLE:
105104
fref().property = 0.0
@@ -113,7 +112,7 @@ z.non_settable_x.property = 1.0 // expected-error{{cannot assign to property: 'n
113112
f2(&z.non_settable_x.property) // expected-error{{cannot pass immutable value as inout argument: 'non_settable_x' is a get-only property}}
114113
f1(&z.non_settable_x.property) // expected-error{{cannot pass immutable value as inout argument: 'non_settable_x' is a get-only property}}
115114
z.non_settable_x.property += 1.0 // expected-error{{left side of mutating operator isn't mutable: 'non_settable_x' is a get-only property}}
116-
++z.non_settable_x.property // expected-error{{cannot pass immutable value to mutating operator: 'non_settable_x' is a get-only property}}
115+
++z.non_settable_x.property // expected-error{{cannot pass immutable value as inout argument: 'non_settable_x' is a get-only property}}
117116

118117
// settable property of a non-settable reference type IS SETTABLE:
119118
z.non_settable_reftype.property = 1.0

test/Misc/misc_diagnostics.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func test20770032() {
136136

137137
func tuple_splat1(_ a : Int, _ b : Int) {
138138
let x = (1,2)
139-
tuple_splat1(x) // expected-warning {{passing 2 arguments to a callee as a single tuple value is deprecated}}
139+
tuple_splat1(x) // expected-error {{passing 2 arguments to a callee as a single tuple value has been removed in Swift 3}}
140140
tuple_splat1(1, 2) // Ok.
141141
tuple_splat1((1, 2)) // expected-error {{missing argument for parameter #2 in call}}
142142
}

test/Sema/diag_c_style_for.swift

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
11
// RUN: %target-parse-verify-swift
22

3-
// expected-warning @+1 {{'++' is deprecated: it will be removed in Swift 3}}
3+
// expected-error @+1 {{'++' is unavailable: it has been removed in Swift 3}}
44
for var a = 0; a < 10; a++ { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}} {{5-9=}} {{10-13= in }} {{14-20= ..< }} {{22-27=}}
55
}
66

7-
// expected-warning @+1 {{'++' is deprecated: it will be removed in Swift 3}}
7+
// expected-error @+1 {{'++' is unavailable: it has been removed in Swift 3}}
88
for var b = 0; b < 10; ++b { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}} {{5-9=}} {{10-13= in }} {{14-20= ..< }} {{22-27=}}
99
}
1010

11-
// expected-warning @+1 {{'++' is deprecated: it will be removed in Swift 3}}
11+
// expected-error @+1 {{'++' is unavailable: it has been removed in Swift 3}}
1212
for var c=1;c != 5 ;++c { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}} {{5-9=}} {{10-11= in }} {{12-18= ..< }} {{20-24=}}
1313
}
1414

15-
// expected-warning @+1 {{'++' is deprecated: it will be removed in Swift 3}}
15+
// expected-error @+1 {{'++' is unavailable: it has been removed in Swift 3}}
1616
for var d=100;d<5;d++ { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}} {{5-9=}} {{10-11= in }} {{14-17= ..< }} {{18-22=}}
1717
}
1818

1919
// next three aren't auto-fixable
20-
// expected-warning @+1 {{'++' is deprecated: it will be removed in Swift 3}}
20+
// expected-error @+1 {{'++' is unavailable: it has been removed in Swift 3}}
2121
for var e = 3; e > 4; e++ { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}} {{none}}
2222
}
2323

24-
// expected-warning @+1 {{'--' is deprecated: it will be removed in Swift 3}}
24+
// expected-error @+1 {{'--' is unavailable: it has been removed in Swift 3}}
2525
for var f = 3; f < 4; f-- { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}} {{none}}
2626
}
2727

2828
let start = Int8(4)
2929
let count = Int8(10)
3030
var other = Int8(2)
3131

32-
// expected-warning @+1 {{'++' is deprecated: it will be removed in Swift 3}}
32+
// expected-error @+1 {{'++' is unavailable: it has been removed in Swift 3}}
3333
for ; other<count; other++ { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}} {{none}}
3434
}
3535

3636
// this should be fixable, and keep the type
37-
// expected-warning @+1 {{'++' is deprecated: it will be removed in Swift 3}}
37+
// expected-error @+1 {{'++' is unavailable: it has been removed in Swift 3}}
3838
for (var number : Int8 = start; number < count; number++) { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}} {{6-10=}} {{23-26= in }} {{31-42= ..< }} {{47-57=}}
3939
print(number)
4040
}
4141

4242
// should produce extra note
43-
// expected-warning @+1 {{'++' is deprecated: it will be removed in Swift 3}}
43+
// expected-error @+1 {{'++' is unavailable: it has been removed in Swift 3}}
4444
for (var m : Int8 = start; m < count; ++m) { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}} {{none}} expected-note {{C-style for statement can't be automatically fixed to for-in, because the loop variable is modified inside the loop}}
4545
m += 3
4646
}
@@ -52,6 +52,6 @@ for var o = 2; o < 888; o += 11 { // expected-warning {{C-style for statement is
5252
}
5353

5454
// could theoretically fix this with "..."
55-
// expected-warning @+1 {{'++' is deprecated: it will be removed in Swift 3}}
55+
// expected-error @+1 {{'++' is unavailable: it has been removed in Swift 3}}
5656
for var p = 2; p <= 8; p++ { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}} {{none}}
5757
}

0 commit comments

Comments
 (0)