Skip to content

Commit 3801f4b

Browse files
authored
Merge pull request #16438 from rudkx/rdar39886178-4.2
Conditionalize warnings for IUO-to-Any coercion on Swift version.
2 parents 0e6d867 + 2955cd1 commit 3801f4b

File tree

8 files changed

+205
-64
lines changed

8 files changed

+205
-64
lines changed

lib/AST/Expr.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -1559,8 +1559,17 @@ static ValueDecl *getCalledValue(Expr *E) {
15591559
if (auto *DRE = dyn_cast<DeclRefExpr>(E))
15601560
return DRE->getDecl();
15611561

1562+
if (auto *OCRE = dyn_cast<OtherConstructorDeclRefExpr>(E))
1563+
return OCRE->getDecl();
1564+
1565+
// Look through SelfApplyExpr.
1566+
if (auto *SAE = dyn_cast<SelfApplyExpr>(E))
1567+
return SAE->getCalledValue();
1568+
15621569
Expr *E2 = E->getValueProvidingExpr();
1563-
if (E != E2) return getCalledValue(E2);
1570+
if (E != E2)
1571+
return getCalledValue(E2);
1572+
15641573
return nullptr;
15651574
}
15661575

lib/Sema/MiscDiagnostics.cpp

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -3723,6 +3723,39 @@ static void diagnoseUnintendedOptionalBehavior(TypeChecker &TC, const Expr *E,
37233723
.fixItInsertAfter(E->getEndLoc(), coercionString);
37243724
}
37253725

