Skip to content

Commit 4f46522

Browse files
committed
Polish off uses of dynamicType in tests
1 parent 14dc86c commit 4f46522

File tree

63 files changed

+183
-183
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+183
-183
lines changed

benchmark/single-source/DictionaryBridge.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import TestsUtils
1919
class Thing : NSObject {
2020

2121
required override init() {
22-
let c = self.dynamicType.col()
22+
let c = type(of: self).col()
2323
CheckResults(c!.count == 10, "The rules of the universe apply")
2424
}
2525

stdlib/public/SDK/Foundation/Measurement.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ extension Measurement where UnitType : Dimension {
9393
} else {
9494
let lhsValueInTermsOfBase = lhs.unit.converter.baseUnitValue(fromValue: lhs.value)
9595
let rhsValueInTermsOfBase = rhs.unit.converter.baseUnitValue(fromValue: rhs.value)
96-
return Measurement(value: lhsValueInTermsOfBase + rhsValueInTermsOfBase, unit: lhs.type(of: unit).baseUnit())
96+
return Measurement(value: lhsValueInTermsOfBase + rhsValueInTermsOfBase, unit: type(of: lhs.unit).baseUnit())
9797
}
9898
}
9999

@@ -107,7 +107,7 @@ extension Measurement where UnitType : Dimension {
107107
} else {
108108
let lhsValueInTermsOfBase = lhs.unit.converter.baseUnitValue(fromValue: lhs.value)
109109
let rhsValueInTermsOfBase = rhs.unit.converter.baseUnitValue(fromValue: rhs.value)
110-
return Measurement(value: lhsValueInTermsOfBase - rhsValueInTermsOfBase, unit: lhs.type(of: unit).baseUnit())
110+
return Measurement(value: lhsValueInTermsOfBase - rhsValueInTermsOfBase, unit: type(of: lhs.unit).baseUnit())
111111
}
112112
}
113113

test/1_stdlib/ArrayBridge.swift.gyb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,9 @@ tests.test("testBridgedVerbatim") {
201201
expectEqual(1, firstBase.serialNumber)
202202

203203
// Verify that NSArray class methods are inherited by a Swift bridging class.
204-
let className = String(reflecting: basesConvertedToNSArray.dynamicType)
204+
let className = String(reflecting: type(of: basesConvertedToNSArray))
205205
expectTrue(className.hasPrefix("Swift._ContiguousArrayStorage"))
206-
expectTrue(basesConvertedToNSArray.dynamicType.supportsSecureCoding)
206+
expectTrue(type(of: basesConvertedToNSArray).supportsSecureCoding)
207207

208208
//===--- Up- and Down-casts -----------------------------------------------===//
209209
var subclass: [Subclass] = [Subclass(11), Subclass(22)]

test/1_stdlib/ErrorBridged.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ ErrorBridgingTests.test("NSCoding") {
8282
let orig = EnumError.ReallyBadError as NSError
8383
let unarchived = archiveAndUnarchiveObject(orig)!
8484
expectEqual(orig, unarchived)
85-
expectTrue(unarchived.dynamicType == NSError.self)
85+
expectTrue(type(of: unarchived) == NSError.self)
8686
}
8787
}
8888

test/1_stdlib/Inputs/DictionaryKeyValueTypesObjC.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,18 @@ func isCocoaDictionary<KeyTy : Hashable, ValueTy>(
3434
}
3535

3636
func isNativeNSDictionary(_ d: NSDictionary) -> Bool {
37-
let className: NSString = NSStringFromClass(d.dynamicType) as NSString
37+
let className: NSString = NSStringFromClass(type(of: d)) as NSString
3838
return className.range(of: "_NativeDictionaryStorageOwner").length > 0
3939
}
4040

4141
func isCocoaNSDictionary(_ d: NSDictionary) -> Bool {
42-
let className: NSString = NSStringFromClass(d.dynamicType) as NSString
42+
let className: NSString = NSStringFromClass(type(of: d)) as NSString
4343
return className.range(of: "NSDictionary").length > 0 ||
4444
className.range(of: "NSCFDictionary").length > 0
4545
}
4646

