Files
swift-mirror/test/Interpreter/algorithms.swift
Doug Gregor 3805e18090 Explicitly track the mapping from dependent types to their opened type variables.
Previously, we were reconstructing this mapping from the "full" opened
type produced by declaration references. However, when dealing with
same-type constraints between associated types and type parameters, we
could end up with an incomplete mapping, which let archetypes slip
through. Most of the churn here is sorting out the locators we need to
use to find the opened-type information. Fixes rdar://problem/18208283
and at least 3 dupes of it that I've found so far.

Swift SVN r25375
2015-02-18 19:41:40 +00:00

43 lines
949 B
Swift

// RUN: %target-run-simple-swift | FileCheck %s
func fib() {
var (a, b) = (0, 1)
while b < 10 {
println(b)
(a, b) = (b, a+b)
}
}
fib()
// CHECK: 1
// CHECK: 1
// CHECK: 2
// CHECK: 3
// CHECK: 5
// CHECK: 8
// From: <rdar://problem/17796401>
let two_one = Array(lazy([1, 2, 3, 4]).reverse().filter { $0 % 2 == 0 }.map { $0 / 2 })
println(two_one)
// CHECK: [2, 1]
// rdar://problem/18208283
func flatten<Element, Sequence: SequenceType, InnerSequence: SequenceType
where Sequence.Generator.Element == InnerSequence, InnerSequence.Generator.Element == Element> (outerSequence: Sequence) -> [Element] {
var result = [Element]()
for innerSequence in outerSequence {
result.extend(innerSequence)
}
return result
}
// CHECK: [1, 2, 3, 4, 5, 6]
let flat = flatten([[1,2,3], [4,5,6]])
println(flat)
// rdar://problem/19416848
func observe<T:SequenceType, V where V == T.Generator.Element>(g:T) { }
observe(["a":1])