From 5358c115194f3f8df4ba562ac2dd0d73fcc45824 Mon Sep 17 00:00:00 2001 From: Richard Wei Date: Fri, 29 Jul 2016 15:25:53 -0700 Subject: [PATCH 1/4] [SE-0096] [Parse] Implement `type(of:)` expression --- include/swift/AST/DiagnosticsParse.def | 12 ++++ include/swift/AST/DiagnosticsSema.def | 2 +- include/swift/Parse/Parser.h | 1 + lib/Parse/ParseExpr.cpp | 78 +++++++++++++++++++++++++- 4 files changed, 91 insertions(+), 2 deletions(-) diff --git a/include/swift/AST/DiagnosticsParse.def b/include/swift/AST/DiagnosticsParse.def index 3a4cb4a424a99..1a155990a27c5 100644 --- a/include/swift/AST/DiagnosticsParse.def +++ b/include/swift/AST/DiagnosticsParse.def @@ -1105,6 +1105,18 @@ ERROR(expr_selector_expected_property_expr,PointsToFirstBadToken, ERROR(expr_selector_expected_rparen,PointsToFirstBadToken, "expected ')' to complete '#selector' expression", ()) +// Type-of expressions. +ERROR(expr_typeof_expected_lparen,PointsToFirstBadToken, + "expected '(' following 'type'", ()) +ERROR(expr_typeof_expected_label_of,PointsToFirstBadToken, + "expected argument label 'of:' within 'type(...)'", ()) +ERROR(expr_typeof_expected_expr,PointsToFirstBadToken, + "expected an expression within 'type(of: ...)'", ()) +ERROR(expr_typeof_expected_rparen,PointsToFirstBadToken, + "expected ')' to complete 'type(of: ...)' expression", ()) +WARNING(expr_dynamictype_deprecated,PointsToFirstBadToken, + "'.dynamicType' is deprecated. Use 'type(of: ...)' instead", ()) + //------------------------------------------------------------------------------ // Attribute-parsing diagnostics //------------------------------------------------------------------------------ diff --git a/include/swift/AST/DiagnosticsSema.def b/include/swift/AST/DiagnosticsSema.def index 497d190e3a0ec..c6ab6ea72153e 100644 --- a/include/swift/AST/DiagnosticsSema.def +++ b/include/swift/AST/DiagnosticsSema.def @@ -691,7 +691,7 @@ ERROR(did_not_call_method,none, (Identifier)) ERROR(init_not_instance_member,none, - "'init' is a member of the type; insert '.dynamicType' to initialize " + "'init' is a member of the type; use 'type(of: ...)' to initialize " "a new object of the same dynamic type", ()) ERROR(super_initializer_not_in_initializer,none, "'super.init' cannot be called outside of an initializer", ()) diff --git a/include/swift/Parse/Parser.h b/include/swift/Parse/Parser.h index 91035e218f914..a10057b9d4dd0 100644 --- a/include/swift/Parse/Parser.h +++ b/include/swift/Parse/Parser.h @@ -1118,6 +1118,7 @@ class Parser { ParserResult parseExprSuper(bool isExprBasic); ParserResult parseExprConfiguration(); ParserResult parseExprStringLiteral(); + ParserResult parseExprTypeOf(); /// If the token is an escaped identifier being used as an argument /// label, but doesn't need to be, diagnose it. diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index b23e17a1e97e0..c5055d88c8126 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -1095,6 +1095,12 @@ ParserResult Parser::parseExprPostfix(Diag<> ID, bool isExprBasic) { } case tok::identifier: // foo + // If starts with 'type(', parse the 'type(of: ...)' metatype expression + if (Tok.getText() == "type" && peekToken().is(tok::l_paren)) { + Result = parseExprTypeOf(); + break; + } + // If we are parsing a refutable pattern and are inside a let/var pattern, // the identifiers change to be value bindings instead of decl references. // Parse and return this as an UnresolvedPatternExpr around a binding. This @@ -1413,12 +1419,22 @@ ParserResult Parser::parseExprPostfix(Diag<> ID, bool isExprBasic) { } // Handle "x.dynamicType" - A metatype expr. + // Deprecated in SE-0096: `x.dynamicType` becomes `type(of: x)` if (Tok.is(tok::kw_dynamicType)) { + // Fix-it + auto range = Result.get()->getSourceRange(); + auto dynamicTypeExprRange = SourceRange(TokLoc, consumeToken()); + diagnose(TokLoc, diag::expr_dynamictype_deprecated) + .highlight(dynamicTypeExprRange) + .fixItReplace(dynamicTypeExprRange, ")") + .fixItInsert(range.Start, "type(of: "); + Result = makeParserResult( - new (Context) DynamicTypeExpr(Result.get(), consumeToken(), Type())); + new (Context) DynamicTypeExpr(Result.get(), dynamicTypeExprRange.End, Type())); continue; } + // Handle "x.self" expr. if (Tok.is(tok::kw_self)) { Result = makeParserResult( @@ -2995,3 +3011,63 @@ Parser::parseVersionConstraintSpec() { return makeParserResult(new (Context) VersionConstraintAvailabilitySpec( Platform.getValue(), PlatformLoc, Version, VersionRange)); } + +/// parseExprTypeOf +/// +/// expr-dynamictype: +/// 'type' '(' 'of:' expr ')' +/// +ParserResult Parser::parseExprTypeOf() { + + assert(Tok.getText() == "type" && "only 'type' should be handled here"); + + // Consume 'type' + SourceLoc keywordLoc = consumeToken(); + // Consume '(' + SourceLoc lParenLoc = consumeToken(tok::l_paren); + + // Parse `of` label + // If we see a potential argument label followed by a ':', consume + // it. + if (Tok.canBeArgumentLabel() && Tok.getText() == "of" && peekToken().is(tok::colon)) { + consumeToken(); + consumeToken(tok::colon); + } else { + diagnose(Tok, diag::expr_typeof_expected_label_of); + return makeParserError(); + } + + // Parse the subexpression. + ParserResult subExpr = parseExpr(diag::expr_typeof_expected_expr); + if (subExpr.hasCodeCompletion()) + return makeParserCodeCompletionResult(); + + // Parse the closing ')' + SourceLoc rParenLoc; + if (subExpr.isParseError()) { + skipUntilDeclStmtRBrace(tok::r_paren); + if (Tok.is(tok::r_paren)) + rParenLoc = consumeToken(); + else + rParenLoc = Tok.getLoc(); + } else { + parseMatchingToken(tok::r_paren, rParenLoc, + diag::expr_typeof_expected_rparen, lParenLoc); + } + + // If the subexpression was in error, just propagate the error. + if (subExpr.isParseError()) { + if (subExpr.hasCodeCompletion()) { + auto res = makeParserResult( + new (Context) DynamicTypeExpr(subExpr.get(), consumeToken(), Type())); + res.setHasCodeCompletion(); + return res; + } else { + return makeParserResult( + new (Context) ErrorExpr(SourceRange(keywordLoc, rParenLoc))); + } + } + + return makeParserResult( + new (Context) DynamicTypeExpr(subExpr.get(), rParenLoc, Type())); +} From 14dc86cf158fec4742e51ffa8eca5a1403c96ff9 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Fri, 29 Jul 2016 02:13:25 -0700 Subject: [PATCH 2/4] Polish off uses of dynamicType in codebase --- docs/archive/LangRef.html | 2 +- include/swift/AST/Expr.h | 2 +- lib/Sema/CSDiag.cpp | 12 ++++----- .../CheckMutableCollectionType.swift.gyb | 8 +++--- .../LoggingWrappers.swift.gyb | 2 +- .../MinimalCollections.swift.gyb | 2 +- .../StdlibUnittest/StdlibUnittest.swift.gyb | 26 +++++++++---------- .../public/SDK/Foundation/Measurement.swift | 6 ++--- stdlib/public/core/AnyHashable.swift | 2 +- stdlib/public/core/Builtin.swift | 10 +++---- stdlib/public/core/DebuggerSupport.swift | 4 +-- stdlib/public/core/ErrorType.swift | 2 +- .../core/ExistentialCollection.swift.gyb | 2 +- stdlib/public/core/HeapBuffer.swift | 2 +- stdlib/public/core/ManagedBuffer.swift | 4 +-- stdlib/public/core/Mirror.swift | 6 ++--- stdlib/public/core/OutputStream.swift | 2 +- stdlib/public/core/Policy.swift | 4 +-- stdlib/public/core/Reflection.swift | 4 +-- 19 files changed, 51 insertions(+), 51 deletions(-) diff --git a/docs/archive/LangRef.html b/docs/archive/LangRef.html index e897c2fe071bc..96c277a898c6c 100644 --- a/docs/archive/LangRef.html +++ b/docs/archive/LangRef.html @@ -1255,7 +1255,7 @@

Metatype Types

type-metatype ::= type-simple '.' 'Type' -

Every type has an associated metatype T.dynamicType. A value of the metatype +

Every type has an associated metatype type(of: T). A value of the metatype type is a reference to a global object which describes the type. Most metatype types are singleton and therefore require no storage, but metatypes associated with class diff --git a/include/swift/AST/Expr.h b/include/swift/AST/Expr.h index 1bdbfffdbbb21..0bda3d18bdf8c 100644 --- a/include/swift/AST/Expr.h +++ b/include/swift/AST/Expr.h @@ -3517,7 +3517,7 @@ class AutoClosureExpr : public AbstractClosureExpr { } }; -/// DynamicTypeExpr - "base.dynamicType" - Produces a metatype value. +/// DynamicTypeExpr - "type(of: base)" - Produces a metatype value. /// /// The metatype value can comes from evaluating an expression and then /// getting its metatype. diff --git a/lib/Sema/CSDiag.cpp b/lib/Sema/CSDiag.cpp index 6a7ab6325c354..b01d85b2976d7 100644 --- a/lib/Sema/CSDiag.cpp +++ b/lib/Sema/CSDiag.cpp @@ -2267,14 +2267,14 @@ bool FailureDiagnosis::diagnoseGeneralMemberFailure(Constraint *constraint) { return true; } - // Suggest inserting '.dynamicType' to construct another object of the - // same dynamic type. - SourceLoc fixItLoc - = ctorRef->getNameLoc().getBaseNameLoc().getAdvancedLoc(-1); + // Suggest inserting a call to 'type(of:)' to construct another object + // of the same dynamic type. + SourceRange fixItRng = ctorRef->getNameLoc().getSourceRange(); - // Place the '.dynamicType' right before the init. + // Surround the caller in `type(of:)`. diagnose(anchor->getLoc(), diag::init_not_instance_member) - .fixItInsert(fixItLoc, ".dynamicType"); + .fixItInsert(fixItRng.Start, "type(of: ") + .fixItInsertAfter(fixItRng.End, ")"); return true; } } diff --git a/stdlib/private/StdlibCollectionUnittest/CheckMutableCollectionType.swift.gyb b/stdlib/private/StdlibCollectionUnittest/CheckMutableCollectionType.swift.gyb index 9b813ef7e1781..edc0dda5fef1a 100644 --- a/stdlib/private/StdlibCollectionUnittest/CheckMutableCollectionType.swift.gyb +++ b/stdlib/private/StdlibCollectionUnittest/CheckMutableCollectionType.swift.gyb @@ -491,10 +491,10 @@ self.test("\(testNamePrefix).sorted/DispatchesThrough_withUnsafeMutableBufferPoi // This sort operation is not in-place. // The collection is copied into an array before sorting. expectEqual( - 0, lc.log._withUnsafeMutableBufferPointerIfSupported[lc.dynamicType]) + 0, lc.log._withUnsafeMutableBufferPointerIfSupported[type(of: lc)]) expectEqual( 0, - lc.log._withUnsafeMutableBufferPointerIfSupportedNonNilReturns[lc.dynamicType]) + lc.log._withUnsafeMutableBufferPointerIfSupportedNonNilReturns[type(of: lc)]) expectEqualSequence([ 1, 2, 3, 4, 5 ], extractedResult.map { $0.value }) } @@ -808,10 +808,10 @@ self.test("\(testNamePrefix).partition/DispatchesThrough_withUnsafeMutableBuffer }) expectEqual( - 1, lc.log._withUnsafeMutableBufferPointerIfSupported[lc.dynamicType]) + 1, lc.log._withUnsafeMutableBufferPointerIfSupported[type(of: lc)]) expectEqual( withUnsafeMutableBufferPointerIsSupported ? 1 : 0, - lc.log._withUnsafeMutableBufferPointerIfSupportedNonNilReturns[lc.dynamicType]) + lc.log._withUnsafeMutableBufferPointerIfSupportedNonNilReturns[type(of: lc)]) expectEqual(4, lc.distance(from: lc.startIndex, to: pivot)) expectEqualsUnordered([1, 2, 3, 4], lc.prefix(upTo: pivot).map { extractValue($0).value }) diff --git a/stdlib/private/StdlibCollectionUnittest/LoggingWrappers.swift.gyb b/stdlib/private/StdlibCollectionUnittest/LoggingWrappers.swift.gyb index bc432baa2244d..94d11e5e8e1cf 100644 --- a/stdlib/private/StdlibCollectionUnittest/LoggingWrappers.swift.gyb +++ b/stdlib/private/StdlibCollectionUnittest/LoggingWrappers.swift.gyb @@ -32,7 +32,7 @@ extension LoggingType { } public var selfType: Any.Type { - return self.dynamicType + return type(of: self) } } diff --git a/stdlib/private/StdlibCollectionUnittest/MinimalCollections.swift.gyb b/stdlib/private/StdlibCollectionUnittest/MinimalCollections.swift.gyb index 5b8722a9f34c9..4a1f7464146a2 100644 --- a/stdlib/private/StdlibCollectionUnittest/MinimalCollections.swift.gyb +++ b/stdlib/private/StdlibCollectionUnittest/MinimalCollections.swift.gyb @@ -555,7 +555,7 @@ public struct ${Self} : ${SelfProtocols} { self.underestimatedCount = 0 self._elements = [] self._collectionState = - _CollectionState(name: "\(self.dynamicType)", elementCount: 0) + _CollectionState(name: "\(type(of: self))", elementCount: 0) } public init(_ elements: S) where S.Iterator.Element == T { diff --git a/stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb b/stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb index cc1a057d441c2..ba3731d08676c 100644 --- a/stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb +++ b/stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb @@ -168,8 +168,8 @@ public func expectEqualTest( ) { if !equal(expected, actual) { expectationFailure( - "expected: \(String(reflecting: expected)) (of type \(String(reflecting: expected.dynamicType)))\n" - + "actual: \(String(reflecting: actual)) (of type \(String(reflecting: actual.dynamicType)))", + "expected: \(String(reflecting: expected)) (of type \(String(reflecting: type(of: expected))))\n" + + "actual: \(String(reflecting: actual)) (of type \(String(reflecting: type(of: actual))))", trace: ${trace} ) } @@ -178,7 +178,7 @@ public func expectEqualTest( public func expectNotEqual(_ expected: T, _ actual: T, ${TRACE}) { if expected == actual { expectationFailure( - "unexpected value: \"\(actual)\" (of type \(String(reflecting: actual.dynamicType)))", + "unexpected value: \"\(actual)\" (of type \(String(reflecting: type(of: actual))))", trace: ${trace} ) } @@ -197,8 +197,8 @@ public func expectOptionalEqual( ) { if (actual == nil) || !equal(expected, actual!) { expectationFailure( - "expected: \"\(expected)\" (of type \(String(reflecting: expected.dynamicType)))\n" - + "actual: \"\(actual)\" (of type \(String(reflecting: actual.dynamicType)))", + "expected: \"\(expected)\" (of type \(String(reflecting: type(of: expected))))\n" + + "actual: \"\(actual)\" (of type \(String(reflecting: type(of: actual))))", trace: ${trace}) } } @@ -206,8 +206,8 @@ public func expectOptionalEqual( public func expectEqual(_ expected: T?, _ actual: T?, ${TRACE}) { if expected != actual { expectationFailure( - "expected: \"\(expected)\" (of type \(String(reflecting: expected.dynamicType)))\n" - + "actual: \"\(actual)\" (of type \(String(reflecting: actual.dynamicType)))", + "expected: \"\(expected)\" (of type \(String(reflecting: type(of: expected))))\n" + + "actual: \"\(actual)\" (of type \(String(reflecting: type(of: actual))))", trace: ${trace}) } } @@ -217,7 +217,7 @@ public func expectNotEqual( ) { if expected == actual { expectationFailure( - "unexpected value: \"\(actual)\" (of type \(String(reflecting: actual.dynamicType)))", + "unexpected value: \"\(actual)\" (of type \(String(reflecting: type(of: actual))))", trace: ${trace}) } } @@ -240,8 +240,8 @@ public func expectOptionalEqual${Generic}( _ expected: ${EquatableType}, _ actual: ${EquatableType}?, ${TRACE}) { if (actual == nil) || expected != actual! { expectationFailure( - "expected: \"\(expected)\" (of type \(String(reflecting: expected.dynamicType)))" - + "actual: \"\(actual)\" (of type \(String(reflecting: actual.dynamicType)))", + "expected: \"\(expected)\" (of type \(String(reflecting: type(of: expected))))" + + "actual: \"\(actual)\" (of type \(String(reflecting: type(of: actual))))", trace: ${trace}) } } @@ -2270,7 +2270,7 @@ public func expectEqualSequence< if !expected.elementsEqual(actual, by: sameValue) { expectationFailure("expected elements: \"\(expected)\"\n" - + "actual: \"\(actual)\" (of type \(String(reflecting: actual.dynamicType)))", + + "actual: \"\(actual)\" (of type \(String(reflecting: type(of: actual))))", trace: ${trace}) } } @@ -2333,7 +2333,7 @@ public func expectEqualsUnordered( ) { if numericCast(expected.count) != actual.count { expectationFailure("expected elements: \"\(expected)\"\n" - + "actual: \"\(actual)\" (of type \(String(reflecting: actual.dynamicType)))", + + "actual: \"\(actual)\" (of type \(String(reflecting: type(of: actual))))", trace: ${trace}) } let r = Range(uncheckedBounds: @@ -2341,7 +2341,7 @@ public func expectEqualsUnordered( for e in actual { if !r.contains(e) { expectationFailure("expected elements: \"\(expected)\"\n" - + "actual: \"\(actual)\" (of type \(String(reflecting: actual.dynamicType)))", + + "actual: \"\(actual)\" (of type \(String(reflecting: type(of: actual))))", trace: ${trace}) } } diff --git a/stdlib/public/SDK/Foundation/Measurement.swift b/stdlib/public/SDK/Foundation/Measurement.swift index da85b42f6a9b4..b861115f75bd3 100644 --- a/stdlib/public/SDK/Foundation/Measurement.swift +++ b/stdlib/public/SDK/Foundation/Measurement.swift @@ -67,7 +67,7 @@ extension Measurement where UnitType : Dimension { return Measurement(value: value, unit: otherUnit) } else { let valueInTermsOfBase = unit.converter.baseUnitValue(fromValue: value) - if otherUnit.isEqual(unit.dynamicType.baseUnit()) { + if otherUnit.isEqual(type(of: unit).baseUnit()) { return Measurement(value: valueInTermsOfBase, unit: otherUnit) } else { let otherValueFromTermsOfBase = otherUnit.converter.value(fromBaseUnitValue: valueInTermsOfBase) @@ -93,7 +93,7 @@ extension Measurement where UnitType : Dimension { } else { let lhsValueInTermsOfBase = lhs.unit.converter.baseUnitValue(fromValue: lhs.value) let rhsValueInTermsOfBase = rhs.unit.converter.baseUnitValue(fromValue: rhs.value) - return Measurement(value: lhsValueInTermsOfBase + rhsValueInTermsOfBase, unit: lhs.unit.dynamicType.baseUnit()) + return Measurement(value: lhsValueInTermsOfBase + rhsValueInTermsOfBase, unit: lhs.type(of: unit).baseUnit()) } } @@ -107,7 +107,7 @@ extension Measurement where UnitType : Dimension { } else { let lhsValueInTermsOfBase = lhs.unit.converter.baseUnitValue(fromValue: lhs.value) let rhsValueInTermsOfBase = rhs.unit.converter.baseUnitValue(fromValue: rhs.value) - return Measurement(value: lhsValueInTermsOfBase - rhsValueInTermsOfBase, unit: lhs.unit.dynamicType.baseUnit()) + return Measurement(value: lhsValueInTermsOfBase - rhsValueInTermsOfBase, unit: lhs.type(of: unit).baseUnit()) } } diff --git a/stdlib/public/core/AnyHashable.swift b/stdlib/public/core/AnyHashable.swift index 5f421b3675c50..4d6ada7978c59 100644 --- a/stdlib/public/core/AnyHashable.swift +++ b/stdlib/public/core/AnyHashable.swift @@ -54,7 +54,7 @@ internal struct _ConcreteHashableBox : _AnyHashableBox { } internal var _typeID: ObjectIdentifier { - return ObjectIdentifier(self.dynamicType) + return ObjectIdentifier(type(of: self)) } internal func _unbox() -> T? { diff --git a/stdlib/public/core/Builtin.swift b/stdlib/public/core/Builtin.swift index 7f32ec1a076ab..02f1da418b068 100644 --- a/stdlib/public/core/Builtin.swift +++ b/stdlib/public/core/Builtin.swift @@ -488,7 +488,7 @@ internal func _makeBridgeObject( _sanityCheck( _isObjCTaggedPointer(object) - || _usesNativeSwiftReferenceCounting(object.dynamicType) + || _usesNativeSwiftReferenceCounting(type(of: object)) || bits == _objectPointerIsObjCBit, "All spare bits must be set in non-native, non-tagged bridge objects" ) @@ -565,7 +565,7 @@ func _isUnique_native(_ object: inout T) -> Bool { (_bitPattern(Builtin.reinterpretCast(object)) & _objectPointerSpareBits) == 0) _sanityCheck(_usesNativeSwiftReferenceCounting( - (Builtin.reinterpretCast(object) as AnyObject).dynamicType)) + type(of: Builtin.reinterpretCast(object) as AnyObject))) return Bool(Builtin.isUnique_native(&object)) } @@ -580,7 +580,7 @@ func _isUniqueOrPinned_native(_ object: inout T) -> Bool { (_bitPattern(Builtin.reinterpretCast(object)) & _objectPointerSpareBits) == 0) _sanityCheck(_usesNativeSwiftReferenceCounting( - (Builtin.reinterpretCast(object) as AnyObject).dynamicType)) + type(of: Builtin.reinterpretCast(object) as AnyObject))) return Bool(Builtin.isUniqueOrPinned_native(&object)) } @@ -606,8 +606,8 @@ public func unsafeUnwrap(_ nonEmpty: T?) -> T { /// Extract an object reference from an Any known to contain an object. internal func _unsafeDowncastToAnyObject(fromAny any: Any) -> AnyObject { - _sanityCheck(any.dynamicType is AnyObject.Type - || any.dynamicType is AnyObject.Protocol, + _sanityCheck(type(of: any) is AnyObject.Type + || type(of: any) is AnyObject.Protocol, "Any expected to contain object reference") // With a SIL instruction, we could more efficiently grab the object reference // out of the Any's inline storage. diff --git a/stdlib/public/core/DebuggerSupport.swift b/stdlib/public/core/DebuggerSupport.swift index b82164f5e25d4..e5832963f6c26 100644 --- a/stdlib/public/core/DebuggerSupport.swift +++ b/stdlib/public/core/DebuggerSupport.swift @@ -39,7 +39,7 @@ public enum _DebuggerSupport { } internal static func isClass(_ value: Any) -> Bool { - if let _ = value.dynamicType as? AnyClass { + if let _ = type(of: value) as? AnyClass { return true } return false @@ -119,7 +119,7 @@ public enum _DebuggerSupport { return csc.description } // for a Class with no custom summary, mimic the Foundation default - return "<\(x.dynamicType): 0x\(String(asNumericValue(x), radix: 16, uppercase: false))>" + return "<\(type(of: x)): 0x\(String(asNumericValue(x), radix: 16, uppercase: false))>" } else { // but if I can't provide a value, just use the type anyway return "\(mirror.subjectType)" diff --git a/stdlib/public/core/ErrorType.swift b/stdlib/public/core/ErrorType.swift index ee24364111bbf..d3a8ef43df31a 100644 --- a/stdlib/public/core/ErrorType.swift +++ b/stdlib/public/core/ErrorType.swift @@ -169,7 +169,7 @@ public typealias ErrorProtocol = Error extension Error { public var _domain: String { - return String(reflecting: self.dynamicType) + return String(reflecting: type(of: self)) } public var _userInfo: Any? { diff --git a/stdlib/public/core/ExistentialCollection.swift.gyb b/stdlib/public/core/ExistentialCollection.swift.gyb index 4f38667be8362..72bb397b782a3 100644 --- a/stdlib/public/core/ExistentialCollection.swift.gyb +++ b/stdlib/public/core/ExistentialCollection.swift.gyb @@ -664,7 +664,7 @@ internal final class _IndexBox< } internal var _typeID: ObjectIdentifier { - return ObjectIdentifier(self.dynamicType) + return ObjectIdentifier(type(of: self)) } internal func _unbox() -> T? { diff --git a/stdlib/public/core/HeapBuffer.swift b/stdlib/public/core/HeapBuffer.swift index 5f1cfcea16e2d..23975f903eb4d 100644 --- a/stdlib/public/core/HeapBuffer.swift +++ b/stdlib/public/core/HeapBuffer.swift @@ -137,7 +137,7 @@ struct _HeapBuffer : Equatable { internal init(_ storage: AnyObject) { _sanityCheck( - _usesNativeSwiftReferenceCounting(storage.dynamicType), + _usesNativeSwiftReferenceCounting(type(of: storage)), "HeapBuffer manages only native objects" ) self._storage = Builtin.castToNativeObject(storage) diff --git a/stdlib/public/core/ManagedBuffer.swift b/stdlib/public/core/ManagedBuffer.swift index bbb1d4ab200e9..1ab8f05e57e51 100644 --- a/stdlib/public/core/ManagedBuffer.swift +++ b/stdlib/public/core/ManagedBuffer.swift @@ -205,7 +205,7 @@ public struct ManagedBufferPointer : Equatable { /// - Precondition: `buffer` is an instance of a non-`@objc` class whose /// `deinit` destroys its stored `Header` and any constructed `Element`s. public init(unsafeBufferObject buffer: AnyObject) { - ManagedBufferPointer._checkValidBufferClass(buffer.dynamicType) + ManagedBufferPointer._checkValidBufferClass(type(of: buffer)) self._nativeBuffer = Builtin.castToNativeObject(buffer) } @@ -220,7 +220,7 @@ public struct ManagedBufferPointer : Equatable { /// it in this specialized constructor. @_versioned internal init(_uncheckedUnsafeBufferObject buffer: AnyObject) { - ManagedBufferPointer._sanityCheckValidBufferClass(buffer.dynamicType) + ManagedBufferPointer._sanityCheckValidBufferClass(type(of: buffer)) self._nativeBuffer = Builtin.castToNativeObject(buffer) } diff --git a/stdlib/public/core/Mirror.swift b/stdlib/public/core/Mirror.swift index 6134bd990b8ce..11b951a7b520d 100644 --- a/stdlib/public/core/Mirror.swift +++ b/stdlib/public/core/Mirror.swift @@ -100,7 +100,7 @@ public struct Mirror { } else { self = Mirror( legacy: _reflect(subject), - subjectType: subject.dynamicType) + subjectType: type(of: subject)) } } @@ -147,7 +147,7 @@ public struct Mirror { _ subject: AnyObject, asClass targetSuperclass: AnyClass) -> _Mirror? { // get a legacy mirror and the most-derived type - var cls: AnyClass = subject.dynamicType + var cls: AnyClass = type(of: subject) var clsMirror = _reflect(subject) // Walk up the chain of mirrors/classes until we find staticSubclass @@ -490,7 +490,7 @@ extension _Mirror { internal func _superMirror() -> _Mirror? { if self.count > 0 { let childMirror = self[0].1 - if _isClassSuperMirror(childMirror.dynamicType) { + if _isClassSuperMirror(type(of: childMirror)) { return childMirror } } diff --git a/stdlib/public/core/OutputStream.swift b/stdlib/public/core/OutputStream.swift index c4b0645bb6f24..99be36be49903 100644 --- a/stdlib/public/core/OutputStream.swift +++ b/stdlib/public/core/OutputStream.swift @@ -338,7 +338,7 @@ internal func _print_unlocked( // string. Check for Optional first, before checking protocol // conformance below, because an Optional value is convertible to a // protocol if its wrapped type conforms to that protocol. - if _isOptional(value.dynamicType) { + if _isOptional(type(of: value)) { let debugPrintable = value as! CustomDebugStringConvertible debugPrintable.debugDescription.write(to: &target) return diff --git a/stdlib/public/core/Policy.swift b/stdlib/public/core/Policy.swift index 77fe38f19b802..1f99a496c8856 100644 --- a/stdlib/public/core/Policy.swift +++ b/stdlib/public/core/Policy.swift @@ -79,7 +79,7 @@ public typealias FloatLiteralType = Double /// `BooleanLiteralType` alias. For example: /// /// let isBool = true -/// print("isBool is a '\(isBool.dynamicType)'") +/// print("isBool is a '\(type(of: isBool))'") /// // Prints "isBool is a 'Bool'" /// /// The type aliased by `BooleanLiteralType` must conform to the @@ -143,7 +143,7 @@ public typealias _MaxBuiltinFloatType = Builtin.FPIEEE64 /// // Prints "true" /// /// let v: AnyObject = 100 -/// print(v.dynamicType) +/// print(type(of: v)) /// // Prints "__NSCFNumber" /// /// The flexible behavior of the `AnyObject` protocol is similar to diff --git a/stdlib/public/core/Reflection.swift b/stdlib/public/core/Reflection.swift index 75c606fbe0c3f..db55b9752566b 100644 --- a/stdlib/public/core/Reflection.swift +++ b/stdlib/public/core/Reflection.swift @@ -103,7 +103,7 @@ public protocol _Mirror { /// The instance being reflected. var value: Any { get } - /// Identical to `value.dynamicType`. + /// Identical to `type(of: value)`. var valueType: Any.Type { get } /// A unique identifier for `value` if it is a class instance; `nil` @@ -214,7 +214,7 @@ internal func _dump_unlocked( _dumpPrint_unlocked(value, mirror, &target) let id: ObjectIdentifier? - if value.dynamicType is AnyObject.Type { + if type(of: value) is AnyObject.Type { // Object is a class (but not an ObjC-bridged struct) id = ObjectIdentifier(_unsafeDowncastToAnyObject(fromAny: value)) } else if let metatypeInstance = value as? Any.Type { From 4f465224eafe845821c93fa16c639d3c0e75e067 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Fri, 29 Jul 2016 03:06:55 -0700 Subject: [PATCH 3/4] Polish off uses of dynamicType in tests --- .../single-source/DictionaryBridge.swift | 2 +- .../public/SDK/Foundation/Measurement.swift | 4 +-- test/1_stdlib/ArrayBridge.swift.gyb | 4 +-- test/1_stdlib/ErrorBridged.swift | 2 +- .../Inputs/DictionaryKeyValueTypesObjC.swift | 6 ++-- test/1_stdlib/Reflection_objc.swift | 2 +- test/1_stdlib/Runtime.swift.gyb | 14 ++++---- test/1_stdlib/RuntimeObjC.swift | 8 ++--- test/1_stdlib/TypeName.swift | 10 +++--- test/ClangModules/attr-swift_name.swift | 2 +- .../ClangModules/objc_bridging_generics.swift | 12 +++---- test/ClangModules/objc_ir.swift | 6 ++-- test/ClangModules/objc_parse.swift | 12 +++---- test/Constraints/casts.swift | 4 +-- test/Constraints/dynamic_lookup.swift | 10 +++--- test/Constraints/existential_metatypes.swift | 2 +- test/Constraints/generics.swift | 2 +- test/Constraints/members.swift | 2 +- test/DebugInfo/nostorage.swift | 2 +- test/IDE/complete_constructor.swift | 4 +-- test/IDE/complete_dynamic_lookup.swift | 4 +-- test/IRGen/class_bounded_generics.swift | 2 +- .../concrete_inherits_generic_base.swift | 2 +- test/IRGen/generic_metatypes.swift | 4 +-- test/IRGen/meta_meta_type.swift | 4 +-- test/IRGen/metadata_dominance.swift | 2 +- .../SDK/CoreFoundation_casting.swift | 2 +- test/Interpreter/classes.swift | 2 +- test/Interpreter/currying_protocols.swift | 2 +- test/Interpreter/dynamic_lookup.swift | 2 +- test/Interpreter/generic_casts.swift | 6 ++-- test/Interpreter/imported_objc_generics.swift | 6 ++-- test/Interpreter/objc_class_properties.swift | 6 ++-- test/Interpreter/protocol_extensions.swift | 2 +- test/Interpreter/repl.swift | 2 +- test/Interpreter/typeof.swift | 16 +++++----- ...eference-dependencies-dynamic-lookup.swift | 2 +- test/Parse/type_expr.swift | 14 ++++---- test/PrintAsObjC/local-types.swift | 2 +- test/SILGen/dynamic.swift | 4 +-- test/SILGen/dynamic_lookup.swift | 4 +-- test/SILGen/existential_metatypes.swift | 2 +- test/SILGen/expressions.swift | 4 +-- test/SILGen/functions.swift | 4 +-- test/SILGen/metatype_abstraction.swift | 10 +++--- test/SILGen/metatypes.swift | 10 +++--- test/SILGen/optional_chain_addressor.swift | 2 +- test/SILOptimizer/cast_folding.swift | 18 +++++------ .../definite_init_failable_initializers.swift | 14 ++++---- ...it_failable_initializers_diagnostics.swift | 2 +- .../SILOptimizer/devirt_unbound_generic.swift | 2 +- .../SILOptimizer/devirt_value_metatypes.swift | 6 ++-- test/Sanitizers/tsan-type-metadata.swift | 2 +- test/Sanitizers/witness_table_lookup.swift | 6 ++-- test/decl/func/dynamic_self.swift | 4 +-- test/decl/func/rethrows.swift | 32 +++++++++---------- test/decl/protocol/req/recursion.swift | 2 +- .../postfix/dot/init_ref_delegation.swift | 32 +++++++++---------- test/expr/unary/selector/selector.swift | 4 +-- test/stmt/errors.swift | 2 +- test/type/metatype/metatypes.swift | 2 +- validation-test/stdlib/IOKitOverlay.swift | 2 +- validation-test/stdlib/Set.swift | 4 +-- 63 files changed, 183 insertions(+), 183 deletions(-) diff --git a/benchmark/single-source/DictionaryBridge.swift b/benchmark/single-source/DictionaryBridge.swift index 3f89e7fc27c7b..75ff81a36a8c4 100644 --- a/benchmark/single-source/DictionaryBridge.swift +++ b/benchmark/single-source/DictionaryBridge.swift @@ -19,7 +19,7 @@ import TestsUtils class Thing : NSObject { required override init() { - let c = self.dynamicType.col() + let c = type(of: self).col() CheckResults(c!.count == 10, "The rules of the universe apply") } diff --git a/stdlib/public/SDK/Foundation/Measurement.swift b/stdlib/public/SDK/Foundation/Measurement.swift index b861115f75bd3..77d5232bc8495 100644 --- a/stdlib/public/SDK/Foundation/Measurement.swift +++ b/stdlib/public/SDK/Foundation/Measurement.swift @@ -93,7 +93,7 @@ extension Measurement where UnitType : Dimension { } else { let lhsValueInTermsOfBase = lhs.unit.converter.baseUnitValue(fromValue: lhs.value) let rhsValueInTermsOfBase = rhs.unit.converter.baseUnitValue(fromValue: rhs.value) - return Measurement(value: lhsValueInTermsOfBase + rhsValueInTermsOfBase, unit: lhs.type(of: unit).baseUnit()) + return Measurement(value: lhsValueInTermsOfBase + rhsValueInTermsOfBase, unit: type(of: lhs.unit).baseUnit()) } } @@ -107,7 +107,7 @@ extension Measurement where UnitType : Dimension { } else { let lhsValueInTermsOfBase = lhs.unit.converter.baseUnitValue(fromValue: lhs.value) let rhsValueInTermsOfBase = rhs.unit.converter.baseUnitValue(fromValue: rhs.value) - return Measurement(value: lhsValueInTermsOfBase - rhsValueInTermsOfBase, unit: lhs.type(of: unit).baseUnit()) + return Measurement(value: lhsValueInTermsOfBase - rhsValueInTermsOfBase, unit: type(of: lhs.unit).baseUnit()) } } diff --git a/test/1_stdlib/ArrayBridge.swift.gyb b/test/1_stdlib/ArrayBridge.swift.gyb index ab52d15b5a889..b6c75fa8851fa 100644 --- a/test/1_stdlib/ArrayBridge.swift.gyb +++ b/test/1_stdlib/ArrayBridge.swift.gyb @@ -201,9 +201,9 @@ tests.test("testBridgedVerbatim") { expectEqual(1, firstBase.serialNumber) // Verify that NSArray class methods are inherited by a Swift bridging class. - let className = String(reflecting: basesConvertedToNSArray.dynamicType) + let className = String(reflecting: type(of: basesConvertedToNSArray)) expectTrue(className.hasPrefix("Swift._ContiguousArrayStorage")) - expectTrue(basesConvertedToNSArray.dynamicType.supportsSecureCoding) + expectTrue(type(of: basesConvertedToNSArray).supportsSecureCoding) //===--- Up- and Down-casts -----------------------------------------------===// var subclass: [Subclass] = [Subclass(11), Subclass(22)] diff --git a/test/1_stdlib/ErrorBridged.swift b/test/1_stdlib/ErrorBridged.swift index 120f559676b7e..65b82fc974889 100644 --- a/test/1_stdlib/ErrorBridged.swift +++ b/test/1_stdlib/ErrorBridged.swift @@ -82,7 +82,7 @@ ErrorBridgingTests.test("NSCoding") { let orig = EnumError.ReallyBadError as NSError let unarchived = archiveAndUnarchiveObject(orig)! expectEqual(orig, unarchived) - expectTrue(unarchived.dynamicType == NSError.self) + expectTrue(type(of: unarchived) == NSError.self) } } diff --git a/test/1_stdlib/Inputs/DictionaryKeyValueTypesObjC.swift b/test/1_stdlib/Inputs/DictionaryKeyValueTypesObjC.swift index 5f2867220a607..4b0612ec8cf51 100644 --- a/test/1_stdlib/Inputs/DictionaryKeyValueTypesObjC.swift +++ b/test/1_stdlib/Inputs/DictionaryKeyValueTypesObjC.swift @@ -34,18 +34,18 @@ func isCocoaDictionary( } func isNativeNSDictionary(_ d: NSDictionary) -> Bool { - let className: NSString = NSStringFromClass(d.dynamicType) as NSString + let className: NSString = NSStringFromClass(type(of: d)) as NSString return className.range(of: "_NativeDictionaryStorageOwner").length > 0 } func isCocoaNSDictionary(_ d: NSDictionary) -> Bool { - let className: NSString = NSStringFromClass(d.dynamicType) as NSString + let className: NSString = NSStringFromClass(type(of: d)) as NSString return className.range(of: "NSDictionary").length > 0 || className.range(of: "NSCFDictionary").length > 0 } func isNativeNSArray(_ d: NSArray) -> Bool { - let className: NSString = NSStringFromClass(d.dynamicType) as NSString + let className: NSString = NSStringFromClass(type(of: d)) as NSString return ["_SwiftDeferredNSArray", "_ContiguousArray", "_EmptyArray"].contains { className.range(of: $0).length > 0 } diff --git a/test/1_stdlib/Reflection_objc.swift b/test/1_stdlib/Reflection_objc.swift index e1a9cd214cb0b..04fe6ceb2d9f6 100644 --- a/test/1_stdlib/Reflection_objc.swift +++ b/test/1_stdlib/Reflection_objc.swift @@ -213,7 +213,7 @@ dump(CGRect(x: 50, y: 60, width: 100, height: 150)) @objc class CanaryBase { deinit { - print("\(self.dynamicType) overboard") + print("\(type(of: self)) overboard") } required init() { } diff --git a/test/1_stdlib/Runtime.swift.gyb b/test/1_stdlib/Runtime.swift.gyb index cde7a0fbb9b10..bb6ad4df6bdfc 100644 --- a/test/1_stdlib/Runtime.swift.gyb +++ b/test/1_stdlib/Runtime.swift.gyb @@ -317,26 +317,26 @@ Runtime.test("typeName") { expectEqual("Swift.Optional.Type", _typeName((AnyObject?).Type.self)) var a: Any = SomeClass() - expectEqual("a.SomeClass", _typeName(a.dynamicType)) + expectEqual("a.SomeClass", _typeName(type(of: a))) a = SomeStruct() - expectEqual("a.SomeStruct", _typeName(a.dynamicType)) + expectEqual("a.SomeStruct", _typeName(type(of: a))) a = SomeEnum() - expectEqual("a.SomeEnum", _typeName(a.dynamicType)) + expectEqual("a.SomeEnum", _typeName(type(of: a))) a = AnyObject.self - expectEqual("Swift.AnyObject.Protocol", _typeName(a.dynamicType)) + expectEqual("Swift.AnyObject.Protocol", _typeName(type(of: a))) a = AnyClass.self - expectEqual("Swift.AnyObject.Type.Protocol", _typeName(a.dynamicType)) + expectEqual("Swift.AnyObject.Type.Protocol", _typeName(type(of: a))) a = (AnyObject?).self expectEqual("Swift.Optional.Type", - _typeName(a.dynamicType)) + _typeName(type(of: a))) a = Any.self - expectEqual("Any.Protocol", _typeName(a.dynamicType)) + expectEqual("Any.Protocol", _typeName(type(of: a))) } class SomeSubclass : SomeClass {} diff --git a/test/1_stdlib/RuntimeObjC.swift b/test/1_stdlib/RuntimeObjC.swift index 6c8904fc752f6..3eeffa8b60975 100644 --- a/test/1_stdlib/RuntimeObjC.swift +++ b/test/1_stdlib/RuntimeObjC.swift @@ -313,13 +313,13 @@ Runtime.test("typeName") { expectEqual("NSObject", _typeName(NSObject.self)) var a : Any = SomeObjCClass() - expectEqual("a.SomeObjCClass", _typeName(a.dynamicType)) + expectEqual("a.SomeObjCClass", _typeName(type(of: a))) a = SomeNSObjectSubclass() - expectEqual("a.SomeNSObjectSubclass", _typeName(a.dynamicType)) + expectEqual("a.SomeNSObjectSubclass", _typeName(type(of: a))) a = NSObject() - expectEqual("NSObject", _typeName(a.dynamicType)) + expectEqual("NSObject", _typeName(type(of: a))) } class GenericClass {} @@ -816,7 +816,7 @@ Reflection.test("Name of metatype of artificial subclass") { obj.addObserver(obj, forKeyPath: "foo", options: [.new], context: &KVOHandle) obj.removeObserver(obj, forKeyPath: "foo") - expectEqual("\(obj.dynamicType)", "TestArtificialSubclass") + expectEqual("\(type(of: obj))", "TestArtificialSubclass") } @objc class StringConvertibleInDebugAndOtherwise : NSObject { diff --git a/test/1_stdlib/TypeName.swift b/test/1_stdlib/TypeName.swift index e3077abda0caf..eeefd78a5b5a1 100644 --- a/test/1_stdlib/TypeName.swift +++ b/test/1_stdlib/TypeName.swift @@ -145,15 +145,15 @@ TypeNameTests.test("Functions") { } expectEqual("(()) -> ()", - _typeName(curry1.dynamicType)) + _typeName(type(of: curry1))) expectEqual("(()) -> (()) -> ()", - _typeName(curry2.dynamicType)) + _typeName(type(of: curry2))) expectEqual("(()) throws -> (()) -> ()", - _typeName(curry2Throws.dynamicType)) + _typeName(type(of: curry2Throws))) expectEqual("(()) -> (()) throws -> ()", - _typeName(curry3.dynamicType)) + _typeName(type(of: curry3))) expectEqual("(()) throws -> (()) throws -> ()", - _typeName(curry3Throws.dynamicType)) + _typeName(type(of: curry3Throws))) } runAllTests() diff --git a/test/ClangModules/attr-swift_name.swift b/test/ClangModules/attr-swift_name.swift index 003131f7e17b0..0b02bffdb5daf 100644 --- a/test/ClangModules/attr-swift_name.swift +++ b/test/ClangModules/attr-swift_name.swift @@ -12,7 +12,7 @@ func test(_ i: Int) { t.theMethod(number: i) _ = t.renamedSomeProp - _ = t.dynamicType.renamedClassProp + _ = type(of: t).renamedClassProp // We only see these two warnings because Clang can catch the other invalid // cases, and marks the attribute as invalid ahead of time. diff --git a/test/ClangModules/objc_bridging_generics.swift b/test/ClangModules/objc_bridging_generics.swift index c941d88531abe..e4b5acdf3ebd5 100644 --- a/test/ClangModules/objc_bridging_generics.swift +++ b/test/ClangModules/objc_bridging_generics.swift @@ -187,8 +187,8 @@ extension AnimalContainer { _ = a.another() _ = x.another().another() - _ = x.dynamicType.create().another() - _ = x.dynamicType.init(noise: x).another() // expected-note{{here}} + _ = type(of: x).create().another() + _ = type(of: x).init(noise: x).another() // expected-note{{here}} _ = y.create().another() _ = y.init(noise: x).another() _ = y.init(noise: x.another()).another() @@ -204,8 +204,8 @@ extension AnimalContainer { } func doesntUseGenericParam4(_ x: T, _ y: T.Type) { - _ = x.dynamicType.apexPredator.another() - x.dynamicType.apexPredator = x + _ = type(of: x).apexPredator.another() + type(of: x).apexPredator = x _ = y.apexPredator.another() @@ -248,8 +248,8 @@ extension AnimalContainer { extension PettableContainer { // TODO: Any erasure shouldn't use generic parameter metadata. func doesntUseGenericParam(_ x: T, _ y: T.Type) { // expected-error{{cannot access the class's generic parameters}} - _ = x.dynamicType.init(fur: x).other() // expected-note{{here}} - _ = x.dynamicType.adopt().other() + _ = type(of: x).init(fur: x).other() // expected-note{{here}} + _ = type(of: x).adopt().other() _ = y.init(fur: x).other() _ = y.adopt().other() x.pet() diff --git a/test/ClangModules/objc_ir.swift b/test/ClangModules/objc_ir.swift index 6c71e71b3f150..79799199dacf1 100644 --- a/test/ClangModules/objc_ir.swift +++ b/test/ClangModules/objc_ir.swift @@ -119,7 +119,7 @@ func protocolMetatype(p: FooProto) -> FooProto.Type { // CHECK: [[SWIFT_RESULT:%.+]] = call %swift.type* @swift_getObjCClassMetadata(%objc_class* [[CASTED_RESULT]]) // CHECK: call void @swift_unknownRelease(%objc_object* %0) // CHECK: ret %swift.type* [[SWIFT_RESULT]] - let type = processFooType(p.dynamicType) + let type = processFooType(type(of: p)) return type } // CHECK: } @@ -136,7 +136,7 @@ func protocolCompositionMetatype(p: Impl) -> (FooProto & AnotherProto).Type { // CHECK: [[SWIFT_RESULT:%.+]] = call %swift.type* @swift_getObjCClassMetadata(%objc_class* [[CASTED_RESULT]]) // CHECK: call void bitcast (void (%swift.refcounted*)* @rt_swift_release to void (%C7objc_ir4Impl*)*)(%C7objc_ir4Impl* %0) // CHECK: ret %swift.type* [[SWIFT_RESULT]] - let type = processComboType(p.dynamicType) + let type = processComboType(type(of: p)) return type } // CHECK: } @@ -149,7 +149,7 @@ func protocolCompositionMetatype2(p: Impl) -> (FooProto & AnotherProto).Type { // CHECK: [[SWIFT_RESULT:%.+]] = call %swift.type* @swift_getObjCClassMetadata(%objc_class* [[CASTED_RESULT]]) // CHECK: call void bitcast (void (%swift.refcounted*)* @rt_swift_release to void (%C7objc_ir4Impl*)*)(%C7objc_ir4Impl* %0) // CHECK: ret %swift.type* [[SWIFT_RESULT]] - let type = processComboType2(p.dynamicType) + let type = processComboType2(type(of: p)) return type } // CHECK: } diff --git a/test/ClangModules/objc_parse.swift b/test/ClangModules/objc_parse.swift index 923409273f77b..0bf23c9db08d4 100644 --- a/test/ClangModules/objc_parse.swift +++ b/test/ClangModules/objc_parse.swift @@ -382,20 +382,20 @@ func testPropertyAndMethodCollision(_ obj: PropertyAndMethodCollision, obj.object = nil obj.object(obj, doSomething:#selector(getter: NSMenuItem.action)) - obj.dynamicType.classRef = nil - obj.dynamicType.classRef(obj, doSomething:#selector(getter: NSMenuItem.action)) + type(of: obj).classRef = nil + type(of: obj).classRef(obj, doSomething:#selector(getter: NSMenuItem.action)) rev.object = nil rev.object(rev, doSomething:#selector(getter: NSMenuItem.action)) - rev.dynamicType.classRef = nil - rev.dynamicType.classRef(rev, doSomething:#selector(getter: NSMenuItem.action)) + type(of: rev).classRef = nil + type(of: rev).classRef(rev, doSomething:#selector(getter: NSMenuItem.action)) var value: Any value = obj.protoProp() value = obj.protoPropRO() - value = obj.dynamicType.protoClassProp() - value = obj.dynamicType.protoClassPropRO() + value = type(of: obj).protoClassProp() + value = type(of: obj).protoClassPropRO() _ = value } diff --git a/test/Constraints/casts.swift b/test/Constraints/casts.swift index 6c797f0151343..4b08c8cdd699f 100644 --- a/test/Constraints/casts.swift +++ b/test/Constraints/casts.swift @@ -186,8 +186,8 @@ var f2: (B) -> Bool = { $0 is D } func metatype_casts(_ b: B.Type, t:T.Type, u: U.Type) { _ = b is D.Type _ = T.self is U.Type - _ = T.self.dynamicType is U.Type.Type - _ = b.dynamicType is D.Type // expected-warning{{always fails}} + _ = type(of: T.self) is U.Type.Type + _ = type(of: b) is D.Type // expected-warning{{always fails}} _ = b is D.Type.Type // expected-warning{{always fails}} } diff --git a/test/Constraints/dynamic_lookup.swift b/test/Constraints/dynamic_lookup.swift index 229eba1730537..116d90c2427ce 100644 --- a/test/Constraints/dynamic_lookup.swift +++ b/test/Constraints/dynamic_lookup.swift @@ -130,12 +130,12 @@ obj.ext1() // expected-warning {{result of call is unused}} obj.wonka() // Find class methods via dynamic method lookup. -obj.dynamicType.staticFoo!(5) -obj.dynamicType.staticWibble!() +type(of: obj).staticFoo!(5) +type(of: obj).staticWibble!() // Same as above but without the '!' -obj.dynamicType.staticFoo(5) -obj.dynamicType.staticWibble() +type(of: obj).staticFoo(5) +type(of: obj).staticWibble() // Overloading and ambiguity resolution @@ -205,7 +205,7 @@ class Z4 where T : AnyObject { } // Don't allow one to call instance methods on the Type via // dynamic method lookup. -obj.dynamicType.foo!(obj)(5) // expected-error{{instance member 'foo' cannot be used on type 'Id' (aka 'AnyObject')}} +type(of: obj).foo!(obj)(5) // expected-error{{instance member 'foo' cannot be used on type 'Id' (aka 'AnyObject')}} // Checked casts to AnyObject var p: P = Y() diff --git a/test/Constraints/existential_metatypes.swift b/test/Constraints/existential_metatypes.swift index 14db40095e508..bc776c11faecb 100644 --- a/test/Constraints/existential_metatypes.swift +++ b/test/Constraints/existential_metatypes.swift @@ -55,7 +55,7 @@ let g: Toaster.Type.Type = HairDryer.Type.self // expected-error {{cannot conver let h: WashingMachine.Type.Type = Dryer.Type.self // expected-error {{cannot convert value of type 'Dryer.Type.Type' to specified type 'WashingMachine.Type.Type'}} func generic(_ t: T.Type) { - let _: Toaster.Type.Type = t.dynamicType + let _: Toaster.Type.Type = type(of: t) } // rdar://problem/20780797 diff --git a/test/Constraints/generics.swift b/test/Constraints/generics.swift index df962a089d6d7..9bef0a2cef824 100644 --- a/test/Constraints/generics.swift +++ b/test/Constraints/generics.swift @@ -48,7 +48,7 @@ protocol SomeProtocol { func generic_metatypes(_ x: T) -> (T.Type, T.SomeAssociated.Type) { - return (x.dynamicType, x.dynamicType.SomeAssociated.self) + return (type(of: x), type(of: x).SomeAssociated.self) } // Inferring a variable's type from a call to a generic. diff --git a/test/Constraints/members.swift b/test/Constraints/members.swift index f6e504d03de40..b62dcdb8a9c74 100644 --- a/test/Constraints/members.swift +++ b/test/Constraints/members.swift @@ -258,7 +258,7 @@ func existential(_ p: P) { let _: () = id(p.bar(0)) // Static member of existential metatype) - let _: () -> () = id(p.dynamicType.tum) + let _: () -> () = id(type(of: p).tum) // Instance member of extension returning Self let _: () -> P = id(p.returnSelfInstance) diff --git a/test/DebugInfo/nostorage.swift b/test/DebugInfo/nostorage.swift index d8e16ba8052ed..8fd15ebe475a9 100644 --- a/test/DebugInfo/nostorage.swift +++ b/test/DebugInfo/nostorage.swift @@ -15,7 +15,7 @@ public class Foo { // CHECK1-SAME: type: ![[METAFOO:[0-9]+]] // CHECK1: ![[METAFOO]] = !DICompositeType(tag: DW_TAG_structure_type, // CHECK1-SAME: align: 8, flags: - let type = self.dynamicType + let type = type(of: self) used(type) }() } diff --git a/test/IDE/complete_constructor.swift b/test/IDE/complete_constructor.swift index c6c9ffc85fed4..fb1267b54fdad 100644 --- a/test/IDE/complete_constructor.swift +++ b/test/IDE/complete_constructor.swift @@ -198,14 +198,14 @@ func testGetInitFromMetatype2() { func testGetInitFromMetatype3() { var SS = ExplicitConstructorsBase1.self - SS.dynamicType.#^INIT_FROM_METATYPE3^# + type(of: SS).#^INIT_FROM_METATYPE3^# } // INIT_FROM_METATYPE3-NOT: Decl[Constructor]/CurrNominal: init()[#ExplicitConstructorsBase1#]{{; name=.+$}} func testGetInitFromMetatype4() { var a = ExplicitConstructorsDerived2() - a.dynamicType.#^INIT_FROM_METATYPE4^# + type(of: a).#^INIT_FROM_METATYPE4^# } // INIT_FROM_METATYPE4: Decl[Constructor]/CurrNominal: init({#a: Int#})[#ExplicitConstructorsDerived2#]; name=init(a: Int) diff --git a/test/IDE/complete_dynamic_lookup.swift b/test/IDE/complete_dynamic_lookup.swift index 8323654ab6aff..5a9e7b7a3ba38 100644 --- a/test/IDE/complete_dynamic_lookup.swift +++ b/test/IDE/complete_dynamic_lookup.swift @@ -491,9 +491,9 @@ func testAnyObject14() { } func testAnyObjectClassMethods1(_ dl: AnyObject) { - dl.dynamicType#^DL_CLASS_NO_DOT_1^# + type(of: dl)#^DL_CLASS_NO_DOT_1^# } func testAnyObjectClassMethods2(_ dl: AnyObject) { - dl.dynamicType.#^DL_CLASS_DOT_1^# + type(of: dl).#^DL_CLASS_DOT_1^# } diff --git a/test/IRGen/class_bounded_generics.swift b/test/IRGen/class_bounded_generics.swift index 3ed7cf887b755..5d0bb2901eec0 100644 --- a/test/IRGen/class_bounded_generics.swift +++ b/test/IRGen/class_bounded_generics.swift @@ -255,7 +255,7 @@ class SomeSwiftClass { // CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds void (%swift.type*)*, void (%swift.type*)** [[T2]], i64 10 // CHECK-NEXT: load void (%swift.type*)*, void (%swift.type*)** [[T3]], align 8 func class_bounded_metatype(_ t : T) { - t.dynamicType.foo() + type(of: t).foo() } class WeakRef { diff --git a/test/IRGen/concrete_inherits_generic_base.swift b/test/IRGen/concrete_inherits_generic_base.swift index 270b18b4c1665..062002c390891 100644 --- a/test/IRGen/concrete_inherits_generic_base.swift +++ b/test/IRGen/concrete_inherits_generic_base.swift @@ -15,7 +15,7 @@ class Base { } func present() { - print("\(self.dynamicType) \(T.self) \(first) \(second)") + print("\(type(of: self)) \(T.self) \(first) \(second)") } } diff --git a/test/IRGen/generic_metatypes.swift b/test/IRGen/generic_metatypes.swift index ea3f6292bb00e..82cc76415135c 100644 --- a/test/IRGen/generic_metatypes.swift +++ b/test/IRGen/generic_metatypes.swift @@ -17,7 +17,7 @@ func genericTypeof(_ x: T) -> T.Type { // CHECK: [[METATYPE:%.*]] = call %swift.type* @swift_getDynamicType(%swift.opaque* {{.*}}, %swift.type* [[TYPE]]) // CHECK: ret %swift.type* [[METATYPE]] - return x.dynamicType + return type(of: x) } struct Foo {} @@ -69,7 +69,7 @@ func protocolTypeof(_ x: Bas) -> Bas.Type { // CHECK: [[T0:%.*]] = insertvalue { %swift.type*, i8** } undef, %swift.type* [[METATYPE]], 0 // CHECK: [[T1:%.*]] = insertvalue { %swift.type*, i8** } [[T0]], i8** [[WTABLE]], 1 // CHECK: ret { %swift.type*, i8** } [[T1]] - return x.dynamicType + return type(of: x) } struct Zim : Bas {} diff --git a/test/IRGen/meta_meta_type.swift b/test/IRGen/meta_meta_type.swift index aa22ffbf2539b..b434a0f8a5590 100644 --- a/test/IRGen/meta_meta_type.swift +++ b/test/IRGen/meta_meta_type.swift @@ -17,7 +17,7 @@ struct Mystruct : Proto { // CHECKIR: [[R2:%[0-9]+]] = insertvalue {{.*}} [[R1]] // CHECKIR: ret { %swift.type*, i8** } [[R2]] func testit(_ p: Proto) -> Proto.Type.Type { - return p.dynamicType.dynamicType + return type(of: type(of: p)) } // CHECKIR-LABEL: define hidden {{.*}} @_TF14meta_meta_type7testit2FPS_5Proto_PMPMPMPS0__ @@ -28,7 +28,7 @@ func testit(_ p: Proto) -> Proto.Type.Type { // CHECKIR: [[R2:%[0-9]+]] = insertvalue {{.*}} [[R1]] // CHECKIR: ret { %swift.type*, i8** } [[R2]] func testit2(_ p: Proto) -> Proto.Type.Type.Type { - return p.dynamicType.dynamicType.dynamicType + return type(of: type(of: type(of: p))) } var tt = testit(Mystruct()) diff --git a/test/IRGen/metadata_dominance.swift b/test/IRGen/metadata_dominance.swift index 1e606ff6f1e6f..96846a051e0a9 100644 --- a/test/IRGen/metadata_dominance.swift +++ b/test/IRGen/metadata_dominance.swift @@ -73,7 +73,7 @@ class SubFoo: Foo { @inline(never) func testMakeFoo(_ p: P) -> Foo.Type { let foo = p.makeFoo() - return foo.dynamicType + return type(of: foo) } // The protocol witness for metadata_dominance.P.makeFoo () -> metadata_dominance.Foo in diff --git a/test/Interpreter/SDK/CoreFoundation_casting.swift b/test/Interpreter/SDK/CoreFoundation_casting.swift index 6ffaf7343d703..6c0715031a276 100644 --- a/test/Interpreter/SDK/CoreFoundation_casting.swift +++ b/test/Interpreter/SDK/CoreFoundation_casting.swift @@ -67,7 +67,7 @@ func testCFStringAnyObjectType() { let cfStr: CFString = CFStringCreateWithCString(nil, "Swift", CFStringBuiltInEncodings.ASCII.rawValue) - let cfStrType = cfStr.dynamicType + let cfStrType = type(of: cfStr) // CHECK: [[STRING_CLASS:(NS|CF).*String]] print(cfStrType) diff --git a/test/Interpreter/classes.swift b/test/Interpreter/classes.swift index 4b22e8be4b983..c7042c689272c 100644 --- a/test/Interpreter/classes.swift +++ b/test/Interpreter/classes.swift @@ -41,7 +41,7 @@ func -(a: Interval, b: Interval) -> Interval { } prefix func -(a: Interval) -> Interval { - return a.dynamicType.like(-a.hi, -a.lo) + return type(of: a).like(-a.hi, -a.lo) } // CHECK: [-2, -1] diff --git a/test/Interpreter/currying_protocols.swift b/test/Interpreter/currying_protocols.swift index da225d874e5bc..0ad9b016099a9 100644 --- a/test/Interpreter/currying_protocols.swift +++ b/test/Interpreter/currying_protocols.swift @@ -105,7 +105,7 @@ func olympicGames(_ g1: Gymnast) -> Gymnast { let f4: (Steroids) -> () = f3() f4(Steroids()) - let f5: () -> Int = g1.dynamicType.currentYear + let f5: () -> Int = type(of: g1).currentYear print(f5()) return g1 diff --git a/test/Interpreter/dynamic_lookup.swift b/test/Interpreter/dynamic_lookup.swift index 1e4c08005218f..3b748f65d2ed4 100644 --- a/test/Interpreter/dynamic_lookup.swift +++ b/test/Interpreter/dynamic_lookup.swift @@ -40,7 +40,7 @@ func test_dynamic_lookup_f(_ obj: AnyObject) { } func test_dynamic_lookup_g(_ obj: AnyObject) { - var og = obj.dynamicType.g + var og = type(of: obj).g if og != nil { og!() } else { diff --git a/test/Interpreter/generic_casts.swift b/test/Interpreter/generic_casts.swift index 2d0a7b2174d96..24e56e31cfa08 100644 --- a/test/Interpreter/generic_casts.swift +++ b/test/Interpreter/generic_casts.swift @@ -139,12 +139,12 @@ print(allMetasToAllMetas(C.self, D.self)) // CHECK: false print(C.self is D.Type) // CHECK: false print((D.self as C.Type) is D.Type) // CHECK: true -let t: Any.Type = (1 as Any).dynamicType +let t: Any.Type = type(of: 1 as Any) print(t is Int.Type) // CHECK: true print(t is Float.Type) // CHECK: false print(t is C.Type) // CHECK: false -let u: Any.Type = (D() as Any).dynamicType +let u: Any.Type = type(of: (D() as Any)) print(u is C.Type) // CHECK: true print(u is D.Type) // CHECK: true print(u is E.Type) // CHECK: false @@ -154,7 +154,7 @@ print(u is Int.Type) // CHECK: false // CHECK-LABEL: AnyObject casts: print("AnyObject casts:") print(allToAll(C(), AnyObject.self)) // CHECK-NEXT: true -print(allToAll(C().dynamicType, AnyObject.self)) // CHECK-NEXT: true +print(allToAll(type(of: C()), AnyObject.self)) // CHECK-NEXT: true // Bridging print(allToAll(0, AnyObject.self)) // CHECK-NEXT: true diff --git a/test/Interpreter/imported_objc_generics.swift b/test/Interpreter/imported_objc_generics.swift index 21c3e6df742a0..50d8ae3e866e2 100644 --- a/test/Interpreter/imported_objc_generics.swift +++ b/test/Interpreter/imported_objc_generics.swift @@ -17,8 +17,8 @@ var ImportedObjCGenerics = TestSuite("ImportedObjCGenerics") ImportedObjCGenerics.test("Creation") { let cs = Container(object: "i-just-met-you") expectEqual("i-just-met-you", cs.object) - expectTrue(cs.dynamicType === Container.self) - expectTrue(cs.dynamicType === Container.self) + expectTrue(type(of: cs) === Container.self) + expectTrue(type(of: cs) === Container.self) } ImportedObjCGenerics.test("Blocks") { @@ -139,7 +139,7 @@ ImportedObjCGenerics.test("InheritanceFromNongeneric") { // Test NSObject methods inherited into Container<> let gc = Container(object: "") expectTrue(gc.description.range(of: "Container") != nil) - expectTrue(gc.dynamicType.superclass() == NSObject.self) + expectTrue(type(of: gc).superclass() == NSObject.self) expectTrue(Container.superclass() == NSObject.self) expectTrue(Container.superclass() == NSObject.self) expectTrue(Container.self == Container.self) diff --git a/test/Interpreter/objc_class_properties.swift b/test/Interpreter/objc_class_properties.swift index 9281de6995637..b45d7a57edb6c 100644 --- a/test/Interpreter/objc_class_properties.swift +++ b/test/Interpreter/objc_class_properties.swift @@ -178,12 +178,12 @@ class NamingConflictSubclass : PropertyNamingConflict { ClassProperties.test("namingConflict") { let obj = PropertyNamingConflict() expectTrue(obj === obj.prop.map { $0 as AnyObject }) - expectEmpty(obj.dynamicType.prop) + expectEmpty(type(of: obj).prop) expectEmpty(PropertyNamingConflict.prop) let sub = NamingConflictSubclass() expectEmpty(sub.prop) - expectNotEmpty(sub.dynamicType.prop) + expectNotEmpty(type(of: sub).prop) expectNotEmpty(NamingConflictSubclass.prop) } @@ -201,7 +201,7 @@ extension NamingConflictSubclass : PropertyNamingConflictProto { ClassProperties.test("namingConflict/protocol") { let obj: PropertyNamingConflictProto = NamingConflictSubclass() expectTrue(obj === obj.protoProp.map { $0 as AnyObject }) - expectEmpty(obj.dynamicType.protoProp) + expectEmpty(type(of: obj).protoProp) let type: PropertyNamingConflictProto.Type = NamingConflictSubclass.self expectEmpty(type.protoProp) diff --git a/test/Interpreter/protocol_extensions.swift b/test/Interpreter/protocol_extensions.swift index 2997b62a06e9e..d3e8dbb33c05b 100644 --- a/test/Interpreter/protocol_extensions.swift +++ b/test/Interpreter/protocol_extensions.swift @@ -241,7 +241,7 @@ print(hasP.p.extValue) // rdar://problem/20739719 class Super: Init { - required init(x: Int) { print("\(x) \(self.dynamicType)") } + required init(x: Int) { print("\(x) \(type(of: self))") } } class Sub: Super {} diff --git a/test/Interpreter/repl.swift b/test/Interpreter/repl.swift index fc8b2bfa1f9be..f5e59850352dd 100644 --- a/test/Interpreter/repl.swift +++ b/test/Interpreter/repl.swift @@ -193,7 +193,7 @@ pr = "foo" // CHECK: String: foo pr.foo() -var _ : ([Int]).Type = [4].dynamicType +var _ : ([Int]).Type = type(of: [4]) // CHECK: : ([Int]).Type var _ : ((Int) -> Int)? = .none // CHECK: : ((Int) -> Int)? diff --git a/test/Interpreter/typeof.swift b/test/Interpreter/typeof.swift index 162e76dc78e90..678517de0f8a0 100644 --- a/test/Interpreter/typeof.swift +++ b/test/Interpreter/typeof.swift @@ -28,11 +28,11 @@ func archeMetatype(_ t: T.Type) { } func archeMetatype2(_ t: T) { - t.dynamicType.foo() + type(of: t).foo() } func boxedExistentialMetatype(_ e: Error) -> Error.Type { - return e.dynamicType + return type(of: e) } enum Hangry : Error { @@ -52,19 +52,19 @@ class Meltdown : Error { class GrilledCheese : Meltdown {} // CHECK: Beads? -classMetatype(B().dynamicType) +classMetatype(type(of: B())) // CHECK: Deeds? -classMetatype(D().dynamicType) +classMetatype(type(of: D())) // CHECK: Seeds? -structMetatype(S().dynamicType) +structMetatype(type(of: S())) // CHECK: Beads? -archeMetatype(B().dynamicType) +archeMetatype(type(of: B())) // FIXME: Deeds? -archeMetatype(D().dynamicType) +archeMetatype(type(of: D())) // CHECK: Seeds? -archeMetatype(S().dynamicType) +archeMetatype(type(of: S())) // CHECK: Beads? archeMetatype2(B()) diff --git a/test/NameBinding/reference-dependencies-dynamic-lookup.swift b/test/NameBinding/reference-dependencies-dynamic-lookup.swift index edf4dd10d2ff3..47ccaa9a2018b 100644 --- a/test/NameBinding/reference-dependencies-dynamic-lookup.swift +++ b/test/NameBinding/reference-dependencies-dynamic-lookup.swift @@ -43,7 +43,7 @@ func testDynamicLookup(_ obj: AnyObject) { obj.bar("abc") // CHECK-DAG: - !private "classFunc" - obj.dynamicType.classFunc() + type(of: obj).classFunc() // CHECK-DAG: - !private "prop" _ = obj.prop diff --git a/test/Parse/type_expr.swift b/test/Parse/type_expr.swift index 48db3b4047ebb..4c5826c833148 100644 --- a/test/Parse/type_expr.swift +++ b/test/Parse/type_expr.swift @@ -53,7 +53,7 @@ func unqualifiedType() { _ = Foo.instMeth _ = Foo // expected-error{{expected member name or constructor call after type name}} expected-note{{add arguments}} {{10-10=()}} expected-note{{use '.self'}} {{10-10=.self}} - _ = Foo.dynamicType // expected-error{{'.dynamicType' is not allowed after a type name}} {{11-22=self}} + _ = type(of: Foo) // expected-error{{'.dynamicType' is not allowed after a type name}} {{11-22=self}} _ = Bad // expected-error{{expected member name or constructor call after type name}} // expected-note@-1{{use '.self' to reference the type object}}{{10-10=.self}} @@ -70,7 +70,7 @@ func qualifiedType() { _ = Foo.Bar.instMeth _ = Foo.Bar // expected-error{{expected member name or constructor call after type name}} expected-note{{add arguments}} {{14-14=()}} expected-note{{use '.self'}} {{14-14=.self}} - _ = Foo.Bar.dynamicType // expected-error{{'.dynamicType' is not allowed after a type name}} {{15-26=self}} + _ = type(of: Foo.Bar) // expected-error{{'.dynamicType' is not allowed after a type name}} {{15-26=self}} } /* TODO allow '.Type' in expr context @@ -79,7 +79,7 @@ func metaType() { let metaTy = Foo.Type.self let badTy = Foo.Type - let badMetaTy = Foo.Type.dynamicType + let badMetaTy = type(of: Foo.Type) } */ @@ -106,7 +106,7 @@ func genQualifiedType() { _ = Gen.Bar.instMeth _ = Gen.Bar - _ = Gen.Bar.dynamicType + _ = type(of: Gen.Bar) } func archetype(_: T) { @@ -117,7 +117,7 @@ func archetype(_: T) { let _ : () = T.meth() _ = T // expected-error{{expected member name or constructor call after type name}} expected-note{{add arguments}} {{8-8=()}} expected-note{{use '.self'}} {{8-8=.self}} - _ = T.dynamicType // expected-error{{'.dynamicType' is not allowed after a type name}} {{9-20=self}} + _ = type(of: T) // expected-error{{'.dynamicType' is not allowed after a type name}} {{9-20=self}} } func assocType(_: T) where T.Zang: Zim { @@ -128,7 +128,7 @@ func assocType(_: T) where T.Zang: Zim { let _ : () = T.Zang.meth() _ = T.Zang // expected-error{{expected member name or constructor call after type name}} expected-note{{add arguments}} {{13-13=()}} expected-note{{use '.self'}} {{13-13=.self}} - _ = T.Zang.dynamicType // expected-error{{'.dynamicType' is not allowed after a type name}} {{14-25=self}} + _ = type(of: T.Zang) // expected-error{{'.dynamicType' is not allowed after a type name}} {{14-25=self}} } class B { @@ -149,7 +149,7 @@ func derivedType() { let _: B.Type = D // expected-error{{expected member name or constructor call after type name}} expected-note{{add arguments}} {{20-20=()}} expected-note{{use '.self'}} {{20-20=.self}} let _: D.Type = D // expected-error{{expected member name or constructor call after type name}} expected-note{{add arguments}} {{20-20=()}} expected-note{{use '.self'}} {{20-20=.self}} - let _: D.Type.Type = D.dynamicType // expected-error{{'.dynamicType' is not allowed after a type name}} {{26-37=self}} + let _: D.Type.Type = type(of: D) // expected-error{{'.dynamicType' is not allowed after a type name}} {{26-37=self}} } // Referencing a nonexistent member or constructor should not trigger errors diff --git a/test/PrintAsObjC/local-types.swift b/test/PrintAsObjC/local-types.swift index f85d8786aabc1..ca2729b56f5ad 100644 --- a/test/PrintAsObjC/local-types.swift +++ b/test/PrintAsObjC/local-types.swift @@ -61,7 +61,7 @@ class ANonObjCClass {} func f(_ f: (ZForwardProtocol3, ZForwardProtocol4) -> ZForwardProtocol5) {} func g(_ g: ZForwardProtocol6 & ZForwardProtocol7) {} - func h(_ h: ANonObjCClass) -> ANonObjCClass.Type { return h.dynamicType } + func h(_ h: ANonObjCClass) -> ANonObjCClass.Type { return type(of: h) } func i(_: ZForwardProtocol8) {} var j: ZForwardClass3 { return ZForwardClass3() } diff --git a/test/SILGen/dynamic.swift b/test/SILGen/dynamic.swift index ed59844909817..3225f5c99fb6e 100644 --- a/test/SILGen/dynamic.swift +++ b/test/SILGen/dynamic.swift @@ -406,7 +406,7 @@ func dynamicExtensionMethods(_ obj: ObjCOtherFile) { // CHECK: class_method [volatile] {{%.*}} : $@thick ObjCOtherFile.Type, #ObjCOtherFile.extensionClassProp!getter.1.foreign // CHECK-NEXT: thick_to_objc_metatype {{%.*}} : $@thick ObjCOtherFile.Type to $@objc_metatype ObjCOtherFile.Type - _ = obj.dynamicType.extensionClassProp + _ = type(of: obj).extensionClassProp // CHECK: class_method [volatile] {{%.*}} : $ObjCOtherFile, #ObjCOtherFile.dynExtensionMethod!1.foreign obj.dynExtensionMethod() @@ -415,7 +415,7 @@ func dynamicExtensionMethods(_ obj: ObjCOtherFile) { // CHECK: class_method [volatile] {{%.*}} : $@thick ObjCOtherFile.Type, #ObjCOtherFile.dynExtensionClassProp!getter.1.foreign // CHECK-NEXT: thick_to_objc_metatype {{%.*}} : $@thick ObjCOtherFile.Type to $@objc_metatype ObjCOtherFile.Type - _ = obj.dynamicType.dynExtensionClassProp + _ = type(of: obj).dynExtensionClassProp } public class Base { diff --git a/test/SILGen/dynamic_lookup.swift b/test/SILGen/dynamic_lookup.swift index c8f7018841ad2..3126ea4e6e964 100644 --- a/test/SILGen/dynamic_lookup.swift +++ b/test/SILGen/dynamic_lookup.swift @@ -49,7 +49,7 @@ func direct_to_static_method(_ obj: AnyObject) { // CHECK-NEXT: [[OPENMETA:%[0-9]+]] = open_existential_metatype [[OBJMETA]] : $@thick AnyObject.Type to $@thick (@opened([[UUID:".*"]]) AnyObject).Type // CHECK-NEXT: [[METHOD:%[0-9]+]] = dynamic_method [volatile] [[OPENMETA]] : $@thick (@opened([[UUID]]) AnyObject).Type, #X.staticF!1.foreign : (X.Type) -> () -> (), $@convention(objc_method) (@thick (@opened([[UUID]]) AnyObject).Type) -> () // CHECK: apply [[METHOD]]([[OPENMETA]]) : $@convention(objc_method) (@thick (@opened([[UUID]]) AnyObject).Type) -> () - obj.dynamicType.staticF!() + type(of: obj).staticF!() } // CHECK-LABEL: sil hidden @_TF14dynamic_lookup12opt_to_class @@ -120,7 +120,7 @@ func opt_to_static_method(_ obj: AnyObject) { // CHECK-NEXT: [[OBJCMETA:%[0-9]+]] = thick_to_objc_metatype [[OPENMETA]] // CHECK-NEXT: [[OPTTEMP:%.*]] = alloc_stack $ImplicitlyUnwrappedOptional<() -> ()> // CHECK-NEXT: dynamic_method_br [[OBJCMETA]] : $@objc_metatype (@opened({{".*"}}) AnyObject).Type, #X.staticF!1.foreign, [[HASMETHOD:[A-Za-z0-9_]+]], [[NOMETHOD:[A-Za-z0-9_]+]] - var optF: (() -> ())! = obj.dynamicType.staticF + var optF: (() -> ())! = type(of: obj).staticF } // CHECK-LABEL: sil hidden @_TF14dynamic_lookup15opt_to_property diff --git a/test/SILGen/existential_metatypes.swift b/test/SILGen/existential_metatypes.swift index 7cb6d31a4cd35..30b4479a8590a 100644 --- a/test/SILGen/existential_metatypes.swift +++ b/test/SILGen/existential_metatypes.swift @@ -14,7 +14,7 @@ struct S: P { // CHECK: bb0([[X:%.*]] : $*P): func existentialMetatype(_ x: P) { // CHECK: [[TYPE1:%.*]] = existential_metatype $@thick P.Type, [[X]] - let type1 = x.dynamicType + let type1 = type(of: x) // CHECK: [[INSTANCE1:%.*]] = alloc_stack $P // CHECK: [[OPEN_TYPE1:%.*]] = open_existential_metatype [[TYPE1]] // CHECK: [[INSTANCE1_VALUE:%.*]] = init_existential_addr [[INSTANCE1]] : $*P diff --git a/test/SILGen/expressions.swift b/test/SILGen/expressions.swift index 5e0a2f33e9087..6c9934d3d0b17 100644 --- a/test/SILGen/expressions.swift +++ b/test/SILGen/expressions.swift @@ -516,7 +516,7 @@ func testDiscardLValue() { func dynamicTypePlusZero(_ a : Super1) -> Super1.Type { - return a.dynamicType + return type(of: a) } // CHECK-LABEL: dynamicTypePlusZero // CHECK: bb0(%0 : $Super1): @@ -526,7 +526,7 @@ func dynamicTypePlusZero(_ a : Super1) -> Super1.Type { struct NonTrivialStruct { var c : Super1 } func dontEmitIgnoredLoadExpr(_ a : NonTrivialStruct) -> NonTrivialStruct.Type { - return a.dynamicType + return type(of: a) } // CHECK-LABEL: dontEmitIgnoredLoadExpr // CHECK: bb0(%0 : $NonTrivialStruct): diff --git a/test/SILGen/functions.swift b/test/SILGen/functions.swift index e541f1c455540..f18f595a68693 100644 --- a/test/SILGen/functions.swift +++ b/test/SILGen/functions.swift @@ -167,7 +167,7 @@ func calls(_ i:Int, j:Int, k:Int) { // CHECK: [[METHOD:%[0-9]+]] = class_method [[META:%[0-9]+]] : {{.*}}, #SomeClass.static_method!1 // CHECK: [[I:%[0-9]+]] = load [[IADDR]] // CHECK: apply [[METHOD]]([[I]], [[META]]) - c.dynamicType.static_method(i) + type(of: c).static_method(i) // -- Curry property accesses. @@ -227,7 +227,7 @@ func calls(_ i:Int, j:Int, k:Int) { // FIXME: [[I:%[0-9]+]] = load [[IADDR]] // FIXME: apply [[PMETHOD]]([[I]], [[PMETA]]) // Needs existential metatypes - //p.dynamicType.static_method(i) + //type(of: p).static_method(i) // -- Use an apply or partial_apply instruction to bind type parameters of a generic. diff --git a/test/SILGen/metatype_abstraction.swift b/test/SILGen/metatype_abstraction.swift index b4f70917ce229..a702deaab8a63 100644 --- a/test/SILGen/metatype_abstraction.swift +++ b/test/SILGen/metatype_abstraction.swift @@ -110,30 +110,30 @@ func genericMetatypeToGenericMetatype(_ x: U.Type) { // CHECK-LABEL: sil hidden @_TFs27static_metatype_of_metatypeFVs1SMMS_ // CHECK: metatype $@thin S.Type.Type func static_metatype_of_metatype(_ x: S) -> S.Type.Type { - return x.dynamicType.dynamicType + return type(of: type(of: x)) } // CHECK-LABEL: sil hidden @_TFs26class_metatype_of_metatypeFCs1CMMS_ // CHECK: [[METATYPE:%.*]] = value_metatype $@thick C.Type // CHECK: [[META_METATYPE:%.*]] = value_metatype $@thick C.Type.Type, [[METATYPE]] func class_metatype_of_metatype(_ x: C) -> C.Type.Type { - return x.dynamicType.dynamicType + return type(of: type(of: x)) } // CHECK-LABEL: sil hidden @_TFs28generic_metatype_of_metatype // CHECK: [[METATYPE:%.*]] = value_metatype $@thick T.Type // CHECK: [[META_METATYPE:%.*]] = value_metatype $@thick T.Type.Type, [[METATYPE]] func generic_metatype_of_metatype(_ x: T) -> T.Type.Type { - return x.dynamicType.dynamicType + return type(of: type(of: x)) } // FIXME rdar://problem/18419772 /* func existential_metatype_of_metatype(_ x: Any) -> Any.Type.Type { - return x.dynamicType.dynamicType + return type(of: type(of: x)) } */ func function_metatype_of_metatype(_ x: @escaping () -> ()) -> (() -> ()).Type.Type { - return x.dynamicType.dynamicType + return type(of: type(of: x)) } diff --git a/test/SILGen/metatypes.swift b/test/SILGen/metatypes.swift index 125ba680865b3..c99eb8e69bbf8 100644 --- a/test/SILGen/metatypes.swift +++ b/test/SILGen/metatypes.swift @@ -38,7 +38,7 @@ func struct_metatypes(s: SomeStruct) // CHECK: [[STRUCT1:%[0-9]+]] = metatype $@thin SomeStruct.Type // CHECK: [[STRUCT2:%[0-9]+]] = metatype $@thin SomeStruct.Type // CHECK: tuple ([[STRUCT1]] : {{.*}}, [[STRUCT2]] : {{.*}}) - return (s.dynamicType, SomeStruct.self) + return (type(of: s), SomeStruct.self) } // CHECK-LABEL: sil hidden @_TF9metatypes15class_metatypes @@ -49,7 +49,7 @@ func class_metatypes(c: SomeClass, s: SomeSubclass) // CHECK: [[SUBCLASS:%[0-9]+]] = value_metatype $@thick SomeSubclass.Type, // CHECK: [[SUBCLASS_UPCAST:%[0-9]+]] = upcast [[SUBCLASS]] : ${{.*}} to $@thick SomeClass.Type // CHECK: tuple ([[CLASS]] : {{.*}}, [[SUBCLASS_UPCAST]] : {{.*}}) - return (c.dynamicType, s.dynamicType) + return (type(of: c), type(of: s)) } // CHECK-LABEL: sil hidden @_TF9metatypes19archetype_metatypes @@ -58,13 +58,13 @@ func archetype_metatypes(t: T) -> (T.Type, T.Type) { // CHECK: [[STATIC_T:%[0-9]+]] = metatype $@thick T.Type // CHECK: [[DYN_T:%[0-9]+]] = value_metatype $@thick T.Type, %0 // CHECK: tuple ([[STATIC_T]] : {{.*}}, [[DYN_T]] : {{.*}}) - return (T.self, t.dynamicType) + return (T.self, type(of: t)) } // CHECK-LABEL: sil hidden @_TF9metatypes21existential_metatypes func existential_metatypes(p: SomeProtocol) -> SomeProtocol.Type { // CHECK: existential_metatype $@thick SomeProtocol.Type - return p.dynamicType + return type(of: p) } struct SomeGenericStruct {} @@ -99,7 +99,7 @@ func existential_metatype_from_thin() -> Any.Type { // CHECK-NEXT: return [[T2]] : $@thick Any.Type func existential_metatype_from_thin_value() -> Any.Type { let s = SomeStruct() - return s.dynamicType + return type(of: s) } // CHECK-LABEL: sil hidden @_TF9metatypes20specialized_metatypeFT_GVs10DictionarySSSi_ diff --git a/test/SILGen/optional_chain_addressor.swift b/test/SILGen/optional_chain_addressor.swift index c47d024d9c06e..414dd19c6a1c2 100644 --- a/test/SILGen/optional_chain_addressor.swift +++ b/test/SILGen/optional_chain_addressor.swift @@ -2,5 +2,5 @@ func foo(x: UnsafeMutablePointer?>) { _ = x.pointee?.pointee - _ = x.pointee?.dynamicType + _ = type(of: x.pointee?) } diff --git a/test/SILOptimizer/cast_folding.swift b/test/SILOptimizer/cast_folding.swift index ef8b96b4d1459..de05050c8eeab 100644 --- a/test/SILOptimizer/cast_folding.swift +++ b/test/SILOptimizer/cast_folding.swift @@ -37,29 +37,29 @@ class E: CP1, CP2 {} func cast0(_ a:T) -> Bool { // Succeeds if T is A - return A().dynamicType is T.Type + return type(of: A()) is T.Type } func cast1(_ a:T) -> Bool { // Succeeds if T is A - return (A() as AnyObject).dynamicType is T.Type + return type(of: (A() as AnyObject)) is T.Type } func cast2(_ a:T) -> Bool { // Succeeds if T is A let ao:AnyObject = A() as AnyObject - return ao.dynamicType is T.Type + return type(of: ao) is T.Type } func cast3(_ p:AnyObject) -> Bool { // Always fails - return p.dynamicType is AnyObject.Protocol + return type(of: p) is AnyObject.Protocol } func cast4(_ p:AnyObject) -> Bool { - return p.dynamicType is A.Type + return type(of: p) is A.Type } func cast5(_ t:AnyObject.Type) -> Bool { @@ -80,23 +80,23 @@ func cast7(_ t:T.Type) -> Bool { func cast8(_ a:T) -> Bool { // Succeeds if T is A - return (A() as P).dynamicType is T.Type + return type(of: (A() as P)) is T.Type } func cast9(_ a:T) -> Bool { // Succeeds if T is A let ao:P = A() as P - return ao.dynamicType is T.Type + return type(of: ao) is T.Type } func cast10(_ p:P) -> Bool { - return p.dynamicType is P.Protocol + return type(of: p) is P.Protocol } func cast11(_ p:P) -> Bool { // Succeeds if p is of type A - return p.dynamicType is A.Type + return type(of: p) is A.Type } func cast12(_ t:P.Type) -> Bool { diff --git a/test/SILOptimizer/definite_init_failable_initializers.swift b/test/SILOptimizer/definite_init_failable_initializers.swift index 3dbb0dec6d3f3..c117289a43a4a 100644 --- a/test/SILOptimizer/definite_init_failable_initializers.swift +++ b/test/SILOptimizer/definite_init_failable_initializers.swift @@ -1504,7 +1504,7 @@ extension P2 { } //// -// self.dynamicType with uninitialized self +// type(of: self) with uninitialized self //// func use(_ a : Any) {} @@ -1513,24 +1513,24 @@ class DynamicTypeBase { var x: Int init() { - use(self.dynamicType) + use(type(of: self)) x = 0 } convenience init(a : Int) { - use(self.dynamicType) + use(type(of: self)) self.init() } } class DynamicTypeDerived : DynamicTypeBase { override init() { - use(self.dynamicType) + use(type(of: self)) super.init() } convenience init(a : Int) { - use(self.dynamicType) + use(type(of: self)) self.init() } } @@ -1539,12 +1539,12 @@ struct DynamicTypeStruct { var x: Int init() { - use(self.dynamicType) + use(type(of: self)) x = 0 } init(a : Int) { - use(self.dynamicType) + use(type(of: self)) self.init() } } diff --git a/test/SILOptimizer/definite_init_failable_initializers_diagnostics.swift b/test/SILOptimizer/definite_init_failable_initializers_diagnostics.swift index 84232e56568a3..453a5b2a46b2f 100644 --- a/test/SILOptimizer/definite_init_failable_initializers_diagnostics.swift +++ b/test/SILOptimizer/definite_init_failable_initializers_diagnostics.swift @@ -91,7 +91,7 @@ class ErrantClass : ErrantBaseClass { something(self) // expected-error {{'self' used inside 'catch' block reachable from self.init call}} // FIXME: not diagnosed - something(self.dynamicType) + something(type(of: self)) throw e } diff --git a/test/SILOptimizer/devirt_unbound_generic.swift b/test/SILOptimizer/devirt_unbound_generic.swift index d4d4ae0b1a71e..36b40d2bbb123 100644 --- a/test/SILOptimizer/devirt_unbound_generic.swift +++ b/test/SILOptimizer/devirt_unbound_generic.swift @@ -67,7 +67,7 @@ public func doTest2(_ t:T) { // CHECK: return @inline(never) func test3(_ d: Derived) { - d.dynamicType.boo() + type(of: d).boo() } public func doTest3(_ t:T) { diff --git a/test/SILOptimizer/devirt_value_metatypes.swift b/test/SILOptimizer/devirt_value_metatypes.swift index f621ed0f5ffcd..00e16caacbb6f 100644 --- a/test/SILOptimizer/devirt_value_metatypes.swift +++ b/test/SILOptimizer/devirt_value_metatypes.swift @@ -19,7 +19,7 @@ class B: A { // CHECK: class_method // CHECK: } public func testValueMetatype(_ x:A) { - x.dynamicType.foo() + type(of: x).foo() } public class C { @@ -42,7 +42,7 @@ public class D : C { // CHECK-NOT: class_method // CHECK: } public func testD(_ x: D) -> Int { - return (x.dynamicType as C.Type).foo() + return (type(of: x) as C.Type).foo() } @@ -58,5 +58,5 @@ public final class E : C { // CHECK: apply // CHECK: return public func testE(_ x: E) -> Int { - return (x.dynamicType as C.Type).foo() + return (type(of: x) as C.Type).foo() } diff --git a/test/Sanitizers/tsan-type-metadata.swift b/test/Sanitizers/tsan-type-metadata.swift index 32ad3ff3f3c6a..a9c3bde917e03 100644 --- a/test/Sanitizers/tsan-type-metadata.swift +++ b/test/Sanitizers/tsan-type-metadata.swift @@ -42,7 +42,7 @@ class Base { second = x } func present() { - print("\(self.dynamicType) \(T.self) \(first) \(second)") + print("\(type(of: self)) \(T.self) \(first) \(second)") } } class SuperDerived: Derived { diff --git a/test/Sanitizers/witness_table_lookup.swift b/test/Sanitizers/witness_table_lookup.swift index 55d9f54a3e08f..055cea173745a 100644 --- a/test/Sanitizers/witness_table_lookup.swift +++ b/test/Sanitizers/witness_table_lookup.swift @@ -27,7 +27,7 @@ protocol P { associatedtype E : Q, Q2 } struct B : Q, Q2 { - static func foo() { consume(self.dynamicType) } + static func foo() { consume(type(of: self)) } } struct A : P { typealias E = B @@ -37,10 +37,10 @@ func foo(_ t: T) { T.E.foo() } struct EasyType : Q, Q2 { - static func foo() { consume(self.dynamicType) } + static func foo() { consume(type(of: self)) } } extension Int : Q, Q2 { - static func foo() { consume(self.dynamicType) } + static func foo() { consume(type(of: self)) } } // Execute concurrently. diff --git a/test/decl/func/dynamic_self.swift b/test/decl/func/dynamic_self.swift index ec917b205931d..6a30d398796b2 100644 --- a/test/decl/func/dynamic_self.swift +++ b/test/decl/func/dynamic_self.swift @@ -69,8 +69,8 @@ class C1 { // FIXME: below diagnostic should complain about C1 -> Self conversion if b { return C1(int: 5) } // expected-error{{cannot convert return expression of type 'C1' to return type 'Self'}} - // One can use .dynamicType to attempt to construct an object of type Self. - if !b { return self.dynamicType.init(int: 5) } + // One can use `type(of:)` to attempt to construct an object of type Self. + if !b { return type(of: self).init(int: 5) } // Can't utter Self within the body of a method. var _: Self = self // expected-error{{'Self' is only available in a protocol or as the result of a method in a class; did you mean 'C1'?}} {{12-16=C1}} diff --git a/test/decl/func/rethrows.swift b/test/decl/func/rethrows.swift index be27a971625b2..60fdc595b36ef 100644 --- a/test/decl/func/rethrows.swift +++ b/test/decl/func/rethrows.swift @@ -225,10 +225,10 @@ func testProtoMethodCallUnhandled(_ s: MyProto) { s.call(raise) // expected-error {{call can throw, but it is not marked with 'try' and the error is not handled}} expected-note {{call is to 'rethrows' function, but argument function can throw}} try s.call(raise) // expected-error {{call can throw, but the error is not handled}} expected-note {{call is to 'rethrows' function, but argument function can throw}} - s.dynamicType.static_call(noraise) - try s.dynamicType.static_call(noraise) // expected-warning {{no calls to throwing functions occur within 'try'}} - s.dynamicType.static_call(raise) // expected-error {{call can throw, but it is not marked with 'try' and the error is not handled}} expected-note {{call is to 'rethrows' function, but argument function can throw}} - try s.dynamicType.static_call(raise) // expected-error {{call can throw, but the error is not handled}} expected-note {{call is to 'rethrows' function, but argument function can throw}} + type(of: s).static_call(noraise) + try type(of: s).static_call(noraise) // expected-warning {{no calls to throwing functions occur within 'try'}} + type(of: s).static_call(raise) // expected-error {{call can throw, but it is not marked with 'try' and the error is not handled}} expected-note {{call is to 'rethrows' function, but argument function can throw}} + try type(of: s).static_call(raise) // expected-error {{call can throw, but the error is not handled}} expected-note {{call is to 'rethrows' function, but argument function can throw}} } func testProtoMethodCallHandled(_ s: MyProto) throws { @@ -237,10 +237,10 @@ func testProtoMethodCallHandled(_ s: MyProto) throws { s.call(raise) // expected-error {{call can throw but is not marked with 'try'}} expected-note {{call is to 'rethrows' function, but argument function can throw}} try s.call(raise) - s.dynamicType.static_call(noraise) - try s.dynamicType.static_call(noraise) // expected-warning {{no calls to throwing functions occur within 'try'}} - s.dynamicType.static_call(raise) // expected-error {{call can throw but is not marked with 'try'}} expected-note {{call is to 'rethrows' function, but argument function can throw}} - try s.dynamicType.static_call(raise) + type(of: s).static_call(noraise) + try type(of: s).static_call(noraise) // expected-warning {{no calls to throwing functions occur within 'try'}} + type(of: s).static_call(raise) // expected-error {{call can throw but is not marked with 'try'}} expected-note {{call is to 'rethrows' function, but argument function can throw}} + try type(of: s).static_call(raise) } func testProtoMethodCallACUnhandled(_ s: MyProto) { @@ -251,12 +251,12 @@ func testProtoMethodCallACUnhandled(_ s: MyProto) { // expected-note {{call is to 'rethrows' function, but argument function can throw}} try s.callAC(raise()) // expected-error {{call can throw, but the error is not handled}} expected-note {{call is to 'rethrows' function, but argument function can throw}} - s.dynamicType.static_callAC(noraise()) - try s.dynamicType.static_callAC(noraise()) // expected-warning {{no calls to throwing functions occur within 'try'}} - s.dynamicType.static_callAC(raise()) // expected-error {{call can throw but is not marked with 'try'}} \ + type(of: s).static_callAC(noraise()) + try type(of: s).static_callAC(noraise()) // expected-warning {{no calls to throwing functions occur within 'try'}} + type(of: s).static_callAC(raise()) // expected-error {{call can throw but is not marked with 'try'}} \ // expected-error {{call can throw, but it is not marked with 'try' and the error is not handled}} \ // expected-note {{call is to 'rethrows' function, but argument function can throw}} - try s.dynamicType.static_callAC(raise()) // expected-error {{call can throw, but the error is not handled}} expected-note {{call is to 'rethrows' function, but argument function can throw}} + try type(of: s).static_callAC(raise()) // expected-error {{call can throw, but the error is not handled}} expected-note {{call is to 'rethrows' function, but argument function can throw}} } func testProtoMethodCallACHandled(_ s: MyProto) throws { @@ -265,10 +265,10 @@ func testProtoMethodCallACHandled(_ s: MyProto) throws { s.callAC(raise()) // expected-error 2 {{call can throw but is not marked with 'try'}} expected-note {{call is to 'rethrows' function, but argument function can throw}} try s.callAC(raise()) - s.dynamicType.static_callAC(noraise()) - try s.dynamicType.static_callAC(noraise()) // expected-warning {{no calls to throwing functions occur within 'try'}} - s.dynamicType.static_callAC(raise()) // expected-error 2 {{call can throw but is not marked with 'try'}} expected-note {{call is to 'rethrows' function, but argument function can throw}} - try s.dynamicType.static_callAC(raise()) + type(of: s).static_callAC(noraise()) + try type(of: s).static_callAC(noraise()) // expected-warning {{no calls to throwing functions occur within 'try'}} + type(of: s).static_callAC(raise()) // expected-error 2 {{call can throw but is not marked with 'try'}} expected-note {{call is to 'rethrows' function, but argument function can throw}} + try type(of: s).static_callAC(raise()) } /** Generics **/ diff --git a/test/decl/protocol/req/recursion.swift b/test/decl/protocol/req/recursion.swift index b01591db725aa..9b8bf89611197 100644 --- a/test/decl/protocol/req/recursion.swift +++ b/test/decl/protocol/req/recursion.swift @@ -8,7 +8,7 @@ extension SomeProtocol where T == Optional { } // expected-error{{same-type c // rdar://problem/19840527 class X where T == X { // expected-error{{same-type requirement makes generic parameter 'T' non-generic}} - var type: T { return self.dynamicType } // expected-error{{cannot convert return expression of type 'X.Type' to return type 'T'}} + var type: T { return type(of: self) } // expected-error{{cannot convert return expression of type 'X.Type' to return type 'T'}} } protocol Y { diff --git a/test/expr/postfix/dot/init_ref_delegation.swift b/test/expr/postfix/dot/init_ref_delegation.swift index 7e4e215c0acc0..0dac223a1d256 100644 --- a/test/expr/postfix/dot/init_ref_delegation.swift +++ b/test/expr/postfix/dot/init_ref_delegation.swift @@ -113,7 +113,7 @@ class Z4 { convenience init(other: Z4) { other.init() // expected-error{{'init' is a member of the type; insert '.dynamicType' to initialize a new object of the same dynamic type}} {{10-10=.dynamicType}} - other.dynamicType.init() // expected-error{{must use a 'required' initializer}} expected-warning{{unused}} + type(of: other).init() // expected-error{{must use a 'required' initializer}} expected-warning{{unused}} } } @@ -151,7 +151,7 @@ struct RDar16603812 { init() {} func foo() { self.init() // expected-error {{'init' is a member of the type; insert '.dynamicType' to initialize a new object of the same dynamic type}} {{11-11=.dynamicType}} - self.dynamicType.init() // expected-warning{{result of 'RDar16603812' initializer is unused}} + type(of: self).init() // expected-warning{{result of 'RDar16603812' initializer is unused}} } } @@ -255,20 +255,20 @@ protocol P { } func foo(_ x: T, y: T.Type) where T: P { - var c1 = x.dynamicType.init(required: 0) - var c2 = x.dynamicType.init(x: 0) // expected-error{{'required' initializer}} - var c3 = x.dynamicType.init() // expected-error{{'required' initializer}} - var c4 = x.dynamicType.init(proto: "") - - var cf1: (Double) -> T = x.dynamicType.init - var cf2: (Int) -> T = x.dynamicType.init // expected-error{{'required' initializer}} - var cf3: () -> T = x.dynamicType.init // expected-error{{'required' initializer}} - var cf4: (String) -> T = x.dynamicType.init - - var c1a = x.dynamicType.init(required: 0) - var c2a = x.dynamicType.init(x: 0) // expected-error{{'required' initializer}} - var c3a = x.dynamicType.init() // expected-error{{'required' initializer}} - var c4a = x.dynamicType.init(proto: "") + var c1 = type(of: x).init(required: 0) + var c2 = type(of: x).init(x: 0) // expected-error{{'required' initializer}} + var c3 = type(of: x).init() // expected-error{{'required' initializer}} + var c4 = type(of: x).init(proto: "") + + var cf1: (Double) -> T = type(of: x).init + var cf2: (Int) -> T = type(of: x).init // expected-error{{'required' initializer}} + var cf3: () -> T = type(of: x).init // expected-error{{'required' initializer}} + var cf4: (String) -> T = type(of: x).init + + var c1a = type(of: x).init(required: 0) + var c2a = type(of: x).init(x: 0) // expected-error{{'required' initializer}} + var c3a = type(of: x).init() // expected-error{{'required' initializer}} + var c4a = type(of: x).init(proto: "") var ci1 = x.init(required: 0) // expected-error{{'init' is a member of the type; insert '.dynamicType' to initialize a new object of the same dynamic type}} {{14-14=.dynamicType}} var ci2 = x.init(x: 0) // expected-error{{'init' is a member of the type; insert '.dynamicType' to initialize a new object of the same dynamic type}} {{14-14=.dynamicType}} diff --git a/test/expr/unary/selector/selector.swift b/test/expr/unary/selector/selector.swift index 9b67a5777948f..2ce61993eecc4 100644 --- a/test/expr/unary/selector/selector.swift +++ b/test/expr/unary/selector/selector.swift @@ -65,8 +65,8 @@ func testSelector(_ c1: C1, p1: P1, obj: AnyObject) { _ = #selector(P1.method5(_:b:)) // expected-error{{static member 'method5(_:b:)' cannot be used on protocol metatype 'P1.Protocol'}} _ = #selector(p1.method4) _ = #selector(p1.method4(_:b:)) - _ = #selector(p1.dynamicType.method5) - _ = #selector(p1.dynamicType.method5(_:b:)) + _ = #selector(type(of: p1).method5) + _ = #selector(type(of: p1).method5(_:b:)) // Interesting expressions that refer to methods. _ = #selector(Swift.AnyObject.method1) diff --git a/test/stmt/errors.swift b/test/stmt/errors.swift index d1527ad18cad1..bee61d8d4778f 100644 --- a/test/stmt/errors.swift +++ b/test/stmt/errors.swift @@ -104,7 +104,7 @@ protocol ThrowingProto { func testExistential(_ p : ThrowingProto) throws { try p.foo() - try p.dynamicType.bar() + try type(of: p).bar() } func testGeneric

