From 4e5665a8bd9d1a5ba3cf4a736182d506769b082c Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Fri, 29 Jul 2016 23:39:23 -0700 Subject: [PATCH 1/4] [SE-0096] Remove support for dynamicType member --- include/swift/AST/DiagnosticsParse.def | 2 -- include/swift/Parse/Tokens.def | 3 --- lib/Parse/ParseExpr.cpp | 23 ----------------------- lib/Parse/ParseType.cpp | 1 - tools/swift-ide-test/KnownObjCMethods.def | 2 +- utils/vim/syntax/swift.vim | 1 - 6 files changed, 1 insertion(+), 31 deletions(-) diff --git a/include/swift/AST/DiagnosticsParse.def b/include/swift/AST/DiagnosticsParse.def index 1a155990a27c5..ea012d1ed65c6 100644 --- a/include/swift/AST/DiagnosticsParse.def +++ b/include/swift/AST/DiagnosticsParse.def @@ -1114,8 +1114,6 @@ 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/Parse/Tokens.def b/include/swift/Parse/Tokens.def index 4f4e787cb83af..aa863f5244646 100644 --- a/include/swift/Parse/Tokens.def +++ b/include/swift/Parse/Tokens.def @@ -147,9 +147,6 @@ KEYWORD(__COLUMN__) KEYWORD(__FUNCTION__) KEYWORD(__DSO_HANDLE__) -// FIXME(SE-0096): REMOVE ME -KEYWORD(dynamicType) - // Pattern keywords. KEYWORD(_) diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index ce9428c514465..d406f30264545 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -1418,35 +1418,12 @@ ParserResult Parser::parseExprPostfix(Diag<> ID, bool isExprBasic) { continue; } - // 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(); - auto dynamicTypeExprRange = SourceRange(TokLoc, consumeToken()); - diagnose(TokLoc, diag::expr_dynamictype_deprecated) - .highlight(dynamicTypeExprRange) - .fixItReplace(dynamicTypeExprRange, ")") - .fixItInsert(range.Start, "type(of: "); - - // HACK: Arbitrary. - auto loc = range.Start; - auto dt = new (Context) DynamicTypeExpr(loc, loc, Result.get(), loc, Type()); - dt->setImplicit(); - Result = makeParserResult(dt); - continue; - } - - // Handle "x.self" expr. if (Tok.is(tok::kw_self)) { Result = makeParserResult( new (Context) DotSelfExpr(Result.get(), TokLoc, consumeToken())); continue; } - // If we have '.', try to recover by creating // an identifier with the same spelling as the keyword. diff --git a/lib/Parse/ParseType.cpp b/lib/Parse/ParseType.cpp index 93762f23bf496..fc9c5e8018fb7 100644 --- a/lib/Parse/ParseType.cpp +++ b/lib/Parse/ParseType.cpp @@ -78,7 +78,6 @@ ParserResult Parser::parseTypeSimple(Diag<> MessageID, consumeToken(tok::code_complete); return makeParserCodeCompletionResult(); case tok::kw_super: - case tok::kw_dynamicType: case tok::kw_self: // These keywords don't start a decl or a statement, and thus should be // safe to skip over. diff --git a/tools/swift-ide-test/KnownObjCMethods.def b/tools/swift-ide-test/KnownObjCMethods.def index 494cfb9dd569d..f37e3152079ff 100644 --- a/tools/swift-ide-test/KnownObjCMethods.def +++ b/tools/swift-ide-test/KnownObjCMethods.def @@ -88,7 +88,7 @@ CLASS_METHOD(NSObject, (0, "class"), Unavailable("use 'self' instead")) // NSObject protocol PROTOCOL_INSTANCE_METHOD(NSObject, (0, "class"), - Unavailable("use 'dynamicType' instead")) + Unavailable("use 'type(of:)' instead")) START_MODULE(Foundation) INSTANCE_METHOD(NSArray, (0, "init"), DesignatedInit) diff --git a/utils/vim/syntax/swift.vim b/utils/vim/syntax/swift.vim index 22a5531daaa92..0016efb946e57 100644 --- a/utils/vim/syntax/swift.vim +++ b/utils/vim/syntax/swift.vim @@ -55,7 +55,6 @@ syn keyword swiftDefinitionModifier syn keyword swiftIdentifierKeyword \ Self - \ dynamicType \ metatype \ self \ super From 9c83e7223e6df7aa91ddd12d37d6e5963e78b8b6 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Sat, 30 Jul 2016 02:01:05 -0700 Subject: [PATCH 2/4] Fixup diagnostics around type(of:) and dynamicType handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Be laxer about the parsing for type(of:) so as not to get in the way of other declarations that may use ‘type’ as their base name. --- include/swift/AST/DiagnosticsParse.def | 2 + lib/Basic/StringExtras.cpp | 1 - lib/Parse/ParseExpr.cpp | 61 +++++++++++++------ .../Mandatory/DIMemoryUseCollector.cpp | 4 +- test/Parse/type_expr.swift | 30 ++++++++- test/SILGen/optional_chain_addressor.swift | 2 +- 6 files changed, 75 insertions(+), 25 deletions(-) diff --git a/include/swift/AST/DiagnosticsParse.def b/include/swift/AST/DiagnosticsParse.def index ea012d1ed65c6..4eff3f67cfe13 100644 --- a/include/swift/AST/DiagnosticsParse.def +++ b/include/swift/AST/DiagnosticsParse.def @@ -1114,6 +1114,8 @@ ERROR(expr_typeof_expected_expr,PointsToFirstBadToken, "expected an expression within 'type(of: ...)'", ()) ERROR(expr_typeof_expected_rparen,PointsToFirstBadToken, "expected ')' to complete 'type(of: ...)' expression", ()) +ERROR(expr_dynamictype_deprecated,PointsToFirstBadToken, + "'.dynamicType' is deprecated. Use 'type(of: ...)' instead", ()) //------------------------------------------------------------------------------ // Attribute-parsing diagnostics diff --git a/lib/Basic/StringExtras.cpp b/lib/Basic/StringExtras.cpp index aa3888d84678a..ee3c5bd75bcb3 100644 --- a/lib/Basic/StringExtras.cpp +++ b/lib/Basic/StringExtras.cpp @@ -36,7 +36,6 @@ bool swift::canBeArgumentLabel(StringRef identifier) { bool swift::canBeMemberName(StringRef identifier) { return llvm::StringSwitch(identifier) - .Case("dynamicType", false) .Case("init", false) .Case("Protocol", false) .Case("self", false) diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index d406f30264545..a99bdfab4e547 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -950,6 +950,30 @@ getMagicIdentifierLiteralKind(tok Kind) { } } +/// See if type(of: ) can be parsed backtracking on failure. +static bool canParseTypeOf(Parser &P) { + if (!(P.Tok.getText() == "type" && P.peekToken().is(tok::l_paren))) { + return false; + } + // Look ahead to parse the parenthesized expression. + Parser::BacktrackingScope Backtrack(P); + P.consumeToken(tok::identifier); + P.consumeToken(tok::l_paren); + // The first argument label must be 'of'. + if (!(P.Tok.getText() == "of" && P.peekToken().is(tok::colon))) { + return false; + } + + // Parse to the closing paren. + while (!P.Tok.is(tok::r_paren) && !P.Tok.is(tok::eof)) { + // Anything that looks like another argument label is bogus. + if (P.Tok.is(tok::comma) && P.peekToken().canBeArgumentLabel()) { + return false; + } + P.skipSingle(); + } + return true; +} /// parseExprPostfix /// @@ -1095,8 +1119,8 @@ 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)) { + // Attempt to parse for 'type(of: )'. + if (canParseTypeOf(*this)) { Result = parseExprTypeOf(); break; } @@ -1424,6 +1448,17 @@ ParserResult Parser::parseExprPostfix(Diag<> ID, bool isExprBasic) { new (Context) DotSelfExpr(Result.get(), TokLoc, consumeToken())); continue; } + + // Handle the deprecated 'x.dynamicType' and migrate it to `type(of: x)` + if (Tok.getText() == "dynamicType") { + 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: "); + continue; + } // If we have '.', try to recover by creating // an identifier with the same spelling as the keyword. @@ -3007,26 +3042,14 @@ ParserResult Parser::parseExprTypeOf() { SourceLoc lParenLoc = consumeToken(tok::l_paren); // 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. + if (Tok.getText() == "of" && peekToken().is(tok::colon)) { + // Consume the label. consumeToken(); consumeToken(tok::colon); - - if (!hasOf) { - return makeParserError(); - } } else { - // No label at all; insert it. - diagnose(Tok, diag::expr_typeof_expected_label_of) - .fixItInsert(ofRange.getStart(), "of: "); + // There cannot be a richer diagnostic here because the user may have + // defined a function `type(...)` that conflicts with the magic expr. + diagnose(Tok, diag::expr_typeof_expected_label_of); } // Parse the subexpression. diff --git a/lib/SILOptimizer/Mandatory/DIMemoryUseCollector.cpp b/lib/SILOptimizer/Mandatory/DIMemoryUseCollector.cpp index b1ca6d6e911a8..2c10fc5b4f94d 100644 --- a/lib/SILOptimizer/Mandatory/DIMemoryUseCollector.cpp +++ b/lib/SILOptimizer/Mandatory/DIMemoryUseCollector.cpp @@ -1240,7 +1240,7 @@ collectClassSelfUses(SILValue ClassPointer, SILType MemorySILType, if (isSelfInitUse(VMI)) Kind = DIUseKind::SelfInit; else - // Otherwise, this is a simple reference to "dynamicType", which is + // Otherwise, this is a simple reference to "type(of:)", which is // always fine, even if self is uninitialized. continue; } @@ -1386,7 +1386,7 @@ void ElementUseCollector::collectDelegatingClassInitSelfUses() { if (isSelfInitUse(VMI)) Kind = DIUseKind::SelfInit; else - // Otherwise, this is a simple reference to "dynamicType", which is + // Otherwise, this is a simple reference to "type(of:)", which is // always fine, even if self is uninitialized. continue; } diff --git a/test/Parse/type_expr.swift b/test/Parse/type_expr.swift index b1aed01680efd..b0ea568834908 100644 --- a/test/Parse/type_expr.swift +++ b/test/Parse/type_expr.swift @@ -53,6 +53,10 @@ 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 {{expected member name or constructor call after type name}} + // expected-error@-1 {{'.dynamicType' is deprecated. Use 'type(of: ...)' instead}} {{7-7=type(of: }} {{10-22=)}} + // expected-note@-2 {{add arguments after the type to construct a value of the type}} + // expected-note@-3 {{use '.self' to reference the type object}} _ = 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}} @@ -69,6 +73,10 @@ 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 {{expected member name or constructor call after type name}} + // expected-error@-1 {{'.dynamicType' is deprecated. Use 'type(of: ...)' instead}} {{7-7=type(of: }} {{14-26=)}} + // expected-note@-2 {{add arguments after the type to construct a value of the type}} + // expected-note@-3 {{use '.self' to reference the type object}} } /* TODO allow '.Type' in expr context @@ -102,9 +110,27 @@ func genQualifiedType() { _ = Gen.Bar.instMeth _ = Gen.Bar + _ = Gen.Bar.dynamicType // expected-error {{'.dynamicType' is deprecated. Use 'type(of: ...)' instead}} {{7-7=type(of: }} {{19-31=)}} +} + +func typeOfShadowing() { + // Try to shadow type(of:) + func type(of t: T.Type, flag: Bool) -> T.Type { + return t + } + + func type(_ t: T.Type) -> T.Type { + return t + } + + func type(fo t: T.Type) -> T.Type { + return t + } + _ = 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(...)'}} + _ = type(Gen.Bar) // No error here. + _ = type(of: Gen.Bar.self, flag: false) // No error here. + _ = type(fo: Foo.Bar.self) // No error here. } func archetype(_: T) { diff --git a/test/SILGen/optional_chain_addressor.swift b/test/SILGen/optional_chain_addressor.swift index dd68bacd51e9e..b7c71d95fc937 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) + _ = x.pointee.map { type(of: $0) } } From e1ae0391e8ce810106e204f7eee710d8113006b4 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Sat, 30 Jul 2016 02:47:35 -0700 Subject: [PATCH 3/4] Fixup validation tests --- test/1_stdlib/TestAffineTransform.swift | 12 ++--- test/1_stdlib/TestCalendar.swift | 12 ++--- test/1_stdlib/TestCharacterSet.swift | 12 ++--- test/1_stdlib/TestData.swift | 12 ++--- test/1_stdlib/TestDate.swift | 24 +++++----- test/1_stdlib/TestDateInterval.swift | 12 ++--- test/1_stdlib/TestIndexPath.swift | 12 ++--- test/1_stdlib/TestIndexSet.swift | 12 ++--- test/1_stdlib/TestLocale.swift | 12 ++--- test/1_stdlib/TestPersonNameComponents.swift | 12 ++--- test/1_stdlib/TestTimeZone.swift | 12 ++--- test/1_stdlib/TestURL.swift | 48 +++++++++---------- test/1_stdlib/TestUUID.swift | 12 ++--- test/1_stdlib/TestUserInfo.swift | 12 ++--- .../0022-rdar21625478.swift | 2 +- validation-test/stdlib/AnyHashable.swift.gyb | 2 +- validation-test/stdlib/Lazy.swift.gyb | 30 ++++++------ .../stdlib/NSDecimalNumberBridging.swift.gyb | 6 +-- .../stdlib/NSNumberBridging.swift.gyb | 8 ++-- .../stdlib/NSStringBridging.swift.gyb | 6 +-- validation-test/stdlib/SequenceType.swift.gyb | 2 +- 21 files changed, 136 insertions(+), 136 deletions(-) diff --git a/test/1_stdlib/TestAffineTransform.swift b/test/1_stdlib/TestAffineTransform.swift index 9bd6a167ab892..4124f419a6b73 100644 --- a/test/1_stdlib/TestAffineTransform.swift +++ b/test/1_stdlib/TestAffineTransform.swift @@ -337,9 +337,9 @@ class TestAffineTransform : TestAffineTransformSuper { AffineTransform(m11: -55.66, m12: 22.7, m21: 1.5, m22: 0.0, tX: -22, tY: -33) ] let anyHashables = values.map(AnyHashable.init) - expectEqual("AffineTransform", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("AffineTransform", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("AffineTransform", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("AffineTransform", String(describing: type(of: anyHashables[0].base))) + expectEqual("AffineTransform", String(describing: type(of: anyHashables[1].base))) + expectEqual("AffineTransform", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -356,9 +356,9 @@ class TestAffineTransform : TestAffineTransformSuper { makeNSAffineTransform(rotatedByDegrees: 10), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("AffineTransform", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("AffineTransform", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("AffineTransform", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("AffineTransform", String(describing: type(of: anyHashables[0].base))) + expectEqual("AffineTransform", String(describing: type(of: anyHashables[1].base))) + expectEqual("AffineTransform", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } diff --git a/test/1_stdlib/TestCalendar.swift b/test/1_stdlib/TestCalendar.swift index a7e72d829eae6..bd0b4d85ea1e1 100644 --- a/test/1_stdlib/TestCalendar.swift +++ b/test/1_stdlib/TestCalendar.swift @@ -263,9 +263,9 @@ class TestCalendar : TestCalendarSuper { Calendar(identifier: .japanese) ] let anyHashables = values.map(AnyHashable.init) - expectEqual("Calendar", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("Calendar", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("Calendar", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("Calendar", String(describing: type(of: anyHashables[0].base))) + expectEqual("Calendar", String(describing: type(of: anyHashables[1].base))) + expectEqual("Calendar", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -278,9 +278,9 @@ class TestCalendar : TestCalendarSuper { NSCalendar(identifier: .japanese)!, ] let anyHashables = values.map(AnyHashable.init) - expectEqual("Calendar", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("Calendar", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("Calendar", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("Calendar", String(describing: type(of: anyHashables[0].base))) + expectEqual("Calendar", String(describing: type(of: anyHashables[1].base))) + expectEqual("Calendar", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } diff --git a/test/1_stdlib/TestCharacterSet.swift b/test/1_stdlib/TestCharacterSet.swift index ca2630a8729f1..ee86610eb932c 100644 --- a/test/1_stdlib/TestCharacterSet.swift +++ b/test/1_stdlib/TestCharacterSet.swift @@ -160,9 +160,9 @@ class TestCharacterSet : TestCharacterSetSuper { CharacterSet(charactersIn: "XYZ") ] let anyHashables = values.map(AnyHashable.init) - expectEqual("CharacterSet", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("CharacterSet", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("CharacterSet", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("CharacterSet", String(describing: type(of: anyHashables[0].base))) + expectEqual("CharacterSet", String(describing: type(of: anyHashables[1].base))) + expectEqual("CharacterSet", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -174,9 +174,9 @@ class TestCharacterSet : TestCharacterSetSuper { NSCharacterSet(charactersIn: "XYZ"), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("CharacterSet", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("CharacterSet", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("CharacterSet", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("CharacterSet", String(describing: type(of: anyHashables[0].base))) + expectEqual("CharacterSet", String(describing: type(of: anyHashables[1].base))) + expectEqual("CharacterSet", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } diff --git a/test/1_stdlib/TestData.swift b/test/1_stdlib/TestData.swift index d3aa71b9f07c8..ae1f5c6aa7083 100644 --- a/test/1_stdlib/TestData.swift +++ b/test/1_stdlib/TestData.swift @@ -875,9 +875,9 @@ class TestData : TestDataSuper { Data(base64Encoded: "AAAB")!, ] let anyHashables = values.map(AnyHashable.init) - expectEqual("Data", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("Data", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("Data", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("Data", String(describing: type(of: anyHashables[0].base))) + expectEqual("Data", String(describing: type(of: anyHashables[1].base))) + expectEqual("Data", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -889,9 +889,9 @@ class TestData : TestDataSuper { NSData(base64Encoded: "AAAB")!, ] let anyHashables = values.map(AnyHashable.init) - expectEqual("Data", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("Data", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("Data", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("Data", String(describing: type(of: anyHashables[0].base))) + expectEqual("Data", String(describing: type(of: anyHashables[1].base))) + expectEqual("Data", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } diff --git a/test/1_stdlib/TestDate.swift b/test/1_stdlib/TestDate.swift index f84dde936b255..80691571d6b0f 100644 --- a/test/1_stdlib/TestDate.swift +++ b/test/1_stdlib/TestDate.swift @@ -143,9 +143,9 @@ class TestDate : TestDateSuper { dateWithString("2010-05-17 14:49:47 -0700"), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("Date", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("Date", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("Date", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("Date", String(describing: type(of: anyHashables[0].base))) + expectEqual("Date", String(describing: type(of: anyHashables[1].base))) + expectEqual("Date", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -157,9 +157,9 @@ class TestDate : TestDateSuper { NSDate(timeIntervalSince1970: 1000000001), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("Date", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("Date", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("Date", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("Date", String(describing: type(of: anyHashables[0].base))) + expectEqual("Date", String(describing: type(of: anyHashables[1].base))) + expectEqual("Date", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -171,9 +171,9 @@ class TestDate : TestDateSuper { DateComponents(year: 1995), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("DateComponents", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("DateComponents", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("DateComponents", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("DateComponents", String(describing: type(of: anyHashables[0].base))) + expectEqual("DateComponents", String(describing: type(of: anyHashables[1].base))) + expectEqual("DateComponents", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -190,9 +190,9 @@ class TestDate : TestDateSuper { makeNSDateComponents(year: 1995), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("DateComponents", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("DateComponents", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("DateComponents", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("DateComponents", String(describing: type(of: anyHashables[0].base))) + expectEqual("DateComponents", String(describing: type(of: anyHashables[1].base))) + expectEqual("DateComponents", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } diff --git a/test/1_stdlib/TestDateInterval.swift b/test/1_stdlib/TestDateInterval.swift index e0f2e083b15f6..4d98a1d65f25e 100644 --- a/test/1_stdlib/TestDateInterval.swift +++ b/test/1_stdlib/TestDateInterval.swift @@ -140,9 +140,9 @@ class TestDateInterval : TestDateIntervalSuper { DateInterval(start: start, duration: duration / 2), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("DateInterval", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("DateInterval", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("DateInterval", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("DateInterval", String(describing: type(of: anyHashables[0].base))) + expectEqual("DateInterval", String(describing: type(of: anyHashables[1].base))) + expectEqual("DateInterval", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -158,9 +158,9 @@ class TestDateInterval : TestDateIntervalSuper { NSDateInterval(start: start, duration: duration / 2), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("DateInterval", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("DateInterval", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("DateInterval", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("DateInterval", String(describing: type(of: anyHashables[0].base))) + expectEqual("DateInterval", String(describing: type(of: anyHashables[1].base))) + expectEqual("DateInterval", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } diff --git a/test/1_stdlib/TestIndexPath.swift b/test/1_stdlib/TestIndexPath.swift index 80d7a8a6e27fb..0c76c36b1ffb6 100644 --- a/test/1_stdlib/TestIndexPath.swift +++ b/test/1_stdlib/TestIndexPath.swift @@ -89,9 +89,9 @@ class TestIndexPath : TestIndexPathSuper { IndexPath(indexes: [1, 2, 3]), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("IndexPath", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("IndexPath", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("IndexPath", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("IndexPath", String(describing: type(of: anyHashables[0].base))) + expectEqual("IndexPath", String(describing: type(of: anyHashables[1].base))) + expectEqual("IndexPath", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -103,9 +103,9 @@ class TestIndexPath : TestIndexPathSuper { NSIndexPath(index: 2), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("IndexPath", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("IndexPath", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("IndexPath", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("IndexPath", String(describing: type(of: anyHashables[0].base))) + expectEqual("IndexPath", String(describing: type(of: anyHashables[1].base))) + expectEqual("IndexPath", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } diff --git a/test/1_stdlib/TestIndexSet.swift b/test/1_stdlib/TestIndexSet.swift index 30036411fb35f..9183603319dda 100644 --- a/test/1_stdlib/TestIndexSet.swift +++ b/test/1_stdlib/TestIndexSet.swift @@ -799,9 +799,9 @@ class TestIndexSet : TestIndexSetSuper { IndexSet([0, 1, 2]), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("IndexSet", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("IndexSet", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("IndexSet", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("IndexSet", String(describing: type(of: anyHashables[0].base))) + expectEqual("IndexSet", String(describing: type(of: anyHashables[1].base))) + expectEqual("IndexSet", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -813,9 +813,9 @@ class TestIndexSet : TestIndexSetSuper { NSIndexSet(index: 1), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("IndexSet", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("IndexSet", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("IndexSet", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("IndexSet", String(describing: type(of: anyHashables[0].base))) + expectEqual("IndexSet", String(describing: type(of: anyHashables[1].base))) + expectEqual("IndexSet", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } diff --git a/test/1_stdlib/TestLocale.swift b/test/1_stdlib/TestLocale.swift index 96a5f92e74fab..8586f86c5456d 100644 --- a/test/1_stdlib/TestLocale.swift +++ b/test/1_stdlib/TestLocale.swift @@ -116,9 +116,9 @@ class TestLocale : TestLocaleSuper { Locale(identifier: "uk"), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("Locale", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("Locale", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("Locale", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("Locale", String(describing: type(of: anyHashables[0].base))) + expectEqual("Locale", String(describing: type(of: anyHashables[1].base))) + expectEqual("Locale", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -130,9 +130,9 @@ class TestLocale : TestLocaleSuper { NSLocale(localeIdentifier: "uk"), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("Locale", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("Locale", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("Locale", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("Locale", String(describing: type(of: anyHashables[0].base))) + expectEqual("Locale", String(describing: type(of: anyHashables[1].base))) + expectEqual("Locale", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } diff --git a/test/1_stdlib/TestPersonNameComponents.swift b/test/1_stdlib/TestPersonNameComponents.swift index b8313f5a189f2..3eba7d1f63174 100644 --- a/test/1_stdlib/TestPersonNameComponents.swift +++ b/test/1_stdlib/TestPersonNameComponents.swift @@ -37,9 +37,9 @@ class TestPersonNameComponents : TestPersonNameComponentsSuper { makePersonNameComponents(givenName: "John", familyName: "Appleseed"), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("PersonNameComponents", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("PersonNameComponents", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("PersonNameComponents", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("PersonNameComponents", String(describing: type(of: anyHashables[0].base))) + expectEqual("PersonNameComponents", String(describing: type(of: anyHashables[1].base))) + expectEqual("PersonNameComponents", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -61,9 +61,9 @@ class TestPersonNameComponents : TestPersonNameComponentsSuper { makeNSPersonNameComponents(givenName: "John", familyName: "Appleseed"), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("PersonNameComponents", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("PersonNameComponents", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("PersonNameComponents", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("PersonNameComponents", String(describing: type(of: anyHashables[0].base))) + expectEqual("PersonNameComponents", String(describing: type(of: anyHashables[1].base))) + expectEqual("PersonNameComponents", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } diff --git a/test/1_stdlib/TestTimeZone.swift b/test/1_stdlib/TestTimeZone.swift index a10fa527a7e26..c7f9ff51b5b49 100644 --- a/test/1_stdlib/TestTimeZone.swift +++ b/test/1_stdlib/TestTimeZone.swift @@ -70,9 +70,9 @@ class TestTimeZone : TestTimeZoneSuper { TimeZone(identifier: "Europe/Kiev")!, ] let anyHashables = values.map(AnyHashable.init) - expectEqual("TimeZone", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("TimeZone", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("TimeZone", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("TimeZone", String(describing: type(of: anyHashables[0].base))) + expectEqual("TimeZone", String(describing: type(of: anyHashables[1].base))) + expectEqual("TimeZone", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -84,9 +84,9 @@ class TestTimeZone : TestTimeZoneSuper { NSTimeZone(name: "Europe/Kiev")!, ] let anyHashables = values.map(AnyHashable.init) - expectEqual("TimeZone", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("TimeZone", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("TimeZone", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("TimeZone", String(describing: type(of: anyHashables[0].base))) + expectEqual("TimeZone", String(describing: type(of: anyHashables[1].base))) + expectEqual("TimeZone", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } diff --git a/test/1_stdlib/TestURL.swift b/test/1_stdlib/TestURL.swift index 504fecdf7c8fc..d4b0e2eeb43d7 100644 --- a/test/1_stdlib/TestURL.swift +++ b/test/1_stdlib/TestURL.swift @@ -212,9 +212,9 @@ class TestURL : TestURLSuper { URL(string: "https://example.org/")!, ] let anyHashables = values.map(AnyHashable.init) - expectEqual("URL", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("URL", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("URL", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("URL", String(describing: type(of: anyHashables[0].base))) + expectEqual("URL", String(describing: type(of: anyHashables[1].base))) + expectEqual("URL", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -226,9 +226,9 @@ class TestURL : TestURLSuper { NSURL(string: "https://example.org/")!, ] let anyHashables = values.map(AnyHashable.init) - expectEqual("URL", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("URL", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("URL", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("URL", String(describing: type(of: anyHashables[0].base))) + expectEqual("URL", String(describing: type(of: anyHashables[1].base))) + expectEqual("URL", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -240,9 +240,9 @@ class TestURL : TestURLSuper { URLComponents(string: "https://example.org/")!, ] let anyHashables = values.map(AnyHashable.init) - expectEqual("URLComponents", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("URLComponents", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("URLComponents", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("URLComponents", String(describing: type(of: anyHashables[0].base))) + expectEqual("URLComponents", String(describing: type(of: anyHashables[1].base))) + expectEqual("URLComponents", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -254,9 +254,9 @@ class TestURL : TestURLSuper { NSURLComponents(string: "https://example.org/")!, ] let anyHashables = values.map(AnyHashable.init) - expectEqual("URLComponents", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("URLComponents", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("URLComponents", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("URLComponents", String(describing: type(of: anyHashables[0].base))) + expectEqual("URLComponents", String(describing: type(of: anyHashables[1].base))) + expectEqual("URLComponents", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -269,9 +269,9 @@ class TestURL : TestURLSuper { URLQueryItem(name: "bar", value: nil), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("URLQueryItem", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("URLQueryItem", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("URLQueryItem", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("URLQueryItem", String(describing: type(of: anyHashables[0].base))) + expectEqual("URLQueryItem", String(describing: type(of: anyHashables[1].base))) + expectEqual("URLQueryItem", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -285,9 +285,9 @@ class TestURL : TestURLSuper { NSURLQueryItem(name: "bar", value: nil), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("URLQueryItem", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("URLQueryItem", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("URLQueryItem", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("URLQueryItem", String(describing: type(of: anyHashables[0].base))) + expectEqual("URLQueryItem", String(describing: type(of: anyHashables[1].base))) + expectEqual("URLQueryItem", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -300,9 +300,9 @@ class TestURL : TestURLSuper { URLRequest(url: URL(string: "https://example.org/")!), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("URLRequest", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("URLRequest", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("URLRequest", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("URLRequest", String(describing: type(of: anyHashables[0].base))) + expectEqual("URLRequest", String(describing: type(of: anyHashables[1].base))) + expectEqual("URLRequest", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -314,9 +314,9 @@ class TestURL : TestURLSuper { NSURLRequest(url: URL(string: "https://example.org/")!), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("URLRequest", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("URLRequest", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("URLRequest", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("URLRequest", String(describing: type(of: anyHashables[0].base))) + expectEqual("URLRequest", String(describing: type(of: anyHashables[1].base))) + expectEqual("URLRequest", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } diff --git a/test/1_stdlib/TestUUID.swift b/test/1_stdlib/TestUUID.swift index 7a69f124a8f5c..4110f1c1d9ebc 100644 --- a/test/1_stdlib/TestUUID.swift +++ b/test/1_stdlib/TestUUID.swift @@ -97,9 +97,9 @@ class TestUUID : TestUUIDSuper { UUID(uuidString: "f81d4fae-7dec-11d0-a765-00a0c91e6bf6")!, ] let anyHashables = values.map(AnyHashable.init) - expectEqual("UUID", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("UUID", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("UUID", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("UUID", String(describing: type(of: anyHashables[0].base))) + expectEqual("UUID", String(describing: type(of: anyHashables[1].base))) + expectEqual("UUID", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -111,9 +111,9 @@ class TestUUID : TestUUIDSuper { NSUUID(uuidString: "f81d4fae-7dec-11d0-a765-00a0c91e6bf6")!, ] let anyHashables = values.map(AnyHashable.init) - expectEqual("UUID", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("UUID", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("UUID", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("UUID", String(describing: type(of: anyHashables[0].base))) + expectEqual("UUID", String(describing: type(of: anyHashables[1].base))) + expectEqual("UUID", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } diff --git a/test/1_stdlib/TestUserInfo.swift b/test/1_stdlib/TestUserInfo.swift index f5cadc76a4296..bebe1ce306551 100644 --- a/test/1_stdlib/TestUserInfo.swift +++ b/test/1_stdlib/TestUserInfo.swift @@ -124,9 +124,9 @@ class TestUserInfo : TestUserInfoSuper { Notification(name: Notification.Name(rawValue: "TestOtherSwiftNotification")), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("Notification", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("Notification", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("Notification", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("Notification", String(describing: type(of: anyHashables[0].base))) + expectEqual("Notification", String(describing: type(of: anyHashables[1].base))) + expectEqual("Notification", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } @@ -138,9 +138,9 @@ class TestUserInfo : TestUserInfoSuper { NSNotification(name: Notification.Name(rawValue: "TestOtherSwiftNotification"), object: nil), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("Notification", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("Notification", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("Notification", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("Notification", String(describing: type(of: anyHashables[0].base))) + expectEqual("Notification", String(describing: type(of: anyHashables[1].base))) + expectEqual("Notification", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } diff --git a/validation-test/compiler_crashers_2_fixed/0022-rdar21625478.swift b/validation-test/compiler_crashers_2_fixed/0022-rdar21625478.swift index 5d6f783cbad71..a04dc24402e5c 100644 --- a/validation-test/compiler_crashers_2_fixed/0022-rdar21625478.swift +++ b/validation-test/compiler_crashers_2_fixed/0022-rdar21625478.swift @@ -182,7 +182,7 @@ extension LoggingType { } public var selfType: Any.Type { - return self.dynamicType + return type(of: self) } } diff --git a/validation-test/stdlib/AnyHashable.swift.gyb b/validation-test/stdlib/AnyHashable.swift.gyb index 9398b02cc2a76..8b8b982001981 100644 --- a/validation-test/stdlib/AnyHashable.swift.gyb +++ b/validation-test/stdlib/AnyHashable.swift.gyb @@ -596,7 +596,7 @@ AnyHashableTests.test("AnyHashable containing _SwiftNativeNSError") { expectEqual( .objCClassWrapper, SwiftRuntime.metadataKind(of: nsErrors.first!)) - expectEqual("_SwiftNativeNSError", String(describing: nsErrors[0].dynamicType)) + expectEqual("_SwiftNativeNSError", String(describing: type(of: nsErrors[0]))) checkHashable(nsErrors, equalityOracle: { $0 / 2 == $1 / 2 }) checkHashable( nsErrors.map(AnyHashable.init), diff --git a/validation-test/stdlib/Lazy.swift.gyb b/validation-test/stdlib/Lazy.swift.gyb index b9f4e9ea53923..2cab409589b18 100644 --- a/validation-test/stdlib/Lazy.swift.gyb +++ b/validation-test/stdlib/Lazy.swift.gyb @@ -624,7 +624,7 @@ func expectSequencePassthrough< S : LazySequenceProtocol, Base : LoggingType, Base.Iterator.Element == S.Iterator.Element >(_ s: S, base: Base, arbitraryElement: S.Iterator.Element, count: Int) { - let baseType = base.dynamicType + let baseType = type(of: base) SequenceLog.makeIterator.expectIncrement(baseType) { _ = s.makeIterator() } SequenceLog.underestimatedCount.expectIncrement(baseType) { @@ -697,7 +697,7 @@ tests.test("LazyCollection/Passthrough") { count: Int(expected.count)) let s = base.lazy - let baseType = base.dynamicType + let baseType = type(of: base) let startIndex = CollectionLog.startIndex.expectIncrement(baseType) { s.startIndex } @@ -752,11 +752,11 @@ tests.test("MapSequence/Passthrough") { let expected = (0..<100).map(OpaqueValue.init) let base = LoggingSequence(wrapping: expected) let mapped = base.lazy.map { OpaqueValue(Double($0.value) / 2.0) } - CollectionLog.underestimatedCount.expectIncrement(base.dynamicType) { + CollectionLog.underestimatedCount.expectIncrement(type(of: base)) { _ = mapped.underestimatedCount } // Not exactly passthrough because we wrap the result - CollectionLog.makeIterator.expectIncrement(base.dynamicType) { + CollectionLog.makeIterator.expectIncrement(type(of: base)) { _ = mapped.makeIterator() } } @@ -800,27 +800,27 @@ tests.test("LazyMapCollection/Passthrough") { let base = LoggingCollection(wrapping: expected) let mapped = base.lazy.map { OpaqueValue(Double($0.value) / 2.0) } - let startIndex = CollectionLog.startIndex.expectIncrement(base.dynamicType) { + let startIndex = CollectionLog.startIndex.expectIncrement(type(of: base)) { mapped.startIndex } - let endIndex = CollectionLog.endIndex.expectIncrement(base.dynamicType) { + let endIndex = CollectionLog.endIndex.expectIncrement(type(of: base)) { mapped.endIndex } // Not exactly passthrough, because mapping transforms the result - CollectionLog.subscriptIndex.expectIncrement(base.dynamicType) { + CollectionLog.subscriptIndex.expectIncrement(type(of: base)) { _ = mapped[startIndex] } - CollectionLog.isEmpty.expectIncrement(base.dynamicType) { + CollectionLog.isEmpty.expectIncrement(type(of: base)) { _ = mapped.isEmpty } - CollectionLog.first.expectIncrement(base.dynamicType) { + CollectionLog.first.expectIncrement(type(of: base)) { _ = mapped.first } - CollectionLog.underestimatedCount.expectIncrement(base.dynamicType) { + CollectionLog.underestimatedCount.expectIncrement(type(of: base)) { _ = mapped.underestimatedCount } // Not exactly passthrough because we wrap the result - CollectionLog.makeIterator.expectIncrement(base.dynamicType) { + CollectionLog.makeIterator.expectIncrement(type(of: base)) { _ = mapped.makeIterator() } } @@ -1231,7 +1231,7 @@ do { _ = flattened.map { _ in calls += 1 } expectEqual( expected.count, calls, - "unexpected laziness in \(flattened.dynamicType)") + "unexpected laziness in \(type(of: flattened))") } tests.test("FlattenSequence/Lazy/\(data)") { @@ -1243,7 +1243,7 @@ do { let flattened = base.joined() var calls = 0 _ = flattened.map { _ in calls += 1 } - expectEqual(0, calls, "unexpected eagerness in \(flattened.dynamicType)") + expectEqual(0, calls, "unexpected eagerness in \(type(of: flattened))") } % for Traversal in 'Forward', 'Bidirectional': @@ -1260,7 +1260,7 @@ do { _ = flattened.map { _ in calls += 1 } expectLE( expected.count, calls, - "unexpected laziness in \(flattened.dynamicType)") + "unexpected laziness in \(type(of: flattened))") } tests.test("Flatten${TraversalCollection}/Lazy\(data)") { @@ -1273,7 +1273,7 @@ do { var calls = 0 _ = flattened.map { _ in calls += 1 } - expectEqual(0, calls, "unexpected eagerness in \(flattened.dynamicType)") + expectEqual(0, calls, "unexpected eagerness in \(type(of: flattened))") } % end } diff --git a/validation-test/stdlib/NSDecimalNumberBridging.swift.gyb b/validation-test/stdlib/NSDecimalNumberBridging.swift.gyb index acbc5d89dd819..ecc731ef7ee46 100644 --- a/validation-test/stdlib/NSDecimalNumberBridging.swift.gyb +++ b/validation-test/stdlib/NSDecimalNumberBridging.swift.gyb @@ -14,9 +14,9 @@ NSDecimalNumberTests.test("AnyHashable containing Foundation.Decimal") { NSDecimalNumber(string: "20.0"), ] let anyHashables = values.map(AnyHashable.init) - expectEqual("Decimal", String(describing: anyHashables[0].base.dynamicType)) - expectEqual("Decimal", String(describing: anyHashables[1].base.dynamicType)) - expectEqual("Decimal", String(describing: anyHashables[2].base.dynamicType)) + expectEqual("Decimal", String(describing: type(of: anyHashables[0].base))) + expectEqual("Decimal", String(describing: type(of: anyHashables[1].base))) + expectEqual("Decimal", String(describing: type(of: anyHashables[2].base))) expectNotEqual(anyHashables[0], anyHashables[1]) expectEqual(anyHashables[1], anyHashables[2]) } diff --git a/validation-test/stdlib/NSNumberBridging.swift.gyb b/validation-test/stdlib/NSNumberBridging.swift.gyb index 52f538bd51d16..5d69d7d7599d8 100644 --- a/validation-test/stdlib/NSNumberBridging.swift.gyb +++ b/validation-test/stdlib/NSNumberBridging.swift.gyb @@ -97,7 +97,7 @@ NSNumberTests.test("Bool.init(_: NSNumber)") { } func isTypePreservingNSNumber(_ n: NSNumber) -> Bool { - let className = NSStringFromClass(n.dynamicType) + let className = NSStringFromClass(type(of: n)) return className.range(of: "_SwiftTypePreservingNSNumber") != nil } @@ -119,7 +119,7 @@ NSNumberTests.test("_SwiftTypePreservingNSNumber.init(coder:)") .code { let n: NSNumber = (42 as Int)._bridgeToObjectiveC() expectTrue(isTypePreservingNSNumber(n)) - let _SwiftTypePreservingNSNumberType: NSNumber.Type = n.dynamicType + let _SwiftTypePreservingNSNumberType: NSNumber.Type = type(of: n) let coder = NSKeyedUnarchiver(forReadingWith: Data([0])) expectCrashLater() _ = _SwiftTypePreservingNSNumberType.init(coder: coder) @@ -261,11 +261,11 @@ NSNumberTests.test("${Self} bridges to NSNumber (actually _SwiftTypePreservingNS expectEmpty(explicitNSNumber._toCustomAnyHashable()) expectTrue( Set(["__NSCFNumber", "__NSCFBoolean"]).contains( - String(describing: AnyHashable(explicitNSNumber).base.dynamicType))) + String(describing: type(of: AnyHashable(explicitNSNumber).base)))) expectEqual(AnyHashable(explicitNSNumber), AnyHashable(explicitNSNumber)) let ah = AnyHashable(bridgedNSNumber) - expectEqual("${Self}", String(describing: ah.base.dynamicType)) + expectEqual("${Self}", String(describing: type(of: ah.base))) % if Self in ['Float', 'Double', 'CGFloat']: // FIXME: remove special cases for floating point when we fix their // conformances to Equatable. diff --git a/validation-test/stdlib/NSStringBridging.swift.gyb b/validation-test/stdlib/NSStringBridging.swift.gyb index d8a1be97673e1..c44e39ce18651 100644 --- a/validation-test/stdlib/NSStringBridging.swift.gyb +++ b/validation-test/stdlib/NSStringBridging.swift.gyb @@ -19,7 +19,7 @@ NSStringTests.test("NSString bridges to String with custom AnyHashable") input in let s = input._bridgeToObjectiveC() expectNotEmpty(s._toCustomAnyHashable()) - expectEqual("String", String(describing: AnyHashable(s).base.dynamicType)) + expectEqual("String", String(describing: type(of: AnyHashable(s).base))) } NSStringTests.test("AnyHashable(NSString) uses Swift String comparison rules") { @@ -29,8 +29,8 @@ NSStringTests.test("AnyHashable(NSString) uses Swift String comparison rules") { let nss2: NSString = NSString(utf8String: "\u{e1}")! let ah1 = AnyHashable(nss1) let ah2 = AnyHashable(nss2) - expectEqual("String", String(describing: ah1.base.dynamicType)) - expectEqual("String", String(describing: ah2.base.dynamicType)) + expectEqual("String", String(describing: type(of: ah1.base))) + expectEqual("String", String(describing: type(of: ah2.base))) checkHashable([ah1, ah2], equalityOracle: { _ in true }) } diff --git a/validation-test/stdlib/SequenceType.swift.gyb b/validation-test/stdlib/SequenceType.swift.gyb index 3a0594f82629f..c48539b76613b 100644 --- a/validation-test/stdlib/SequenceType.swift.gyb +++ b/validation-test/stdlib/SequenceType.swift.gyb @@ -27,7 +27,7 @@ extension SequenceLog { extension LoggingSequence { func nonCustomizableOperation() { - Log.nonCustomizableOperation[self.dynamicType] += 1 + Log.nonCustomizableOperation[type(of: self)] += 1 return base.nonCustomizableOperation() } } From 8d23005cbebaa05f102c8140a46dae3acc0d83b7 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Sat, 30 Jul 2016 12:48:59 -0700 Subject: [PATCH 4/4] Improve fallthrough diagnostics --- lib/Parse/ParseExpr.cpp | 10 +++++++--- test/Parse/type_expr.swift | 13 +++++++------ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index a99bdfab4e547..b480784c43272 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -966,8 +966,10 @@ static bool canParseTypeOf(Parser &P) { // Parse to the closing paren. while (!P.Tok.is(tok::r_paren) && !P.Tok.is(tok::eof)) { - // Anything that looks like another argument label is bogus. - if (P.Tok.is(tok::comma) && P.peekToken().canBeArgumentLabel()) { + // Anything that looks like another argument label is bogus. It is + // sufficient to parse for a single trailing comma. Backtracking will + // fall back to an unresolved decl. + if (P.Tok.is(tok::comma)) { return false; } P.skipSingle(); @@ -1451,13 +1453,15 @@ ParserResult Parser::parseExprPostfix(Diag<> ID, bool isExprBasic) { // Handle the deprecated 'x.dynamicType' and migrate it to `type(of: x)` if (Tok.getText() == "dynamicType") { + BacktrackingScope backtrackScope(*this); 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: "); - continue; + + // fallthrough to an UnresolvedDotExpr. } // If we have '.', try to recover by creating diff --git a/test/Parse/type_expr.swift b/test/Parse/type_expr.swift index b0ea568834908..a33cdd09eb965 100644 --- a/test/Parse/type_expr.swift +++ b/test/Parse/type_expr.swift @@ -53,10 +53,8 @@ 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 {{expected member name or constructor call after type name}} + _ = Foo.dynamicType // expected-error {{type 'Foo' has no member 'dynamicType'}} // expected-error@-1 {{'.dynamicType' is deprecated. Use 'type(of: ...)' instead}} {{7-7=type(of: }} {{10-22=)}} - // expected-note@-2 {{add arguments after the type to construct a value of the type}} - // expected-note@-3 {{use '.self' to reference the type object}} _ = 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}} @@ -73,10 +71,8 @@ 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 {{expected member name or constructor call after type name}} + _ = Foo.Bar.dynamicType // expected-error {{type 'Foo.Bar' has no member 'dynamicType'}} // expected-error@-1 {{'.dynamicType' is deprecated. Use 'type(of: ...)' instead}} {{7-7=type(of: }} {{14-26=)}} - // expected-note@-2 {{add arguments after the type to construct a value of the type}} - // expected-note@-3 {{use '.self' to reference the type object}} } /* TODO allow '.Type' in expr context @@ -119,6 +115,10 @@ func typeOfShadowing() { return t } + func type(of t: T.Type, _ : U) -> T.Type { + return t + } + func type(_ t: T.Type) -> T.Type { return t } @@ -131,6 +131,7 @@ func typeOfShadowing() { _ = type(Gen.Bar) // No error here. _ = type(of: Gen.Bar.self, flag: false) // No error here. _ = type(fo: Foo.Bar.self) // No error here. + _ = type(of: Foo.Bar.self, [1, 2, 3]) // No error here. } func archetype(_: T) {