Skip to content

Commit d2e1c4a

Browse files
committed
Update PrintAsObjC, NameBinding, attr, decl, expr tests for id-as-Any.
1 parent cfdb957 commit d2e1c4a

File tree

9 files changed

+38
-43
lines changed

9 files changed

+38
-43
lines changed

test/NameBinding/reference-dependencies-dynamic-lookup.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ func testDynamicLookup(_ obj: AnyObject) {
5252
// CHECK-DAG: - !private "method"
5353
_ = obj.method(5, with: 5.0 as Double)
5454

55-
// CHECK-DAG: - !private "subscript"
56-
_ = obj[2] as AnyObject
57-
_ = obj[2] as AnyObject!
55+
// TODO: unable to resolve ambiguity
56+
// C/HECK-DAG: - !private "subscript"
57+
// _ = obj[2] as Any
58+
// _ = obj[2] as Any!
5859
}
5960

6061
// CHECK-DAG: - "counter"

test/PrintAsObjC/override.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class A_Child : Base {
2424
// CHECK-NEXT: @property (nonatomic, readonly, getter=getProp) NSUInteger prop;
2525
override var prop: Int { return 0 }
2626
// CHECK-NEXT: - (id _Nullable)objectAtIndexedSubscript:(NSUInteger)x;
27-
override subscript(x: Int) -> AnyObject? { return nil }
27+
override subscript(x: Int) -> Any? { return nil }
2828

2929
// CHECK-NEXT: - (NSUInteger)foo;
3030
override func foo() -> Int { return 0 }
@@ -48,7 +48,7 @@ class A_Grandchild : A_Child {
4848
// CHECK-NEXT: @property (nonatomic, readonly, getter=getProp) NSUInteger prop;
4949
override var prop: Int { return 0 }
5050
// CHECK-NEXT: - (id _Nullable)objectAtIndexedSubscript:(NSUInteger)x;
51-
override subscript(x: Int) -> AnyObject? { return nil }
51+
override subscript(x: Int) -> Any? { return nil }
5252

5353
// CHECK-NEXT: - (NSUInteger)foo;
5454
override func foo() -> Int { return 0 }
@@ -75,7 +75,7 @@ class B_GrandchildViaEmpty : B_EmptyChild {
7575

7676
// CHECK-NEXT: - (id _Nullable)objectAtIndexedSubscript:(NSUInteger)x;
7777
// CHECK-NEXT: - (void)setObject:(id _Nullable)newValue atIndexedSubscript:(NSUInteger)x;
78-
override subscript(x: Int) -> AnyObject? {
78+
override subscript(x: Int) -> Any? {
7979
get { return nil }
8080
set {}
8181
}

test/PrintAsObjC/pragma-clang.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
// CHECK: @interface Test
1919
@objc class Test : NSObject, TestProto {
2020
var str: String = ""
21-
var strongProp: AnyObject?
21+
var strongProp: Any?
2222
}
2323
// CHECK: #pragma clang diagnostic pop
2424
// CHECK-NOT: clang diagnostic

test/attr/attr_objc.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,6 @@ class infer_instanceFunc1 {
691691
// expected-note@-2 {{Swift structs cannot be represented in Objective-C}}
692692
// expected-error@-3 {{method cannot be marked @objc because the type of the parameter 2 cannot be represented in Objective-C}}
693693
// expected-note@-4 {{non-'@objc' enums cannot be represented in Objective-C}}
694-
// expected-error@-5 {{method cannot be marked @objc because its result type cannot be represented in Objective-C}}
695-
// expected-note@-6 {{'Any' is not considered '@objc'; use 'AnyObject' instead}}
696694

697695
@objc func func_UnnamedParam1(_: Int) {} // no-error
698696

@@ -971,11 +969,9 @@ class infer_instanceVar1 {
971969
// CHECK-LABEL: @objc var var_AnyObject2: AnyObject.Type
972970

973971
var var_Existential0: Any
974-
// CHECK-LABEL: {{^}} var var_Existential0: Any
972+
// CHECK-LABEL: @objc var var_Existential0: Any
975973

976974
@objc var var_Existential0_: Any
977-
// expected-error@-1 {{property cannot be marked @objc because its type cannot be represented in Objective-C}}
978-
// expected-note@-2 {{'Any' is not considered '@objc'; use 'AnyObject' instead}}
979975

980976
var var_Existential1: PlainProtocol
981977
// CHECK-LABEL: {{^}} var var_Existential1: PlainProtocol
@@ -1151,7 +1147,6 @@ class infer_instanceVar1 {
11511147
var var_Optional_fail6: PlainEnum?
11521148
var var_Optional_fail7: PlainEnum.Type?
11531149
var var_Optional_fail8: PlainProtocol?
1154-
var var_Optional_fail9: Any?
11551150
var var_Optional_fail10: PlainProtocol?
11561151
var var_Optional_fail11: (PlainProtocol & Protocol_ObjC1)?
11571152
var var_Optional_fail12: Int?
@@ -1373,10 +1368,9 @@ class infer_instanceVar1 {
13731368
// no-error
13741369

13751370
var var_ArrayType11: [Any]
1376-
// CHECK-LABEL: {{^}} var var_ArrayType11: [Any]
1371+
// CHECK-LABEL: @objc var var_ArrayType11: [Any]
13771372

13781373
@objc var var_ArrayType11_: [Any]
1379-
// expected-error @-1{{property cannot be marked @objc because its type cannot be represented in Objective-C}}
13801374

13811375
var var_ArrayType13: [Any?]
13821376
// CHECK-LABEL: {{^}} var var_ArrayType13: [Any?]

test/decl/var/NSCopying.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Foundation
66

77
class NotCopyable {}
88
class CopyableClass : NSCopying {
9-
@objc(copyWithZone:) func copy(with zone: NSZone?) -> AnyObject {
9+
@objc(copyWithZone:) func copy(with zone: NSZone?) -> Any {
1010
return self
1111
}
1212
}

test/expr/cast/array_bridge.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct B : _ObjectiveCBridgeable {
4040
var a: [A] = []
4141
var b: [B] = []
4242

43-
a = b
43+
a = b as [A]
4444

4545
b = a // expected-error {{cannot assign value of type '[A]' to type '[B]'}}
4646

@@ -82,7 +82,7 @@ struct F : _ObjectiveCBridgeable {
8282
var e: [E] = []
8383
var f: [F] = []
8484

85-
e = f
85+
e = f as [E]
8686
f = e // expected-error {{cannot assign value of type '[E]' to type '[F]'}}
8787

8888
class G {
@@ -112,7 +112,7 @@ struct H : _ObjectiveCBridgeable {
112112
var g: [G] = []
113113
var h: [H] = []
114114

115-
g = h // should type check, but cause a failure at runtime
115+
g = h as [G] // should type check, but cause a failure at runtime
116116

117117

118118
struct I : _ObjectiveCBridgeable {
@@ -139,5 +139,5 @@ struct I : _ObjectiveCBridgeable {
139139
var aoa: [AnyObject] = []
140140
var i: [I] = []
141141

142-
aoa = i
142+
aoa = i as [AnyObject]
143143
i = aoa // expected-error {{cannot assign value of type '[AnyObject]' to type '[I]'}}

test/expr/cast/array_coerce.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ da = ca // expected-error{{cannot assign value of type 'Array<C>' to type 'Array
2121
var caa = [ca]
2222
var daa = [da]
2323

24-
caa = daa // expected-error{{cannot assign value of type '[Array<D>]' to type '[Array<C>]'}}
24+
caa = daa
2525

2626
// Array slice type
2727
var cas: [C] = [c1]

test/expr/cast/dictionary_bridge.swift

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,25 +67,25 @@ func testUpcastBridge() {
6767
var dictOB = Dictionary<ObjC, BridgedToObjC>()
6868

6969
// Upcast to object types.
70-
dictRR = dictBB
71-
dictRR = dictBO
72-
dictRR = dictOB
70+
dictRR = dictBB as [Root: Root]
71+
dictRR = dictBO as [Root: Root]
72+
dictRR = dictOB as [Root: Root]
7373

74-
dictRO = dictBB
75-
dictRO = dictBO
76-
dictRO = dictOB
74+
dictRO = dictBB as [Root: ObjC]
75+
dictRO = dictBO as [Root: ObjC]
76+
dictRO = dictOB as [Root: ObjC]
7777

78-
dictOR = dictBB
79-
dictOR = dictBO
80-
dictOR = dictOB
78+
dictOR = dictBB as [ObjC: Root]
79+
dictOR = dictBO as [ObjC: Root]
80+
dictOR = dictOB as [ObjC: Root]
8181

82-
dictOO = dictBB
83-
dictOO = dictBO
84-
dictOO = dictOB
82+
dictOO = dictBB as [ObjC: ObjC]
83+
dictOO = dictBO as [ObjC: ObjC]
84+
dictOO = dictOB as [ObjC: ObjC]
8585

8686
// Upcast key or value to object type (but not both)
87-
dictBO = dictBB
88-
dictOB = dictBB
87+
dictBO = dictBB as [BridgedToObjC: ObjC]
88+
dictOB = dictBB as [ObjC: BridgedToObjC]
8989

9090
dictBB = dictBO // expected-error{{cannot assign value of type 'Dictionary<BridgedToObjC, ObjC>' to type 'Dictionary<BridgedToObjC, BridgedToObjC>'}}
9191
dictBB = dictOB // expected-error{{cannot assign value of type 'Dictionary<ObjC, BridgedToObjC>' to type 'Dictionary<BridgedToObjC, BridgedToObjC>'}}
@@ -119,8 +119,8 @@ func testDowncastBridge() {
119119
_ = dictRO as! Dictionary<BridgedToObjC, ObjC>
120120
_ = dictRO as! Dictionary<ObjC, BridgedToObjC>
121121

122-
_ = dictBO as! Dictionary<BridgedToObjC, BridgedToObjC>
123-
_ = dictOB as! Dictionary<BridgedToObjC, BridgedToObjC>
122+
_ = dictBO as Dictionary<BridgedToObjC, BridgedToObjC>
123+
_ = dictOB as Dictionary<BridgedToObjC, BridgedToObjC>
124124

125125
// We don't do mixed down/upcasts.
126126
_ = dictDO as! Dictionary<BridgedToObjC, BridgedToObjC> // expected-error{{'Dictionary<DerivesObjC, ObjC>' is not convertible to 'Dictionary<BridgedToObjC, BridgedToObjC>'}}
@@ -148,8 +148,8 @@ func testConditionalDowncastBridge() {
148148
if let d = dictRO as? Dictionary<BridgedToObjC, ObjC> { }
149149
if let d = dictRO as? Dictionary<ObjC, BridgedToObjC> { }
150150

151-
if let d = dictBO as? Dictionary<BridgedToObjC, BridgedToObjC> { }
152-
if let d = dictOB as? Dictionary<BridgedToObjC, BridgedToObjC> { }
151+
let d1 = dictBO as Dictionary<BridgedToObjC, BridgedToObjC>
152+
let d2 = dictOB as Dictionary<BridgedToObjC, BridgedToObjC>
153153

154154
// We don't do mixed down/upcasts.
155155
if let d = dictDO as? Dictionary<BridgedToObjC, BridgedToObjC> { } // expected-error{{'Dictionary<DerivesObjC, ObjC>' is not convertible to 'Dictionary<BridgedToObjC, BridgedToObjC>'}}

test/expr/cast/set_bridge.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ func testUpcastBridge() {
6060
var setB = Set<BridgedToObjC>()
6161

6262
// Upcast to object types.
63-
setR = setB; _ = setR
64-
setO = setB; _ = setO
63+
setR = setB as Set<Root>; _ = setR
64+
setO = setB as Set<ObjC>; _ = setO
6565

6666
// Upcast object to bridged type
6767
setB = setO // expected-error{{cannot assign value of type 'Set<ObjC>' to type 'Set<BridgedToObjC>'}}
@@ -78,7 +78,7 @@ func testForcedDowncastBridge() {
7878
let setB = Set<BridgedToObjC>()
7979

8080
_ = setR as! Set<BridgedToObjC>
81-
_ = setO as! Set<BridgedToObjC>
81+
_ = setO as Set<BridgedToObjC>
8282
_ = setD as! Set<BridgedToObjC> // expected-error {{'ObjC' is not a subtype of 'DerivesObjC'}}
8383
// expected-note @-1 {{in cast from type 'Set<DerivesObjC>' to 'Set<BridgedToObjC>'}}
8484

@@ -99,7 +99,7 @@ func testConditionalDowncastBridge() {
9999
var setB = Set<BridgedToObjC>()
100100

101101
if let s = setR as? Set<BridgedToObjC> { }
102-
if let s = setO as? Set<BridgedToObjC> { }
102+
let s1 = setO as Set<BridgedToObjC>
103103
if let s = setD as? Set<BridgedToObjC> { } // expected-error {{'ObjC' is not a subtype of 'DerivesObjC'}}
104104
// expected-note @-1 {{in cast from type 'Set<DerivesObjC>' to 'Set<BridgedToObjC>'}}
105105

0 commit comments

Comments
 (0)