(p : P) throws { try p.foo() diff --git a/test/type/metatype/metatypes.swift b/test/type/metatype/metatypes.swift index 6917a792565c7..6aae31ba448b1 100644 --- a/test/type/metatype/metatypes.swift +++ b/test/type/metatype/metatypes.swift @@ -17,4 +17,4 @@ Test1b.foo() var test1 = Test1a.self test1 = Test1b.self var x = Test1b() -test1 = x.dynamicType +test1 = type(of: x) diff --git a/validation-test/stdlib/IOKitOverlay.swift b/validation-test/stdlib/IOKitOverlay.swift index 8c4494d92a345..9c057a71f0da2 100644 --- a/validation-test/stdlib/IOKitOverlay.swift +++ b/validation-test/stdlib/IOKitOverlay.swift @@ -18,7 +18,7 @@ IOKitTests.test("IOReturn value") { IOKitTests.test("IOReturn type") { let manager = IOHIDManagerCreate(nil, 0) let result = IOHIDManagerClose(manager, 0) - expectTrue(result.dynamicType == kIOReturnNotOpen.dynamicType) + expectTrue(type(of: result) == type(of: kIOReturnNotOpen)) } runAllTests() diff --git a/validation-test/stdlib/Set.swift b/validation-test/stdlib/Set.swift index d48239faa371d..88456d3e7b313 100644 --- a/validation-test/stdlib/Set.swift +++ b/validation-test/stdlib/Set.swift @@ -137,12 +137,12 @@ func isNativeSet(_ s: Set) -> Bool { #if _runtime(_ObjC) func isNativeNSSet(_ s: NSSet) -> Bool { - let className: NSString = NSStringFromClass(s.dynamicType) as NSString + let className: NSString = NSStringFromClass(type(of: s)) as NSString return className.range(of: "NativeSetStorage").length > 0 } func isCocoaNSSet(_ s: NSSet) -> Bool { - let className: NSString = NSStringFromClass(s.dynamicType) as NSString + let className: NSString = NSStringFromClass(type(of: s)) as NSString return className.range(of: "NSSet").length > 0 || className.range(of: "NSCFSet").length > 0 } From 80fb5c1c5a2dd321b2bf4c89c0b476a4b8a1ea5b Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Fri, 29 Jul 2016 12:54:28 -0700 Subject: [PATCH 4/4] Remove usage of getMetatypeLoc() --- include/swift/AST/DiagnosticsSema.def | 2 - include/swift/AST/Expr.h | 26 ++++++---- include/swift/Parse/Tokens.def | 4 +- lib/FrontendTool/FrontendTool.cpp | 2 +- lib/Parse/ParseExpr.cpp | 48 +++++++++++++------ lib/Sema/MiscDiagnostics.cpp | 10 +--- test/Parse/type_expr.swift | 17 +++---- test/SILGen/optional_chain_addressor.swift | 2 +- test/SILOptimizer/cast_folding.swift | 2 +- .../postfix/dot/init_ref_delegation.swift | 18 +++---- 10 files changed, 71 insertions(+), 60 deletions(-) diff --git a/include/swift/AST/DiagnosticsSema.def b/include/swift/AST/DiagnosticsSema.def index c6ab6ea72153e..5b3a19f2c63ea 100644 --- a/include/swift/AST/DiagnosticsSema.def +++ b/include/swift/AST/DiagnosticsSema.def @@ -2271,8 +2271,6 @@ WARNING(optional_pattern_match_promotion,none, (Type, Type)) -ERROR(type_of_metatype,none, - "'.dynamicType' is not allowed after a type name", ()) ERROR(invalid_noescape_use,none, "non-escaping %select{value|parameter}1 %0 may only be called", (Identifier, bool)) diff --git a/include/swift/AST/Expr.h b/include/swift/AST/Expr.h index 0bda3d18bdf8c..62e9d59c3f9dd 100644 --- a/include/swift/AST/Expr.h +++ b/include/swift/AST/Expr.h @@ -3519,28 +3519,34 @@ class AutoClosureExpr : public AbstractClosureExpr { /// DynamicTypeExpr - "type(of: base)" - Produces a metatype value. /// -/// The metatype value can comes from evaluating an expression and then -/// getting its metatype. +/// The metatype value comes from evaluating an expression then retrieving the +/// metatype of the result. class DynamicTypeExpr : public Expr { + SourceLoc KeywordLoc; + SourceLoc LParenLoc; Expr *Base; - SourceLoc MetatypeLoc; + SourceLoc RParenLoc; public: - explicit DynamicTypeExpr(Expr *Base, SourceLoc MetatypeLoc, Type Ty) + explicit DynamicTypeExpr(SourceLoc KeywordLoc, SourceLoc LParenLoc, + Expr *Base, SourceLoc RParenLoc, Type Ty) : Expr(ExprKind::DynamicType, /*Implicit=*/false, Ty), - Base(Base), MetatypeLoc(MetatypeLoc) { } + KeywordLoc(KeywordLoc), LParenLoc(LParenLoc), Base(Base), + RParenLoc(RParenLoc) { } Expr *getBase() const { return Base; } void setBase(Expr *base) { Base = base; } - SourceLoc getLoc() const { return MetatypeLoc; } - SourceLoc getMetatypeLoc() const { return MetatypeLoc; } - + SourceLoc getLoc() const { return KeywordLoc; } + SourceRange getSourceRange() const { + return SourceRange(KeywordLoc, RParenLoc); + } + SourceLoc getStartLoc() const { - return getBase()->getStartLoc(); + return KeywordLoc; } SourceLoc getEndLoc() const { - return (MetatypeLoc.isValid() ? MetatypeLoc : getBase()->getEndLoc()); + return RParenLoc; } static bool classof(const Expr *E) { diff --git a/include/swift/Parse/Tokens.def b/include/swift/Parse/Tokens.def index 83c644b9b49c9..4f4e787cb83af 100644 --- a/include/swift/Parse/Tokens.def +++ b/include/swift/Parse/Tokens.def @@ -130,7 +130,6 @@ STMT_KEYWORD(catch) // Expression keywords. KEYWORD(as) KEYWORD(Any) -KEYWORD(dynamicType) KEYWORD(false) KEYWORD(is) KEYWORD(nil) @@ -148,6 +147,9 @@ KEYWORD(__COLUMN__) KEYWORD(__FUNCTION__) KEYWORD(__DSO_HANDLE__) +// FIXME(SE-0096): REMOVE ME +KEYWORD(dynamicType) + // Pattern keywords. KEYWORD(_) diff --git a/lib/FrontendTool/FrontendTool.cpp b/lib/FrontendTool/FrontendTool.cpp index 4d6776bbe4f3d..189cffaa4036d 100644 --- a/lib/FrontendTool/FrontendTool.cpp +++ b/lib/FrontendTool/FrontendTool.cpp @@ -585,7 +585,7 @@ class JSONFixitWriter : public DiagnosticConsumer { Info.ID == diag::invalid_ibinspectable.ID || Info.ID == diag::invalid_ibaction_decl.ID) return false; - // Adding .dynamicType interacts poorly with the swift migrator by + // Adding type(of:) interacts poorly with the swift migrator by // invalidating some inits with type errors. if (Info.ID == diag::init_not_instance_member.ID) return false; diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index c5055d88c8126..ce9428c514465 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -1420,6 +1420,8 @@ ParserResult Parser::parseExprPostfix(Diag<> ID, bool isExprBasic) { // Handle "x.dynamicType" - A metatype expr. // Deprecated in SE-0096: `x.dynamicType` becomes `type(of: x)` + // + // FIXME(SE-0096): This will go away along with the keyword soon. if (Tok.is(tok::kw_dynamicType)) { // Fix-it auto range = Result.get()->getSourceRange(); @@ -1429,8 +1431,11 @@ ParserResult Parser::parseExprPostfix(Diag<> ID, bool isExprBasic) { .fixItReplace(dynamicTypeExprRange, ")") .fixItInsert(range.Start, "type(of: "); - Result = makeParserResult( - new (Context) DynamicTypeExpr(Result.get(), dynamicTypeExprRange.End, Type())); + // HACK: Arbitrary. + auto loc = range.Start; + auto dt = new (Context) DynamicTypeExpr(loc, loc, Result.get(), loc, Type()); + dt->setImplicit(); + Result = makeParserResult(dt); continue; } @@ -3018,23 +3023,33 @@ Parser::parseVersionConstraintSpec() { /// 'type' '(' 'of:' expr ')' /// ParserResult Parser::parseExprTypeOf() { - - assert(Tok.getText() == "type" && "only 'type' should be handled here"); - // Consume 'type' SourceLoc keywordLoc = consumeToken(); - // Consume '(' + + // Parse the leading '('. SourceLoc lParenLoc = consumeToken(tok::l_paren); - // Parse `of` label - // If we see a potential argument label followed by a ':', consume - // it. - if (Tok.canBeArgumentLabel() && Tok.getText() == "of" && peekToken().is(tok::colon)) { + // Parse `of` label. + auto ofRange = Tok.getRange(); + if (Tok.canBeArgumentLabel() && peekToken().is(tok::colon)) { + bool hasOf = Tok.getText() == "of"; + if (!hasOf) { + // User mis-spelled the 'of' label. + diagnose(Tok, diag::expr_typeof_expected_label_of) + .fixItReplace({ ofRange.getStart(), ofRange.getEnd() }, "of"); + } + + // Consume either 'of' or the misspelling. consumeToken(); consumeToken(tok::colon); + + if (!hasOf) { + return makeParserError(); + } } else { - diagnose(Tok, diag::expr_typeof_expected_label_of); - return makeParserError(); + // No label at all; insert it. + diagnose(Tok, diag::expr_typeof_expected_label_of) + .fixItInsert(ofRange.getStart(), "of: "); } // Parse the subexpression. @@ -3059,15 +3074,18 @@ ParserResult Parser::parseExprTypeOf() { if (subExpr.isParseError()) { if (subExpr.hasCodeCompletion()) { auto res = makeParserResult( - new (Context) DynamicTypeExpr(subExpr.get(), consumeToken(), Type())); + new (Context) DynamicTypeExpr(keywordLoc, lParenLoc, + subExpr.get(), rParenLoc, + Type())); res.setHasCodeCompletion(); return res; } else { return makeParserResult( - new (Context) ErrorExpr(SourceRange(keywordLoc, rParenLoc))); + new (Context) ErrorExpr(SourceRange(keywordLoc, rParenLoc))); } } return makeParserResult( - new (Context) DynamicTypeExpr(subExpr.get(), rParenLoc, Type())); + new (Context) DynamicTypeExpr(keywordLoc, lParenLoc, + subExpr.get(), rParenLoc, Type())); } diff --git a/lib/Sema/MiscDiagnostics.cpp b/lib/Sema/MiscDiagnostics.cpp index e4b307d0e74fe..0b6b550693fb1 100644 --- a/lib/Sema/MiscDiagnostics.cpp +++ b/lib/Sema/MiscDiagnostics.cpp @@ -486,17 +486,9 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E, return; // Allow references to types as a part of: - // - member references T.foo, T.Type, T.self, etc. (but *not* T.type) + // - member references T.foo, T.Type, T.self, etc. // - constructor calls T() if (auto *ParentExpr = Parent.getAsExpr()) { - // Reject use of "T.dynamicType", it should be written as "T.self". - if (auto metaExpr = dyn_cast(ParentExpr)) { - // Add a fixit to replace '.dynamicType' with '.self'. - TC.diagnose(E->getStartLoc(), diag::type_of_metatype) - .fixItReplace(metaExpr->getMetatypeLoc(), "self"); - return; - } - // This is the white-list of accepted syntactic forms. if (isa(ParentExpr) || isa(ParentExpr) || // T.self diff --git a/test/Parse/type_expr.swift b/test/Parse/type_expr.swift index 4c5826c833148..b1aed01680efd 100644 --- a/test/Parse/type_expr.swift +++ b/test/Parse/type_expr.swift @@ -53,7 +53,6 @@ func unqualifiedType() { _ = Foo.instMeth _ = Foo // expected-error{{expected member name or constructor call after type name}} expected-note{{add arguments}} {{10-10=()}} expected-note{{use '.self'}} {{10-10=.self}} - _ = type(of: Foo) // expected-error{{'.dynamicType' is not allowed after a type name}} {{11-22=self}} _ = Bad // expected-error{{expected member name or constructor call after type name}} // expected-note@-1{{use '.self' to reference the type object}}{{10-10=.self}} @@ -70,7 +69,6 @@ func qualifiedType() { _ = Foo.Bar.instMeth _ = Foo.Bar // expected-error{{expected member name or constructor call after type name}} expected-note{{add arguments}} {{14-14=()}} expected-note{{use '.self'}} {{14-14=.self}} - _ = type(of: Foo.Bar) // expected-error{{'.dynamicType' is not allowed after a type name}} {{15-26=self}} } /* TODO allow '.Type' in expr context @@ -90,11 +88,9 @@ func genType() { _ = Gen.meth let _ : () = Gen.meth() _ = Gen.instMeth - - // Misparses because generic parameter disambiguation rejects '>' not - // followed by '.' or '(' - _ = Gen // expected-error{{not a postfix unary operator}} - _ = Gen.dynamicType // expected-error{{'.dynamicType' is not allowed after a type name}} {{16-27=self}} + _ = Gen // expected-error{{expected member name or constructor call after type name}} + // expected-note@-1{{use '.self' to reference the type object}} + // expected-note@-2{{add arguments after the type to construct a value of the type}} } func genQualifiedType() { @@ -106,7 +102,9 @@ func genQualifiedType() { _ = Gen.Bar.instMeth _ = Gen.Bar - _ = type(of: Gen.Bar) + _ = type(of: Gen.Bar) // No error here. + _ = type(Gen.Bar) // expected-error {{expected argument label 'of:' within 'type(...)'}} {{12-12=of: }} + _ = type(fo: Gen.Bar) // expected-error {{expected argument label 'of:' within 'type(...)'}} } func archetype(_: T) { @@ -117,7 +115,6 @@ func archetype(_: T) { let _ : () = T.meth() _ = T // expected-error{{expected member name or constructor call after type name}} expected-note{{add arguments}} {{8-8=()}} expected-note{{use '.self'}} {{8-8=.self}} - _ = type(of: T) // expected-error{{'.dynamicType' is not allowed after a type name}} {{9-20=self}} } func assocType(_: T) where T.Zang: Zim { @@ -128,7 +125,6 @@ func assocType(_: T) where T.Zang: Zim { let _ : () = T.Zang.meth() _ = T.Zang // expected-error{{expected member name or constructor call after type name}} expected-note{{add arguments}} {{13-13=()}} expected-note{{use '.self'}} {{13-13=.self}} - _ = type(of: T.Zang) // expected-error{{'.dynamicType' is not allowed after a type name}} {{14-25=self}} } class B { @@ -149,7 +145,6 @@ func derivedType() { let _: B.Type = D // expected-error{{expected member name or constructor call after type name}} expected-note{{add arguments}} {{20-20=()}} expected-note{{use '.self'}} {{20-20=.self}} let _: D.Type = D // expected-error{{expected member name or constructor call after type name}} expected-note{{add arguments}} {{20-20=()}} expected-note{{use '.self'}} {{20-20=.self}} - let _: D.Type.Type = type(of: D) // expected-error{{'.dynamicType' is not allowed after a type name}} {{26-37=self}} } // Referencing a nonexistent member or constructor should not trigger errors diff --git a/test/SILGen/optional_chain_addressor.swift b/test/SILGen/optional_chain_addressor.swift index 414dd19c6a1c2..dd68bacd51e9e 100644 --- a/test/SILGen/optional_chain_addressor.swift +++ b/test/SILGen/optional_chain_addressor.swift @@ -2,5 +2,5 @@ func foo(x: UnsafeMutablePointer?>) { _ = x.pointee?.pointee - _ = type(of: x.pointee?) + _ = type(of: x.pointee) } diff --git a/test/SILOptimizer/cast_folding.swift b/test/SILOptimizer/cast_folding.swift index de05050c8eeab..a2291db00c5a6 100644 --- a/test/SILOptimizer/cast_folding.swift +++ b/test/SILOptimizer/cast_folding.swift @@ -509,7 +509,7 @@ func test18_2() -> Bool { // CHECK-NEXT: return %1 @inline(never) func test19() -> Bool { - let t: Any.Type = (1 as Any).dynamicType + let t: Any.Type = type(of: 1 as Any) return t is Int.Type } diff --git a/test/expr/postfix/dot/init_ref_delegation.swift b/test/expr/postfix/dot/init_ref_delegation.swift index 0dac223a1d256..4e28e96725f1e 100644 --- a/test/expr/postfix/dot/init_ref_delegation.swift +++ b/test/expr/postfix/dot/init_ref_delegation.swift @@ -101,7 +101,7 @@ enum Z2 { // Ill-formed initialization: wrong context. class Z3 { func f() { - self.init() // expected-error{{'init' is a member of the type; insert '.dynamicType' to initialize a new object of the same dynamic type}} {{9-9=.dynamicType}} + self.init() // expected-error{{'init' is a member of the type; use 'type(of: ...)' to initialize a new object of the same dynamic type}} {{10-10=type(of: }} {{14-14=)}} } init() { } @@ -112,7 +112,7 @@ class Z4 { init() {} // expected-note{{selected non-required initializer}} convenience init(other: Z4) { - other.init() // expected-error{{'init' is a member of the type; insert '.dynamicType' to initialize a new object of the same dynamic type}} {{10-10=.dynamicType}} + other.init() // expected-error{{'init' is a member of the type; use 'type(of: ...)' to initialize a new object of the same dynamic type}} {{11-11=type(of: }} {{15-15=)}} type(of: other).init() // expected-error{{must use a 'required' initializer}} expected-warning{{unused}} } } @@ -121,7 +121,7 @@ class Z5 : Z4 { override init() { } convenience init(other: Z5) { - other.init() // expected-error{{'init' is a member of the type; insert '.dynamicType' to initialize a new object of the same dynamic type}} {{10-10=.dynamicType}} + other.init() // expected-error{{'init' is a member of the type; use 'type(of: ...)' to initialize a new object of the same dynamic type}} {{11-11=type(of: }} {{15-15=)}} } } @@ -150,7 +150,7 @@ struct RDar16603812 { var i = 42 init() {} func foo() { - self.init() // expected-error {{'init' is a member of the type; insert '.dynamicType' to initialize a new object of the same dynamic type}} {{11-11=.dynamicType}} + self.init() // expected-error {{'init' is a member of the type; use 'type(of: ...)' to initialize a new object of the same dynamic type}} {{12-12=type(of: }} {{16-16=)}} type(of: self).init() // expected-warning{{result of 'RDar16603812' initializer is unused}} } } @@ -199,7 +199,7 @@ class D: C { } func foo() { - self.init(x: 0) // expected-error{{'init' is a member of the type; insert '.dynamicType' to initialize a new object of the same dynamic type}} {{9-9=.dynamicType}} + self.init(x: 0) // expected-error{{'init' is a member of the type; use 'type(of: ...)' to initialize a new object of the same dynamic type}} {{10-10=type(of: }} {{14-14=)}} } func bar() { super.init(x: 0) // expected-error{{'super.init' cannot be called outside of an initializer}} @@ -270,10 +270,10 @@ func foo(_ x: T, y: T.Type) where T: P { var c3a = type(of: x).init() // expected-error{{'required' initializer}} var c4a = type(of: x).init(proto: "") - var ci1 = x.init(required: 0) // expected-error{{'init' is a member of the type; insert '.dynamicType' to initialize a new object of the same dynamic type}} {{14-14=.dynamicType}} - var ci2 = x.init(x: 0) // expected-error{{'init' is a member of the type; insert '.dynamicType' to initialize a new object of the same dynamic type}} {{14-14=.dynamicType}} - var ci3 = x.init() // expected-error{{'init' is a member of the type; insert '.dynamicType' to initialize a new object of the same dynamic type}} {{14-14=.dynamicType}} - var ci4 = x.init(proto: "") // expected-error{{'init' is a member of the type; insert '.dynamicType' to initialize a new object of the same dynamic type}} {{14-14=.dynamicType}} + var ci1 = x.init(required: 0) // expected-error{{'init' is a member of the type; use 'type(of: ...)' to initialize a new object of the same dynamic type}} {{15-15=type(of: }} {{19-19=)}} + var ci2 = x.init(x: 0) // expected-error{{'init' is a member of the type; use 'type(of: ...)' to initialize a new object of the same dynamic type}} {{15-15=type(of: }} {{19-19=)}} + var ci3 = x.init() // expected-error{{'init' is a member of the type; use 'type(of: ...)' to initialize a new object of the same dynamic type}} {{15-15=type(of: }} {{19-19=)}} + var ci4 = x.init(proto: "") // expected-error{{'init' is a member of the type; use 'type(of: ...)' to initialize a new object of the same dynamic type}} {{15-15=type(of: }} {{19-19=)}} var ci1a = x(required: 0) // expected-error{{cannot call value of non-function type 'T'}} var ci2a = x(x: 0) // expected-error{{cannot call value of non-function type 'T'}}