mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
constraint-based type checker, include the body of the explicit
closure within the set of constraints. This allows type information to
flow from the body expression, so that we can type-check, e.g.,
map(new Int[N], { $0.toString() })
to a String[] without context information. Fixes <rdar://problem/11229738>.
Swift SVN r2794
35 lines
1.1 KiB
Swift
35 lines
1.1 KiB
Swift
// RUN: %swift -repl < %s 2>&1 | FileCheck %s
|
|
|
|
func myMap<T1, T2>(array : T1[], fn : (T1) -> T2) -> T2[] {}
|
|
|
|
var intArray : Int[]
|
|
|
|
func toString<T>(x : T) -> String { }
|
|
|
|
// CHECK: Constraints:
|
|
// CHECK: (x : $T4) -> String == $T5 -> $T6
|
|
// CHECK: [byref(heap)] $T2 << $T5
|
|
// CHECK: $T6 << $T3
|
|
// CHECK: (array : $T0[], fn : $T0 -> $T1) -> $T1[] == $T7 -> $T8
|
|
// CHECK: ([byref(heap)] Int[], ($T2) -> $T3) << $T7
|
|
// CHECK: ---Child system #1---
|
|
// CHECK: Assumptions:
|
|
// CHECK: assuming $T3 == String
|
|
// CHECK: assuming $T2 == Int64
|
|
// CHECK: assuming $T4 == Int64
|
|
// CHECK: assuming $T1 == String
|
|
// CHECK: Type Variables:
|
|
// CHECK: $T0 as Int64
|
|
// CHECK: $T1 as String
|
|
// CHECK: $T2 as Int64
|
|
// CHECK: $T3 as String
|
|
// CHECK: $T4 as Int64
|
|
// CHECK: $T5 as (x : $T4)
|
|
// CHECK: $T6 as String
|
|
// CHECK: $T7 as (array : Slice<$T0>, fn : $T0 -> $T1)
|
|
// CHECK: $T8 as Slice<$T1>
|
|
// CHECK: SOLVED (completely)
|
|
// CHECK: Unique solution found.
|
|
// FIXME: Would like to use String() constructor here.
|
|
:dump_constraints myMap(intArray, { toString($0) })
|