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
Copy file name to clipboardExpand all lines: test/Sema/placeholder_type.swift
+25-13Lines changed: 25 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,10 @@
1
1
// RUN: %target-typecheck-verify-swift
2
2
3
-
letx:_=0
3
+
letx:_=0 // expected-error {{placeholder type may not appear as type of a variable}} expected-note {{replace the placeholder with the inferred type 'Int'}} {{8-9=Int}}
4
4
letx2= x
5
+
varx3:_{ // expected-error {{type placeholder not allowed here}}
6
+
get{42}
7
+
}
5
8
letdict1:[_:Int]=["hi":0]
6
9
letdict2:[Character:_]=["h":0]
7
10
@@ -112,10 +115,10 @@ let _: () -> Int = { _() } // expected-error 2 {{type placeholder not allowed he
112
115
let _:Int= _.init() // expected-error {{type placeholder not allowed here}} expected-error {{could not infer type for placeholder}}
113
116
let _:()->Int={ _.init()} // expected-error 2 {{type placeholder not allowed here}} expected-error {{could not infer type for placeholder}}
114
117
115
-
func returnsInt()->Int{_()} // expected-error {{type of expression is ambiguous without more context}}
116
-
func returnsIntClosure()->()->Int{{_()}} // expected-error {{unable to infer closure type in the current context}}
117
-
func returnsInt2()->Int{ _.init()} // expected-error {{could not infer type for placeholder}}
118
-
func returnsIntClosure2()->()->Int{{ _.init()}} // expected-error {{could not infer type for placeholder}}
118
+
func returnsInt()->Int{_()} // expected-error {{type placeholder not allowed here}} expected-error {{type of expression is ambiguous without more context}}
119
+
func returnsIntClosure()->()->Int{{_()}} // expected-error 2 {{type placeholder not allowed here}} expected-error {{unable to infer closure type in the current context}}
120
+
func returnsInt2()->Int{ _.init()} // expected-error {{type placeholder not allowed here}} expected-error {{could not infer type for placeholder}}
121
+
func returnsIntClosure2()->()->Int{{ _.init()}} // expected-error 2 {{type placeholder not allowed here}} expected-error {{could not infer type for placeholder}}
119
122
120
123
let _:Int.Type= _ // expected-error {{'_' can only appear in a pattern or on the left side of an assignment}}
121
124
let _:Int.Type= _.self // expected-error {{type placeholder not allowed here}}
@@ -144,13 +147,13 @@ let _ = [_].otherStaticMember.method()
144
147
func f(x:Any, arr:[Int]){
145
148
// FIXME: Better diagnostics here. Maybe we should suggest replacing placeholders with 'Any'?
146
149
147
-
if x is _{} // expected-error {{type of expression is ambiguous without more context}}
150
+
if x is _{} // expected-error {{type placeholder not allowed here}} expected-error {{type of expression is ambiguous without more context}}
148
151
if x is [_]{} // expected-error {{type of expression is ambiguous without more context}}
149
152
if x is ()->_{} // expected-error {{type of expression is ambiguous without more context}}
150
-
iflet y = x as?_{} // expected-error {{type of expression is ambiguous without more context}}
153
+
iflet y = x as?_{} // expected-error {{type placeholder not allowed here}} expected-error {{type of expression is ambiguous without more context}}
151
154
iflet y = x as?[_]{} // expected-error {{type of expression is ambiguous without more context}}
152
155
iflet y = x as?()->_{} // expected-error {{type of expression is ambiguous without more context}}
153
-
lety1= x as!_ // expected-error {{type of expression is ambiguous without more context}}
156
+
lety1= x as!_ // expected-error {{type placeholder not allowed here}} expected-error {{type of expression is ambiguous without more context}}
154
157
lety2= x as![_] // expected-error {{type of expression is ambiguous without more context}}
155
158
lety3= x as!()->_ // expected-error {{type of expression is ambiguous without more context}}
// TODO: Better error message here? Would be nice if we could point to the placeholder...
209
212
let _:SetFailureType<Int,String>=Just<Int>().setFailureType(to: _.self).setFailureType(to:String.self) // expected-error {{type placeholder not allowed here}} expected-error {{generic parameter 'T' could not be inferred}}
210
213
211
-
let _:(_)=0asInt
212
-
let _:Int=0as(_)
214
+
let _:(_)=0asInt // expected-error {{placeholder type may not appear as type of a variable}} expected-note {{replace the placeholder with the inferred type 'Int'}} {{9-10=Int}}
215
+
let _:Int=0as(_) // expected-error {{type placeholder not allowed here}}
216
+
let _:Int=0as(((((_))))) // expected-error {{type placeholder not allowed here}}
213
217
214
218
_ =(1...10)
215
219
.map{
@@ -254,3 +258,11 @@ enum EnumWithPlaceholders {
254
258
// expected-note@-1 {{replace the placeholder with the inferred type 'Int'}}
255
259
}
256
260
261
+
func deferredInit(_ c:Bool){
262
+
letx:_ // expected-error {{type placeholder not allowed here}}
0 commit comments