4747
func isNativeNSArray(_ d: NSArray) -> Bool {
48-
let className: NSString = NSStringFromClass(d.dynamicType) as NSString
48+
let className: NSString = NSStringFromClass(type(of: d)) as NSString
4949
return ["_SwiftDeferredNSArray", "_ContiguousArray", "_EmptyArray"].contains {
5050
className.range(of: $0).length > 0
5151
}

test/1_stdlib/Reflection_objc.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ dump(CGRect(x: 50, y: 60, width: 100, height: 150))
213213

214214
@objc class CanaryBase {
215215
deinit {
216-
print("\(self.dynamicType) overboard")
216+
print("\(type(of: self)) overboard")
217217
}
218218

219219
required init() { }

test/1_stdlib/Runtime.swift.gyb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -317,26 +317,26 @@ Runtime.test("typeName") {
317317
expectEqual("Swift.Optional<Swift.AnyObject>.Type", _typeName((AnyObject?).Type.self))
318318

319319
var a: Any = SomeClass()
320-
expectEqual("a.SomeClass", _typeName(a.dynamicType))
320+
expectEqual("a.SomeClass", _typeName(type(of: a)))
321321

322322
a = SomeStruct()
323-
expectEqual("a.SomeStruct", _typeName(a.dynamicType))
323+
expectEqual("a.SomeStruct", _typeName(type(of: a)))
324324

325325
a = SomeEnum()
326-
expectEqual("a.SomeEnum", _typeName(a.dynamicType))
326+
expectEqual("a.SomeEnum", _typeName(type(of: a)))
327327

328328
a = AnyObject.self
329-
expectEqual("Swift.AnyObject.Protocol", _typeName(a.dynamicType))
329+
expectEqual("Swift.AnyObject.Protocol", _typeName(type(of: a)))
330330

331331
a = AnyClass.self
332-
expectEqual("Swift.AnyObject.Type.Protocol", _typeName(a.dynamicType))
332+
expectEqual("Swift.AnyObject.Type.Protocol", _typeName(type(of: a)))
333333

334334
a = (AnyObject?).self
335335
expectEqual("Swift.Optional<Swift.AnyObject>.Type",
336-
_typeName(a.dynamicType))
336+
_typeName(type(of: a)))
337337

338338
a = Any.self
339-
expectEqual("Any.Protocol", _typeName(a.dynamicType))
339+
expectEqual("Any.Protocol", _typeName(type(of: a)))
340340
}
341341

342342
class SomeSubclass : SomeClass {}

test/1_stdlib/RuntimeObjC.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,13 @@ Runtime.test("typeName") {
313313
expectEqual("NSObject", _typeName(NSObject.self))
314314

315315
var a : Any = SomeObjCClass()
316-
expectEqual("a.SomeObjCClass", _typeName(a.dynamicType))
316+
expectEqual("a.SomeObjCClass", _typeName(type(of: a)))
317317

318318
a = SomeNSObjectSubclass()
319-
expectEqual("a.SomeNSObjectSubclass", _typeName(a.dynamicType))
319+
expectEqual("a.SomeNSObjectSubclass", _typeName(type(of: a)))
320320

321321
a = NSObject()
322-
expectEqual("NSObject", _typeName(a.dynamicType))
322+
expectEqual("NSObject", _typeName(type(of: a)))
323323
}
324324

325325
class GenericClass<T> {}
@@ -816,7 +816,7 @@ Reflection.test("Name of metatype of artificial subclass") {
816816
obj.addObserver(obj, forKeyPath: "foo", options: [.new], context: &KVOHandle)
817817
obj.removeObserver(obj, forKeyPath: "foo")
818818

819-
expectEqual("\(obj.dynamicType)", "TestArtificialSubclass")
819+
expectEqual("\(type(of: obj))", "TestArtificialSubclass")
820820
}
821821

822822
@objc class StringConvertibleInDebugAndOtherwise : NSObject {

test/1_stdlib/TypeName.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,15 @@ TypeNameTests.test("Functions") {
145145
}
146146

147147
expectEqual("(()) -> ()",
148-
_typeName(curry1.dynamicType))
148+
_typeName(type(of: curry1)))
149149
expectEqual("(()) -> (()) -> ()",
150-
_typeName(curry2.dynamicType))
150+
_typeName(type(of: curry2)))
151151
expectEqual("(()) throws -> (()) -> ()",
152-
_typeName(curry2Throws.dynamicType))
152+
_typeName(type(of: curry2Throws)))
153153
expectEqual("(()) -> (()) throws -> ()",
154-
_typeName(curry3.dynamicType))
154+
_typeName(type(of: curry3)))
155155
expectEqual("(()) throws -> (()) throws -> ()",
156-
_typeName(curry3Throws.dynamicType))
156+
_typeName(type(of: curry3Throws)))
157157
}
158158

