mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Most tests were using %swift or similar substitutions, which did not include the target triple and SDK. The driver was defaulting to the host OS. Thus, we could not run the tests when the standard library was not built for OS X. Swift SVN r24504
56 lines
1.2 KiB
Swift
56 lines
1.2 KiB
Swift
// RUN: %target-parse-verify-swift
|
|
|
|
// Simple subscript of arrays:
|
|
func simpleSubscript(array: [Float], x: Int) -> Float {
|
|
var f = array[x]
|
|
return array[x]
|
|
}
|
|
|
|
// Subscript of archetype.
|
|
protocol IntToStringSubscript {
|
|
subscript (i : Int) -> String { get }
|
|
}
|
|
|
|
class LameDictionary {
|
|
subscript (i : Int) -> String {
|
|
get {
|
|
return String(i)
|
|
}
|
|
}
|
|
}
|
|
|
|
func archetypeSubscript<T : IntToStringSubscript, U : LameDictionary>(t: T, u: U)
|
|
-> String {
|
|
// Subscript an archetype.
|
|
if false { return t[17] }
|
|
|
|
// Subscript an archetype for which the subscript operator is in a base class.
|
|
return u[17]
|
|
}
|
|
|
|
// Subscript of existential type.
|
|
func existentialSubscript(a: IntToStringSubscript) -> String {
|
|
return a[17]
|
|
}
|
|
|
|
class MyDictionary<Key, Value> {
|
|
subscript (key : Key) -> Value {
|
|
get {}
|
|
}
|
|
}
|
|
|
|
class MyStringToInt<T> : MyDictionary<String, Int> { }
|
|
|
|
// Subscript of generic type.
|
|
func genericSubscript<T>(t: T,
|
|
array: Array<Int>,
|
|
i2i: MyDictionary<Int, Int>,
|
|
t2i: MyDictionary<T, Int>,
|
|
s2i: MyStringToInt<()>) -> Int {
|
|
if true { return array[5] }
|
|
if true { return i2i[5] }
|
|
if true { return t2i[t] }
|
|
return s2i["hello"]
|
|
}
|
|
|