You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve warning for inferring an undesirable type (#27797)
* [Sema][Diagnostics] Add fixit for warning when inferring an undesirable type
* [Sema][Diagnostics] Generalize undesirable type warning to include arrays of empty tuples
https://bugs.swift.org/browse/SR-11511
Copy file name to clipboardExpand all lines: test/decl/var/properties.swift
+5-5
Original file line number
Diff line number
Diff line change
@@ -1272,11 +1272,11 @@ class WeakFixItTest {
1272
1272
1273
1273
// SR-8811 (Warning)
1274
1274
1275
-
letsr8811a=fatalError() // expected-warning {{constant 'sr8811a' inferred to have type 'Never', which is an enum with no cases}} expected-note {{add an explicit type annotation to silence this warning}}
1275
+
letsr8811a=fatalError() // expected-warning {{constant 'sr8811a' inferred to have type 'Never', which is an enum with no cases}} expected-note {{add an explicit type annotation to silence this warning}} {{12-12=: Never}}
1276
1276
1277
1277
letsr8811b:Never=fatalError() // Ok
1278
1278
1279
-
letsr8811c=(16,fatalError()) // expected-warning {{constant 'sr8811c' inferred to have type '(Int, Never)', which contains an enum with no cases}} expected-note {{add an explicit type annotation to silence this warning}}
1279
+
letsr8811c=(16,fatalError()) // expected-warning {{constant 'sr8811c' inferred to have type '(Int, Never)', which contains an enum with no cases}} expected-note {{add an explicit type annotation to silence this warning}} {{12-12=: (Int, Never)}}
1280
1280
1281
1281
letsr8811d:(Int,Never)=(16,fatalError()) // Ok
1282
1282
@@ -1292,11 +1292,11 @@ class SR_10995 {
1292
1292
}
1293
1293
1294
1294
func sr_10995_foo(){
1295
-
letdoubleOptionalNever=makeDoubleOptionalNever() // expected-warning {{constant 'doubleOptionalNever' inferred to have type 'Never??', which may be unexpected}}
1296
-
// expected-note@-1 {{add an explicit type annotation to silence this warning}}
1295
+
letdoubleOptionalNever=makeDoubleOptionalNever() // expected-warning {{constant 'doubleOptionalNever' inferred to have type 'Never??', which may be unexpected}}
1296
+
// expected-note@-1 {{add an explicit type annotation to silence this warning}} {{28-28=: Never??}}
1297
1297
// expected-warning@-2 {{initialization of immutable value 'doubleOptionalNever' was never used; consider replacing with assignment to '_' or removing it}}
1298
1298
letsingleOptionalNever=makeSingleOptionalNever() // expected-warning {{constant 'singleOptionalNever' inferred to have type 'Never?', which may be unexpected}}
1299
-
// expected-note@-1 {{add an explicit type annotation to silence this warning}}
1299
+
// expected-note@-1 {{add an explicit type annotation to silence this warning}} {{28-28=: Never?}}
1300
1300
// expected-warning@-2 {{initialization of immutable value 'singleOptionalNever' was never used; consider replacing with assignment to '_' or removing it}}
// SR-11511 Warning for inferring an array of empty tuples
64
+
vararrayOfEmptyTuples=[""].map{print($0)} // expected-warning {{variable 'arrayOfEmptyTuples' inferred to have type '[()]'}} \
65
+
// expected-note {{add an explicit type annotation to silence this warning}} {{23-23=: [()]}}
66
+
67
+
varmaybeEmpty=Optional(arrayOfEmptyTuples) // expected-warning {{variable 'maybeEmpty' inferred to have type '[()]?'}} \
68
+
// expected-note {{add an explicit type annotation to silence this warning}} {{15-15=: [()]?}}
69
+
70
+
varshouldWarnWithoutSugar=(arrayOfEmptyTuples asArray<()>) // expected-warning {{variable 'shouldWarnWithoutSugar' inferred to have type 'Array<()>'}} \
71
+
// expected-note {{add an explicit type annotation to silence this warning}} {{27-27=: Array<()>}}
72
+
63
73
classSomeClass{}
64
74
65
75
// <rdar://problem/16877304> weak let's should be rejected
varpi_f3= float.init(getPi()) // expected-error {{ambiguous use of 'init(_:)'}}
589
589
varpi_f4= float.init(pi_f)
590
590
591
-
vare=Empty(f) // expected-warning {{variable 'e' inferred to have type 'Empty', which is an enum with no cases}} expected-note {{add an explicit type annotation to silence this warning}}
591
+
vare=Empty(f) // expected-warning {{variable 'e' inferred to have type 'Empty', which is an enum with no cases}} expected-note {{add an explicit type annotation to silence this warning}} {{8-8=: Empty}}
592
592
vare2=Empty(d) // expected-error{{cannot convert value of type 'Double' to expected argument type 'Float'}}
593
-
vare3=Empty(Float(d)) // expected-warning {{variable 'e3' inferred to have type 'Empty', which is an enum with no cases}} expected-note {{add an explicit type annotation to silence this warning}}
593
+
vare3=Empty(Float(d)) // expected-warning {{variable 'e3' inferred to have type 'Empty', which is an enum with no cases}} expected-note {{add an explicit type annotation to silence this warning}} {{9-9=: Empty}}
0 commit comments