mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
coercion. Overload resolution uses this argument deduction when
dealing with generic functions, to determine when we can invoke a
generic function. When a generic function is selected, we create a
SpecializeExpr wrapping the DeclRefExpr to the generic function.
This is sufficient to type-check calls to simple things like a call to
func identity<T>(x : T) -> T { return x }
with a value of known type. However, it's missing far too many pieces
to enumerate.
Swift SVN r2230
31 lines
858 B
Swift
31 lines
858 B
Swift
// RUN: %swift %s -verify
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// Deduction of generic arguments
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
func identity<T>(value : T) -> T { return value }
|
|
|
|
func useIdentity(x : Int, y : Float, i32 : Int32) {
|
|
x = identity(x)
|
|
y = identity(y)
|
|
|
|
// FIXME: These need much smarter deduction.
|
|
// x = identity(17)
|
|
// i32 = identity(17)
|
|
}
|
|
|
|
// FIXME: Crummy diagnostic!
|
|
func twoIdentical<T>(x : T, y : T) -> T {} // expected-note{{found this candidate}}
|
|
|
|
func useTwoIdentical(x : Int, y : Float, i32 : Int32) {
|
|
x = twoIdentical(x, x)
|
|
y = twoIdentical(y, y)
|
|
x = twoIdentical(x, 1)
|
|
x = twoIdentical(1, x)
|
|
y = twoIdentical(1.0, y)
|
|
y = twoIdentical(y, 1.0)
|
|
|
|
twoIdentical(x, y) // expected-error{{no candidates found for call}}
|
|
}
|