Skip to content

Commit 416cb7f

Browse files
committed
[Sema] Update Optional-to-Any tests for swiftlang#14299
As IUOs types are no longer generated, we don't show them in diagnostics.
1 parent 7d3785a commit 416cb7f

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3524,11 +3524,6 @@ static void diagnoseUnintendedOptionalBehavior(TypeChecker &TC, const Expr *E,
35243524
}
35253525

35263526
void emitSilenceOptionalAnyWarningWithCoercion(Expr *E, Type destType) {
3527-
// Treat an IUO destination type as a regular Optional type, as we cannot
3528-
// suggest a fix-it of e.g 'as Any!'.
3529-
if (auto baseType = destType->getImplicitlyUnwrappedOptionalObjectType())
3530-
destType = OptionalType::get(baseType);
3531-
35323527
SmallString<16> coercionString;
35333528
coercionString += " as ";
35343529
coercionString += destType->getWithoutParens()->getString();

test/Sema/diag_unintended_optional_behavior.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,19 @@ func warnNestedOptionalToOptionalAnyCoercion(_ a: Int?, _ b: Any??, _ c: Int???,
8383
}
8484

8585
func warnIUOToAnyCoercion(_ a: Int!, _ b: Any?!) {
86-
_ = takeAny(a, b) // expected-warning {{expression implicitly coerced from 'Int!' to 'Any'}}
86+
_ = takeAny(a, b) // expected-warning {{expression implicitly coerced from 'Int?' to 'Any'}}
8787
// expected-note@-1 {{provide a default value to avoid this warning}}{{16-16= ?? <#default value#>}}
8888
// expected-note@-2 {{force-unwrap the value to avoid this warning}}{{16-16=!}}
8989
// 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'}}
90+
// expected-warning@-4 {{expression implicitly coerced from 'Any??' to 'Any'}}
9191
// expected-note@-5 {{force-unwrap the value to avoid this warning}}{{19-19=!!}}
9292
// expected-note@-6 {{explicitly cast to 'Any' with 'as Any' to silence this warning}}{{19-19= as Any}}
9393

9494
_ = takeAny(a as Any, b as Any)
9595
}
9696

9797
func warnIUOToOptionalAnyCoercion(_ a: Int!, _ b: Any?!, _ c: Int??!, _ d: Any???!) {
98-
takesOptionalAny(a, b) // expected-warning {{expression implicitly coerced from 'Any?!' to 'Any?'}}
98+
takesOptionalAny(a, b) // expected-warning {{expression implicitly coerced from 'Any??' to 'Any?'}}
9999
// expected-note@-1 {{provide a default value to avoid this warning}}{{24-24= ?? <#default value#>}}
100100
// expected-note@-2 {{force-unwrap the value to avoid this warning}}{{24-24=!}}
101101
// expected-note@-3 {{explicitly cast to 'Any?' with 'as Any?' to silence this warning}}{{24-24= as Any?}}
@@ -104,10 +104,10 @@ func warnIUOToOptionalAnyCoercion(_ a: Int!, _ b: Any?!, _ c: Int??!, _ d: Any??
104104
takesOptionalAny(a, b!)
105105
takesOptionalAny(a, b as Any?)
106106

107-
takesOptionalAny(c, d) // expected-warning {{expression implicitly coerced from 'Int??!' to 'Any?'}}
107+
takesOptionalAny(c, d) // expected-warning {{expression implicitly coerced from 'Int???' to 'Any?'}}
108108
// expected-note@-1 {{force-unwrap the value to avoid this warning}}{{21-21=!!}}
109109
// 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?'}}
110+
// expected-warning@-3 {{expression implicitly coerced from 'Any????' to 'Any?'}}
111111
// expected-note@-4 {{force-unwrap the value to avoid this warning}}{{24-24=!!!}}
112112
// expected-note@-5 {{explicitly cast to 'Any?' with 'as Any?' to silence this warning}}{{24-24= as Any?}}
113113

@@ -118,7 +118,7 @@ func warnIUOToOptionalAnyCoercion(_ a: Int!, _ b: Any?!, _ c: Int??!, _ d: Any??
118118
func takesIUO(_: Any!, _: Any!) {}
119119

120120
func warnOptionalToIUOAny(_ a: Int?, _ b: Any??, _ c: Int???, _ d: Any????) {
121-
takesIUO(a, b) // expected-warning {{expression implicitly coerced from 'Any??' to 'Any!'}}
121+
takesIUO(a, b) // expected-warning {{expression implicitly coerced from 'Any??' to 'Any?'}}
122122
// expected-note@-1 {{provide a default value to avoid this warning}}{{16-16= ?? <#default value#>}}
123123
// expected-note@-2 {{force-unwrap the value to avoid this warning}}{{16-16=!}}
124124
// expected-note@-3 {{explicitly cast to 'Any?' with 'as Any?' to silence this warning}}{{16-16= as Any?}}
@@ -127,10 +127,10 @@ func warnOptionalToIUOAny(_ a: Int?, _ b: Any??, _ c: Int???, _ d: Any????) {
127127
takesIUO(a, b!)
128128
takesIUO(a, b as Any?)
129129

130-
takesIUO(c, d) // expected-warning {{expression implicitly coerced from 'Int???' to 'Any!'}}
130+
takesIUO(c, d) // expected-warning {{expression implicitly coerced from 'Int???' to 'Any?'}}
131131
// expected-note@-1 {{force-unwrap the value to avoid this warning}}{{13-13=!!}}
132132
// expected-note@-2 {{explicitly cast to 'Any?' with 'as Any?' to silence this warning}}{{13-13= as Any?}}
133-
// expected-warning@-3 {{expression implicitly coerced from 'Any????' to 'Any!'}}
133+
// expected-warning@-3 {{expression implicitly coerced from 'Any????' to 'Any?'}}
134134
// expected-note@-4 {{force-unwrap the value to avoid this warning}}{{16-16=!!!}}
135135
// expected-note@-5 {{explicitly cast to 'Any?' with 'as Any?' to silence this warning}}{{16-16= as Any?}}
136136

0 commit comments

Comments
 (0)