159159
runAllTests()

test/ClangModules/attr-swift_name.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func test(_ i: Int) {
1212
t.theMethod(number: i)
1313

1414
_ = t.renamedSomeProp
15-
_ = t.dynamicType.renamedClassProp
15+
_ = type(of: t).renamedClassProp
1616

1717
// We only see these two warnings because Clang can catch the other invalid
1818
// cases, and marks the attribute as invalid ahead of time.

test/ClangModules/objc_bridging_generics.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ extension AnimalContainer {
187187
_ = a.another()
188188
_ = x.another().another()
189189

190-
_ = x.dynamicType.create().another()
191-
_ = x.dynamicType.init(noise: x).another() // expected-note{{here}}
190+
_ = type(of: x).create().another()
191+
_ = type(of: x).init(noise: x).another() // expected-note{{here}}
192192
_ = y.create().another()
193193
_ = y.init(noise: x).another()
194194
_ = y.init(noise: x.another()).another()
@@ -204,8 +204,8 @@ extension AnimalContainer {
204204
}
205205

206206
func doesntUseGenericParam4(_ x: T, _ y: T.Type) {
207-
_ = x.dynamicType.apexPredator.another()
208-
x.dynamicType.apexPredator = x
207+
_ = type(of: x).apexPredator.another()
208+
type(of: x).apexPredator = x
209209

210210
_ = y.apexPredator.another()
211211

@@ -248,8 +248,8 @@ extension AnimalContainer {
248248
extension PettableContainer {
249249
// TODO: Any erasure shouldn't use generic parameter metadata.
250250
func doesntUseGenericParam(_ x: T, _ y: T.Type) { // expected-error{{cannot access the class's generic parameters}}
251-
_ = x.dynamicType.init(fur: x).other() // expected-note{{here}}
252-
_ = x.dynamicType.adopt().other()
251+
_ = type(of: x).init(fur: x).other() // expected-note{{here}}
252+
_ = type(of: x).adopt().other()
253253
_ = y.init(fur: x).other()
254254
_ = y.adopt().other()
255255
x.pet()

test/ClangModules/objc_ir.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func protocolMetatype(p: FooProto) -> FooProto.Type {
119119
// CHECK: [[SWIFT_RESULT:%.+]] = call %swift.type* @swift_getObjCClassMetadata(%objc_class* [[CASTED_RESULT]])
120120
// CHECK: call void @swift_unknownRelease(%objc_object* %0)
121121
// CHECK: ret %swift.type* [[SWIFT_RESULT]]
122-
let type = processFooType(p.dynamicType)
122+
let type = processFooType(type(of: p))
123123
return type
124124
} // CHECK: }
125125

@@ -136,7 +136,7 @@ func protocolCompositionMetatype(p: Impl) -> (FooProto & AnotherProto).Type {
136136
// CHECK: [[SWIFT_RESULT:%.+]] = call %swift.type* @swift_getObjCClassMetadata(%objc_class* [[CASTED_RESULT]])
137137
// CHECK: call void bitcast (void (%swift.refcounted*)* @rt_swift_release to void (%C7objc_ir4Impl*)*)(%C7objc_ir4Impl* %0)
138138
// CHECK: ret %swift.type* [[SWIFT_RESULT]]
139-
let type = processComboType(p.dynamicType)
139+
let type = processComboType(type(of: p))
140140
return type
141141
} // CHECK: }
142142

@@ -149,7 +149,7 @@ func protocolCompositionMetatype2(p: Impl) -> (FooProto & AnotherProto).Type {
149149
// CHECK: [[SWIFT_RESULT:%.+]] = call %swift.type* @swift_getObjCClassMetadata(%objc_class* [[CASTED_RESULT]])
150150
// CHECK: call void bitcast (void (%swift.refcounted*)* @rt_swift_release to void (%C7objc_ir4Impl*)*)(%C7objc_ir4Impl* %0)
151151
// CHECK: ret %swift.type* [[SWIFT_RESULT]]
152-
let type = processComboType2(p.dynamicType)
152+
let type = processComboType2(type(of: p))
153153
return type
154154
} // CHECK: }
155155

test/ClangModules/objc_parse.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -382,20 +382,20 @@ func testPropertyAndMethodCollision(_ obj: PropertyAndMethodCollision,
382382
obj.object = nil
383383
obj.object(obj, doSomething:#selector(getter: NSMenuItem.action))
384384

385-
obj.dynamicType.classRef = nil
386-
obj.dynamicType.classRef(obj, doSomething:#selector(getter: NSMenuItem.action))
385+
type(of: obj).classRef = nil
386+
type(of: obj).classRef(obj, doSomething:#selector(getter: NSMenuItem.action))
387387

388388
rev.object = nil
389389
rev.object(rev, doSomething:#selector(getter: NSMenuItem.action))
390390

391-
rev.dynamicType.classRef = nil
392-
rev.dynamicType.classRef(rev, doSomething:#selector(getter: NSMenuItem.action))
391+
type(of: rev).classRef = nil
392+
type(of: rev).classRef(rev, doSomething:#selector(getter: NSMenuItem.action))
393393

394394
var value: Any
395395
value = obj.protoProp()
396396
value = obj.protoPropRO()
397-
value = obj.dynamicType.protoClassProp()
398-
value = obj.dynamicType.protoClassPropRO()
397+
value = type(of: obj).protoClassProp()
398+
value = type(of: obj).protoClassPropRO()
399399
_ = value
400400
}
401401

test/Constraints/casts.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ var f2: (B) -> Bool = { $0 is D }
186186
func metatype_casts<T, U>(_ b: B.Type, t:T.Type, u: U.Type) {
187187
_ = b is D.Type
188188
_ = T.self is U.Type
189-
_ = T.self.dynamicType is U.Type.Type
190-
_ = b.dynamicType is D.Type // expected-warning{{always fails}}
189+
_ = type(of: T.self) is U.Type.Type
190+
_ = type(of: b) is D.Type // expected-warning{{always fails}}
191191
_ = b is D.Type.Type // expected-warning{{always fails}}
192192

193193
}

test/Constraints/dynamic_lookup.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ obj.ext1() // expected-warning {{result of call is unused}}
130130
obj.wonka()
131131

132132
// Find class methods via dynamic method lookup.
133-
obj.dynamicType.staticFoo!(5)
134-
obj.dynamicType.staticWibble!()
133+
type(of: obj).staticFoo!(5)
134+
type(of: obj).staticWibble!()
135135

136136
// Same as above but without the '!'
137-
obj.dynamicType.staticFoo(5)
138-
obj.dynamicType.staticWibble()
137+
type(of: obj).staticFoo(5)
138+
type(of: obj).staticWibble()
139139

140140
// Overloading and ambiguity resolution
141141

@@ -205,7 +205,7 @@ class Z4<T> where T : AnyObject { }
205205

206206
// Don't allow one to call instance methods on the Type via
207207
// dynamic method lookup.
208-
obj.dynamicType.foo!(obj)(5) // expected-error{{instance member 'foo' cannot be used on type 'Id' (aka 'AnyObject')}}
208+
type(of: obj).foo!(obj)(5) // expected-error{{instance member 'foo' cannot be used on type 'Id' (aka 'AnyObject')}}
209209

210210
// Checked casts to AnyObject
211211
var p: P = Y()

test/Constraints/existential_metatypes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ let g: Toaster.Type.Type = HairDryer.Type.self // expected-error {{cannot conver
5555
let h: WashingMachine.Type.Type = Dryer.Type.self // expected-error {{cannot convert value of type 'Dryer.Type.Type' to specified type 'WashingMachine.Type.Type'}}
5656

5757
func generic<T : WashingMachine>(_ t: T.Type) {
58-
let _: Toaster.Type.Type = t.dynamicType
58+
let _: Toaster.Type.Type = type(of: t)
5959
}
6060

6161
// rdar://problem/20780797

test/Constraints/generics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protocol SomeProtocol {
4848
func generic_metatypes<T : SomeProtocol>(_ x: T)
4949
-> (T.Type, T.SomeAssociated.Type)
5050
{
51-
return (x.dynamicType, x.dynamicType.SomeAssociated.self)
51+
return (type(of: x), type(of: x).SomeAssociated.self)
5252
}
5353

5454
// Inferring a variable's type from a call to a generic.

test/Constraints/members.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ func existential(_ p: P) {
258258
let _: () = id(p.bar(0))
259259

260260
// Static member of existential metatype)
261-
let _: () -> () = id(p.dynamicType.tum)
261+
let _: () -> () = id(type(of: p).tum)
262262

263263
// Instance member of extension returning Self
264264
let _: () -> P = id(p.returnSelfInstance)

test/DebugInfo/nostorage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class Foo {
1515
// CHECK1-SAME: type: ![[METAFOO:[0-9]+]]
1616
// CHECK1: ![[METAFOO]] = !DICompositeType(tag: DW_TAG_structure_type,
1717
// CHECK1-SAME: align: 8, flags:
18-
let type = self.dynamicType
18+
let type = type(of: self)
1919
used(type)
2020
}()
2121
}

test/IDE/complete_constructor.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,14 @@ func testGetInitFromMetatype2() {
198198

199199
func testGetInitFromMetatype3() {
200200
var SS = ExplicitConstructorsBase1.self
201-
SS.dynamicType.#^INIT_FROM_METATYPE3^#
201+
type(of: SS).#^INIT_FROM_METATYPE3^#
202202
}
203203

204204
// INIT_FROM_METATYPE3-NOT: Decl[Constructor]/CurrNominal: init()[#ExplicitConstructorsBase1#]{{; name=.+$}}
205205

206206
func testGetInitFromMetatype4() {
207207
var a = ExplicitConstructorsDerived2()
208-
a.dynamicType.#^INIT_FROM_METATYPE4^#
208+
type(of: a).#^INIT_FROM_METATYPE4^#
209209
}
210210

211211
// INIT_FROM_METATYPE4: Decl[Constructor]/CurrNominal: init({#a: Int#})[#ExplicitConstructorsDerived2#]; name=init(a: Int)

test/IDE/complete_dynamic_lookup.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,9 @@ func testAnyObject14() {
491491
}
492492

493493
func testAnyObjectClassMethods1(_ dl: AnyObject) {
494-
dl.dynamicType#^DL_CLASS_NO_DOT_1^#
494+
type(of: dl)#^DL_CLASS_NO_DOT_1^#
495495
}
496496

497497
func testAnyObjectClassMethods2(_ dl: AnyObject) {
498-
dl.dynamicType.#^DL_CLASS_DOT_1^#
498+
type(of: dl).#^DL_CLASS_DOT_1^#
499499
}

test/IRGen/class_bounded_generics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class SomeSwiftClass {
255255
// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds void (%swift.type*)*, void (%swift.type*)** [[T2]], i64 10
256256
// CHECK-NEXT: load void (%swift.type*)*, void (%swift.type*)** [[T3]], align 8
257257
func class_bounded_metatype<T: SomeSwiftClass>(_ t : T) {
258-
t.dynamicType.foo()
258+
type(of: t).foo()
259259
}
260260

261261
class WeakRef<T: AnyObject> {

test/IRGen/concrete_inherits_generic_base.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Base<T> {
1515
}
1616

1717
func present() {
18-
print("\(self.dynamicType) \(T.self) \(first) \(second)")
18+
print("\(type(of: self)) \(T.self) \(first) \(second)")
1919
}
2020
}
2121

test/IRGen/generic_metatypes.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
func genericTypeof<T>(_ x: T) -> T.Type {
1818
// CHECK: [[METATYPE:%.*]] = call %swift.type* @swift_getDynamicType(%swift.opaque* {{.*}}, %swift.type* [[TYPE]])
1919
// CHECK: ret %swift.type* [[METATYPE]]
20-
return x.dynamicType
20+
return type(of: x)
2121
}
2222

2323
struct Foo {}
@@ -69,7 +69,7 @@ func protocolTypeof(_ x: Bas) -> Bas.Type {
6969
// CHECK: [[T0:%.*]] = insertvalue { %swift.type*, i8** } undef, %swift.type* [[METATYPE]], 0
7070
// CHECK: [[T1:%.*]] = insertvalue { %swift.type*, i8** } [[T0]], i8** [[WTABLE]], 1
7171
// CHECK: ret { %swift.type*, i8** } [[T1]]
72-
return x.dynamicType
72+
return type(of: x)
7373
}
7474

7575
struct Zim : Bas {}

0 commit comments

Comments
 (0)