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
[Parse] Recover slightly better from bad shorthand if let
Instead of assuming that `if let <expr>` is meant
to be `if case <expr> = ...`, turn it into
`if let _ = <expr>`, which is consistent with
the fix-it we suggest.
This currently doesn't have much of an effect on
the diagnostics we produce, but will be important
once we start doing bidirectional inference for
ExprPatterns, as it avoids unhelpful diagnostics.
Copy file name to clipboardExpand all lines: test/stmt/if_while_var.swift
+12-3Lines changed: 12 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -42,8 +42,13 @@ if var nonOptional { nonOptional = nonOptionalStruct(); _ = nonOptional } // exp
42
42
guardlet nonOptional else{ _ = nonOptional; fatalError()} // expected-error{{initializer for conditional binding must have Optional type, not 'NonOptionalStruct'}}
43
43
guardvar nonOptional else{ _ = nonOptional; fatalError()} // expected-error{{initializer for conditional binding must have Optional type, not 'NonOptionalStruct'}}
44
44
45
-
ifletnonOptional.property {} // expected-error{{unwrap condition requires a valid identifier}} expected-error{{pattern matching in a condition requires the 'case' keyword}}
46
-
ifvarnonOptional.property {} // expected-error{{unwrap condition requires a valid identifier}} expected-error{{pattern matching in a condition requires the 'case' keyword}}
45
+
ifletnonOptional.property {}
46
+
// expected-error@-1 {{unwrap condition requires a valid identifier}}
47
+
// expected-error@-2 {{initializer for conditional binding must have Optional type, not 'Any'}}
48
+
49
+
ifvarnonOptional.property {}
50
+
// expected-error@-1 {{unwrap condition requires a valid identifier}}
51
+
// expected-error@-2 {{initializer for conditional binding must have Optional type, not 'Any'}}
47
52
48
53
guardlet _ =nonOptionalStruct()else{fatalError()} // expected-error{{initializer for conditional binding must have Optional type, not 'NonOptionalStruct'}}
49
54
guardlet _ =nonOptionalEnum()else{fatalError()} // expected-error{{initializer for conditional binding must have Optional type, not 'NonOptionalEnum'}}
@@ -65,7 +70,11 @@ class B {} // expected-note * {{did you mean 'B'?}}
65
70
classD:B{}// expected-note * {{did you mean 'D'?}}
66
71
67
72
// TODO poor recovery in these cases
68
-
iflet{} // expected-error {{expected '{' after 'if' condition}} expected-error {{pattern matching in a condition requires the 'case' keyword}} expected-error {{unwrap condition requires a valid identifier}}
73
+
iflet{}
74
+
// expected-error@-1 {{expected '{' after 'if' condition}}
75
+
// expected-error@-2 {{unwrap condition requires a valid identifier}}
76
+
// expected-error@-3 {{initializer for conditional binding must have Optional type, not '() -> ()'}}
77
+
69
78
iflet x ={} // expected-error{{'{' after 'if'}} expected-error{{initializer for conditional binding must have Optional type, not '() -> ()'}}
70
79
// expected-warning@-1{{value 'x' was defined but never used}}
0 commit comments