mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
as a way to get more type information out of incorrect subexpressions. UnresolvedType
generally just propagates around the type system like a type variable:
- it magically conforms to all protocols
- it CSGens as an unconstrained type variable.
- it ASTPrints as _, just like a type variable.
The major difference is that UnresolvedType can be used outside the context of a
ConstraintSystem, which is useful for CSGen since it sets up several of them to
diagnose subexpressions w.r.t. their types.
For now, our use of this is extremely limited: when a closureexpr has no contextual
type available and its parameters are invalid, we wipe them out with UnresolvedType
(instead of the previous nulltype dance) to get ambiguities later on.
We also introduce a new FreeTypeVariableBinding::UnresolvedType approach for
constraint solving (and use this only in one place in CSDiags so far, to resolve
the callee of a CallExpr) which solves a system and rewrites any leftover type
variables as UnresolvedTypes. This allows us to get more precise information out,
for example, diagnosing:
func r22162441(lines: [String]) {
lines.map { line in line.fooBar() }
}
with: value of type 'String' has no member 'fooBar'
instead of: type of expression is ambiguous without more context
This improves a number of other diagnostics as well, but is just the infrastructural
stepping stone for greater things.
Swift SVN r31105
43 lines
991 B
Swift
43 lines
991 B
Swift
// RUN: %target-parse-verify-swift
|
|
|
|
func takeIntToInt(f: (Int) -> Int) { }
|
|
func takeIntIntToInt(f: (Int, Int) -> Int) { }
|
|
|
|
// Simple closures
|
|
func simple() {
|
|
takeIntToInt({(x: Int) -> Int in
|
|
return x + 1
|
|
})
|
|
takeIntIntToInt({(x: Int, y: Int) -> Int in
|
|
return x + y
|
|
})
|
|
}
|
|
|
|
// Closures with variadic argument lists
|
|
func variadic() {
|
|
var f = {(start: Int, rest: Int...) -> Int in
|
|
var result = start
|
|
for x in rest {
|
|
result += x
|
|
}
|
|
return result
|
|
}
|
|
f(1)
|
|
f(1, 2)
|
|
f(1, 3)
|
|
|
|
let D = { (Ss ...) in 1 } // expected-error{{'...' cannot be applied to a subpattern which is not explicitly typed}}, expected-error{{unable to infer closure type in the current context}}
|
|
}
|
|
|
|
// Closures with attributes in the parameter list.
|
|
func attrs() {
|
|
_ = {(inout z: Int) -> Int in z }
|
|
}
|
|
|
|
// Closures with argument and parameter names.
|
|
func argAndParamNames() -> Int {
|
|
let f1: (x: Int, y: Int) -> Int = { (a x, b y) in x + y }
|
|
f1(x: 1, y: 2)
|
|
return f1(x: 1, y: 2)
|
|
}
|