mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Fixes rdar://problem/14776565 (AnyObject lookup for Objective-C
properties with custom getters) and rdar://problem/17184411 (allowing
__attribute__((swift_name("foo"))) to work on anything).
36 lines
986 B
Swift
36 lines
986 B
Swift
// RUN: %target-run-simple-swift | FileCheck %s
|
|
// REQUIRES: executable_test
|
|
|
|
// REQUIRES: objc_interop
|
|
|
|
import Foundation
|
|
|
|
// Dynamic subscripting of NSArray, dynamic method dispatch
|
|
// CHECK: {{^3$}}
|
|
var array : AnyObject = [1, 2, 3, 4, 5]
|
|
print(array[2].description)
|
|
|
|
// Dynamic subscripting on an array using an object (fails)
|
|
// CHECK: NSArray subscript with an object fails
|
|
var optVal1 = array["Hello"]
|
|
if optVal1 != nil {
|
|
print((optVal1!)!.description)
|
|
} else {
|
|
print("NSArray subscript with an object fails")
|
|
}
|
|
|
|
// Dynamic subscripting of NSDictionary, dynamic method dispatch
|
|
// CHECK: {{^2$}}
|
|
var nsdict : NSDictionary = ["Hello" : 1, "World" : 2]
|
|
var dict : AnyObject = nsdict
|
|
print((dict["World"]!)!.description)
|
|
|
|
// Dynamic subscripting on a dictionary using an index (fails)
|
|
// CHECK: NSDictionary subscript with an index fails
|
|
var optVal2 = dict[1]
|
|
if optVal2 != nil {
|
|
print(optVal2.description)
|
|
} else {
|
|
print("NSDictionary subscript with an index fails")
|
|
}
|