3726+
static bool hasImplicitlyUnwrappedResult(Expr *E) {
3727+
auto getDeclForExpr = [&](Expr *E) -> ValueDecl * {
3728+
if (auto *call = dyn_cast<CallExpr>(E))
3729+
E = call->getDirectCallee();
3730+
3731+
if (auto *subscript = dyn_cast<SubscriptExpr>(E)) {
3732+
if (subscript->hasDecl())
3733+
return subscript->getDecl().getDecl();
3734+
3735+
return nullptr;
3736+
}
3737+
3738+
if (auto *memberRef = dyn_cast<MemberRefExpr>(E))
3739+
return memberRef->getMember().getDecl();
3740+
if (auto *declRef = dyn_cast<DeclRefExpr>(E))
3741+
return declRef->getDecl();
3742+
if (auto *apply = dyn_cast<ApplyExpr>(E))
3743+
return apply->getCalledValue();
3744+
3745+
return nullptr;
3746+
};
3747+
3748+
// Look through implicit conversions like loads, derived-to-base
3749+
// conversion, etc.
3750+
if (auto *ICE = dyn_cast<ImplicitConversionExpr>(E))
3751+
E = ICE->getSubExpr();
3752+
3753+
auto *decl = getDeclForExpr(E);
3754+
3755+
return decl
3756+
&& decl->getAttrs().hasAttribute<ImplicitlyUnwrappedOptionalAttr>();
3757+
}
3758+
37263759
void visitErasureExpr(ErasureExpr *E, OptionalToAnyCoercion coercion) {
37273760
if (coercion.shouldSuppressDiagnostic())
37283761
return;
@@ -3734,6 +3767,12 @@ static void diagnoseUnintendedOptionalBehavior(TypeChecker &TC, const Expr *E,
37343767
while (auto *bindExpr = dyn_cast<BindOptionalExpr>(subExpr))
37353768
subExpr = bindExpr->getSubExpr();
37363769

3770+
// Do not warn on coercions from implicitly unwrapped optionals
3771+
// for Swift versions less than 5.
3772+
if (!TC.Context.isSwiftVersionAtLeast(5) &&
3773+
hasImplicitlyUnwrappedResult(subExpr))
3774+
return;
3775+
37373776
// We're taking the source type from the child of any BindOptionalExprs,
37383777
// and the destination from the parent of any
37393778
// (InjectIntoOptional/OptionalEvaluation)Exprs in order to take into

test/ClangImporter/objc_parse.swift

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -247,27 +247,18 @@ func almostSubscriptableValueMismatch(_ as1: AlmostSubscriptable, a: A) {
247247
func almostSubscriptableKeyMismatch(_ bc: BadCollection, key: NSString) {
248248
// FIXME: We end up importing this as read-only due to the mismatch between
249249
// getter/setter element types.
250-
var _ : Any = bc[key] // expected-warning {{expression implicitly coerced from 'Any?' to 'Any'}}
251-
// expected-note@-1 {{force-unwrap the value to avoid this warning}}
252-
// expected-note@-2 {{provide a default value to avoid this warning}}
253-
// expected-note@-3 {{explicitly cast to 'Any' with 'as Any' to silence this warning}}
250+
var _ : Any = bc[key]
254251
}
255252

256253
func almostSubscriptableKeyMismatchInherited(_ bc: BadCollectionChild,
257254
key: String) {
258-
var value : Any = bc[key] // expected-warning {{expression implicitly coerced from 'Any?' to 'Any'}}
259-
// expected-note@-1 {{force-unwrap the value to avoid this warning}}
260-
// expected-note@-2 {{provide a default value to avoid this warning}}
261-
// expected-note@-3 {{explicitly cast to 'Any' with 'as Any' to silence this warning}}
255+
var value : Any = bc[key]
262256
bc[key] = value // expected-error{{cannot assign through subscript: subscript is get-only}}
263257
}
264258

265259
func almostSubscriptableKeyMismatchInherited(_ roc: ReadOnlyCollectionChild,
266260
key: String) {
267-
var value : Any = roc[key] // expected-warning {{expression implicitly coerced from 'Any?' to 'Any'}}
268-
// expected-note@-1 {{force-unwrap the value to avoid this warning}}
269-
// expected-note@-2 {{provide a default value to avoid this warning}}
270-
// expected-note@-3 {{explicitly cast to 'Any' with 'as Any' to silence this warning}}
261+
var value : Any = roc[key]
271262
roc[key] = value // expected-error{{cannot assign through subscript: subscript is get-only}}
272263
}
273264

@@ -407,22 +398,10 @@ func testPropertyAndMethodCollision(_ obj: PropertyAndMethodCollision,
407398
type(of: rev).classRef(rev, doSomething:#selector(getter: NSMenuItem.action))
408399

409400
var value: Any
410-
value = obj.protoProp() // expected-warning {{expression implicitly coerced from 'Any?' to 'Any'}}
411-
// expected-note@-1 {{force-unwrap the value to avoid this warning}}
412-
// expected-note@-2 {{provide a default value to avoid this warning}}
413-
// expected-note@-3 {{explicitly cast to 'Any' with 'as Any' to silence this warning}}
414-
value = obj.protoPropRO() // expected-warning {{expression implicitly coerced from 'Any?' to 'Any'}}
415-
// expected-note@-1 {{force-unwrap the value to avoid this warning}}
416-
// expected-note@-2 {{provide a default value to avoid this warning}}
417-
// expected-note@-3 {{explicitly cast to 'Any' with 'as Any' to silence this warning}}
418-
value = type(of: obj).protoClassProp() // expected-warning {{expression implicitly coerced from 'Any?' to 'Any'}}
419-
// expected-note@-1 {{force-unwrap the value to avoid this warning}}
420-
// expected-note@-2 {{provide a default value to avoid this warning}}
421-
// expected-note@-3 {{explicitly cast to 'Any' with 'as Any' to silence this warning}}
422-
value = type(of: obj).protoClassPropRO() // expected-warning {{expression implicitly coerced from 'Any?' to 'Any'}}
423-
// expected-note@-1 {{force-unwrap the value to avoid this warning}}
424-
// expected-note@-2 {{provide a default value to avoid this warning}}
425-
// expected-note@-3 {{explicitly cast to 'Any' with 'as Any' to silence this warning}}
401+
value = obj.protoProp()
402+
value = obj.protoPropRO()
403+
value = type(of: obj).protoClassProp()
404+
value = type(of: obj).protoClassPropRO()
426405
_ = value
427406
}
428407

test/Constraints/casts_objc.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,7 @@ func nsobject_as_class_cast<T>(_ x: NSObject, _: T) {
3434
func test(_ a : CFString!, b : CFString) {
3535
let dict = NSMutableDictionary()
3636
let object = NSObject()
37-
dict[a] = object // expected-warning {{expression implicitly coerced from 'CFString?' to 'Any'}}
38-
// expected-note@-1 {{force-unwrap the value to avoid this warning}}
39-
// expected-note@-2 {{provide a default value to avoid this warning}}
40-
// expected-note@-3 {{explicitly cast to 'Any' with 'as Any' to silence this warning}}
41-
42-
37+
dict[a] = object
4338
dict[b] = object
4439
}
4540

test/Constraints/diag_ambiguities.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ struct SR3715 {
5151
func take(_ a: [Any]) {}
5252

5353
func test() {
54-
take([overloaded]) // expected-warning {{expression implicitly coerced from 'Int?' to 'Any'}}
55-
// expected-note@-1 {{force-unwrap the value to avoid this warning}}
56-
// expected-note@-2 {{provide a default value to avoid this warning}}
57-
// expected-note@-3 {{explicitly cast to 'Any' with 'as Any' to silence this warning}}
54+
take([overloaded])
5855
}
5956
}
6057

test/Constraints/existential_metatypes.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,5 @@ func testP3(_ p: P3, something: Something) {
8787
}
8888

8989
func testIUOToAny(_ t: AnyObject.Type!) {
90-
let _: Any = t // expected-warning {{expression implicitly coerced from 'AnyObject.Type?' to 'Any'}}
91-
// expected-note@-1 {{force-unwrap the value to avoid this warning}}
92-
// expected-note@-2 {{provide a default value to avoid this warning}}
93-
// expected-note@-3 {{explicitly cast to 'Any' with 'as Any' to silence this warning}}
90+
let _: Any = t
9491
}

test/Sema/diag_unintended_optional_behavior.swift

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -82,34 +82,42 @@ func warnNestedOptionalToOptionalAnyCoercion(_ a: Int?, _ b: Any??, _ c: Int???,
8282
takesOptionalAny(c as Any?, d as Any?)
8383
}
8484

85-
func warnIUOToAnyCoercion(_ a: Int!, _ b: Any?!) {
86-
_ = takeAny(a, b) // expected-warning {{expression implicitly coerced from 'Int?' to 'Any'}}
87-
// expected-note@-1 {{provide a default value to avoid this warning}}{{16-16= ?? <#default value#>}}
88-
// expected-note@-2 {{force-unwrap the value to avoid this warning}}{{16-16=!}}
89-
// expected-note@-3 {{explicitly cast to 'Any' with 'as Any' to silence this warning}}{{16-16= as Any}}
90-
// expected-warning@-4 {{expression implicitly coerced from 'Any??' to 'Any'}}
91-
// expected-note@-5 {{force-unwrap the value to avoid this warning}}{{19-19=!!}}
92-
// expected-note@-6 {{explicitly cast to 'Any' with 'as Any' to silence this warning}}{{19-19= as Any}}
85+
class C {
86+
var a: Int!
87+
var b: Any?!
88+
func returningIUO() -> Int! { return a }
89+
func returningAny() -> Any { return a }
90+
91+
subscript(i: Int) -> Int! { return 0 }
92+
subscript(i: Float) -> Any! { return 0 }
93+
}
94+
95+
class D {
96+
init!() {}
97+
}
98+
99+
func returningIUO() -> Int! { return 1 }
100+
101+
// No warnings in Swift 3/4 for IUO-to-Any coercion.
102+
func nowarnIUOToAnyCoercion(_ a: Int!, _ b: Any?!) {
103+
_ = takeAny(a, b)
104+
_ = takeAny(returningIUO(), C().returningIUO())
105+
_ = takeAny(C().a, C().b)
106+
_ = takeAny(C()[0], C()[1.0])
107+
_ = takeAny(D(), D())
93108

94109
_ = takeAny(a as Any, b as Any)
95110
}
96111

97-
func warnIUOToOptionalAnyCoercion(_ a: Int!, _ b: Any?!, _ c: Int??!, _ d: Any???!) {
98-
takesOptionalAny(a, b) // expected-warning {{expression implicitly coerced from 'Any??' to 'Any?'}}
99-
// expected-note@-1 {{provide a default value to avoid this warning}}{{24-24= ?? <#default value#>}}
100-
// expected-note@-2 {{force-unwrap the value to avoid this warning}}{{24-24=!}}
101-
// expected-note@-3 {{explicitly cast to 'Any?' with 'as Any?' to silence this warning}}{{24-24= as Any?}}
112+
// No warnings in Swift 3/4 for IUO-to-Any coercion.
113+
func nowarnIUOToOptionalAnyCoercion(_ a: Int!, _ b: Any?!, _ c: Int??!, _ d: Any???!) {
114+
takesOptionalAny(a, b)
102115

103116
takesOptionalAny(a, b ?? "")
104117
takesOptionalAny(a, b!)
105118
takesOptionalAny(a, b as Any?)
106119

107-
takesOptionalAny(c, d) // expected-warning {{expression implicitly coerced from 'Int???' to 'Any?'}}
108-
// expected-note@-1 {{force-unwrap the value to avoid this warning}}{{21-21=!!}}
109-
// expected-note@-2 {{explicitly cast to 'Any?' with 'as Any?' to silence this warning}}{{21-21= as Any?}}
110-
// expected-warning@-3 {{expression implicitly coerced from 'Any????' to 'Any?'}}
111-
// expected-note@-4 {{force-unwrap the value to avoid this warning}}{{24-24=!!!}}
112-
// expected-note@-5 {{explicitly cast to 'Any?' with 'as Any?' to silence this warning}}{{24-24= as Any?}}
120+
takesOptionalAny(c, d)
113121

114122
takesOptionalAny(c!!, d!!!)
115123
takesOptionalAny(c as Any?, d as Any?)
@@ -146,10 +154,22 @@ func warnCollectionOfOptionalToAnyCoercion(_ a: [Int?], _ d: [String : Int?]) {
146154
// expected-note@-1 {{explicitly cast to '[Any]' with 'as [Any]' to silence this warning}}{{25-25= as [Any]}}
147155
// expected-warning@-2 {{expression implicitly coerced from '[String : Int?]' to '[String : Any]'}}
148156
// expected-note@-3 {{explicitly cast to '[String : Any]' with 'as [String : Any]' to silence this warning}}{{28-28= as [String : Any]}}
157+
takesCollectionOfAny([a[0]], ["test" : a[0]]) // expected-warning {{expression implicitly coerced from 'Int?' to 'Any'}}
158+
// expected-note@-1 {{provide a default value to avoid this warning}}{{29-29= ?? <#default value#>}}
159+
// expected-note@-2 {{force-unwrap the value to avoid this warning}}{{29-29=!}}
160+
// expected-note@-3 {{explicitly cast to 'Any' with 'as Any' to silence this warning}}{{29-29= as Any}}
161+
// expected-warning@-4 {{expression implicitly coerced from 'Int?' to 'Any'}}
162+
// expected-note@-5 {{provide a default value to avoid this warning}}{{46-46= ?? <#default value#>}}
163+
// expected-note@-6 {{force-unwrap the value to avoid this warning}}{{46-46=!}}
164+
// expected-note@-7 {{explicitly cast to 'Any' with 'as Any' to silence this warning}}{{46-46= as Any}}
149165

150166
takesCollectionOfAny(a as [Any], d as [String : Any])
151167
}
152168

169+
func nowarnCollectionOfIUOToAnyCoercion(_ a: Int!) {
170+
takesCollectionOfAny([a], ["test" : a])
171+
}
172+
153173
func warnCollectionOfTripleOptionalToAnyCoercion(_ a: [Any???], _ d: [String: Any???]) {
154174
takesCollectionOfAny(a, d) // expected-warning {{expression implicitly coerced from '[Any???]' to '[Any]'}}
155175
// expected-note@-1 {{explicitly cast to '[Any]' with 'as [Any]' to silence this warning}}{{25-25= as [Any]}}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// RUN: %target-typecheck-verify-swift -swift-version 5
2+
3+
// Additional warnings produced in Swift 5+ mode.
4+
5+
func takeAny(_ left: Any, _ right: Any) -> Int? {
6+
return left as? Int
7+
}
8+
9+
func takesOptionalAny(_: Any?, _: Any?) {}
10+
11+
class C {
12+
var a: Int!
13+
var b: Any?!
14+
func returningIUO() -> Int! { return a }
15+
func returningAny() -> Any { return a } // expected-warning {{expression implicitly coerced from 'Int?' to 'Any'}}
16+
// expected-note@-1 {{provide a default value to avoid this warning}}{{40-40= ?? <#default value#>}}
17+
// expected-note@-2 {{force-unwrap the value to avoid this warning}}{{40-40=!}}
18+
// expected-note@-3 {{explicitly cast to 'Any' with 'as Any' to silence this warning}}{{40-40= as Any}}
19+
20+
subscript(i: Int) -> Int! { return 0 }
21+
subscript(i: Float) -> Any! { return 0 }
22+
}
23+
24+
class D {
25+
init!() {}
26+
}
27+
28+
func returningIUO() -> Int! { return 1 }
29+
30+
func warnIUOToAnyCoercion(_ a: Int!, _ b: Any?!) {
31+
_ = takeAny(a, b) // expected-warning {{expression implicitly coerced from 'Int?' to 'Any'}}
32+
// expected-note@-1 {{provide a default value to avoid this warning}}{{16-16= ?? <#default value#>}}
33+
// expected-note@-2 {{force-unwrap the value to avoid this warning}}{{16-16=!}}
34+
// expected-note@-3 {{explicitly cast to 'Any' with 'as Any' to silence this warning}}{{16-16= as Any}}
35+
// expected-warning@-4 {{expression implicitly coerced from 'Any??' to 'Any'}}
36+
// expected-note@-5 {{force-unwrap the value to avoid this warning}}{{19-19=!!}}
37+
// expected-note@-6 {{explicitly cast to 'Any' with 'as Any' to silence this warning}}{{19-19= as Any}}
38+
_ = takeAny(returningIUO(), C().returningIUO()) // expected-warning {{expression implicitly coerced from 'Int?' to 'Any'}}
39+
// expected-note@-1 {{provide a default value to avoid this warning}}{{29-29= ?? <#default value#>}}
40+
// expected-note@-2 {{force-unwrap the value to avoid this warning}}{{29-29=!}}
41+
// expected-note@-3 {{explicitly cast to 'Any' with 'as Any' to silence this warning}}{{29-29= as Any}}
42+
// expected-warning@-4 {{expression implicitly coerced from 'Int?' to 'Any'}}
43+
// expected-note@-5 {{provide a default value to avoid this warning}}{{49-49= ?? <#default value#>}}
44+
// expected-note@-6 {{force-unwrap the value to avoid this warning}}{{49-49=!}}
45+
// expected-note@-7 {{explicitly cast to 'Any' with 'as Any' to silence this warning}}{{49-49= as Any}}
46+
_ = takeAny(C().a, C().b) // expected-warning {{expression implicitly coerced from 'Int?' to 'Any'}}
47+
// expected-note@-1 {{provide a default value to avoid this warning}}{{20-20= ?? <#default value#>}}
48+
// expected-note@-2 {{force-unwrap the value to avoid this warning}}{{20-20=!}}
49+
// expected-note@-3 {{explicitly cast to 'Any' with 'as Any' to silence this warning}}{{20-20= as Any}}
50+
// expected-warning@-4 {{expression implicitly coerced from 'Any??' to 'Any'}}
51+
// expected-note@-5 {{force-unwrap the value to avoid this warning}}{{27-27=!!}}
52+
// expected-note@-6 {{explicitly cast to 'Any' with 'as Any' to silence this warning}}{{27-27= as Any}}
53+
_ = takeAny(C()[0], C()[1.0]) // expected-warning {{expression implicitly coerced from 'Int?' to 'Any'}}
54+
// expected-note@-1 {{provide a default value to avoid this warning}}{{21-21= ?? <#default value#>}}
55+
// expected-note@-2 {{force-unwrap the value to avoid this warning}}{{21-21=!}}
56+
// expected-note@-3 {{explicitly cast to 'Any' with 'as Any' to silence this warning}}{{21-21= as Any}}
57+
// expected-warning@-4 {{expression implicitly coerced from 'Any?' to 'Any'}}
58+
// expected-note@-5 {{provide a default value to avoid this warning}}{{31-31= ?? <#default value#>}}
59+
// expected-note@-6 {{force-unwrap the value to avoid this warning}}{{31-31=!}}
60+
// expected-note@-7 {{explicitly cast to 'Any' with 'as Any' to silence this warning}}{{31-31= as Any}}
61+
_ = takeAny(D(), D()) // expected-warning {{expression implicitly coerced from 'D?' to 'Any'}}
62+
// expected-note@-1 {{provide a default value to avoid this warning}}{{18-18= ?? <#default value#>}}
63+
// expected-note@-2 {{force-unwrap the value to avoid this warning}}{{18-18=!}}
64+
// expected-note@-3 {{explicitly cast to 'Any' with 'as Any' to silence this warning}}{{18-18= as Any}}
65+
// expected-warning@-4 {{expression implicitly coerced from 'D?' to 'Any'}}
66+
// expected-note@-5 {{provide a default value to avoid this warning}}{{23-23= ?? <#default value#>}}
67+
// expected-note@-6 {{force-unwrap the value to avoid this warning}}{{23-23=!}}
68+
// expected-note@-7 {{explicitly cast to 'Any' with 'as Any' to silence this warning}}{{23-23= as Any}}
69+
70+
_ = takeAny(a as Any, b as Any)
71+
}
72+
73+
func warnIUOToOptionalAnyCoercion(_ a: Int!, _ b: Any?!, _ c: Int??!, _ d: Any???!) {
74+
takesOptionalAny(a, b) // expected-warning {{expression implicitly coerced from 'Any??' to 'Any?'}}
75+
// expected-note@-1 {{provide a default value to avoid this warning}}{{24-24= ?? <#default value#>}}
76+
// expected-note@-2 {{force-unwrap the value to avoid this warning}}{{24-24=!}}
77+
// expected-note@-3 {{explicitly cast to 'Any?' with 'as Any?' to silence this warning}}{{24-24= as Any?}}
78+
79+
takesOptionalAny(a, b ?? "")
80+
takesOptionalAny(a, b!)
81+
takesOptionalAny(a, b as Any?)
82+
83+
takesOptionalAny(c, d) // expected-warning {{expression implicitly coerced from 'Int???' to 'Any?'}}
84+
// expected-note@-1 {{force-unwrap the value to avoid this warning}}{{21-21=!!}}
85+
// expected-note@-2 {{explicitly cast to 'Any?' with 'as Any?' to silence this warning}}{{21-21= as Any?}}
86+
// expected-warning@-3 {{expression implicitly coerced from 'Any????' to 'Any?'}}
87+
// expected-note@-4 {{force-unwrap the value to avoid this warning}}{{24-24=!!!}}
88+
// expected-note@-5 {{explicitly cast to 'Any?' with 'as Any?' to silence this warning}}{{24-24= as Any?}}
89+
90+
takesOptionalAny(c!!, d!!!)
91+
takesOptionalAny(c as Any?, d as Any?)
92+
}
93+
94+
func takesCollectionOfAny(_ a: [Any], _ d: [String : Any]) {}
95+
96+
func warnCollectionOfIUOToAnyCoercion(_ a: Int!) {
97+
takesCollectionOfAny([a], ["test" : a]) // expected-warning {{expression implicitly coerced from 'Int?' to 'Any'}}
98+
// expected-note@-1 {{provide a default value to avoid this warning}}{{26-26= ?? <#default value#>}}
99+
// expected-note@-2 {{force-unwrap the value to avoid this warning}}{{26-26=!}}
100+
// expected-note@-3 {{explicitly cast to 'Any' with 'as Any' to silence this warning}}{{26-26= as Any}}
101+
// expected-warning@-4 {{expression implicitly coerced from 'Int?' to 'Any'}}
102+
// expected-note@-5 {{provide a default value to avoid this warning}}{{40-40= ?? <#default value#>}}
103+
// expected-note@-6 {{force-unwrap the value to avoid this warning}}{{40-40=!}}
104+
// expected-note@-7 {{explicitly cast to 'Any' with 'as Any' to silence this warning}}{{40-40= as Any}}
105+
}

0 commit comments

Comments
 (0)