Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/AST/DiagnosticsParse.def
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ 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,
ERROR(expr_dynamictype_deprecated,PointsToFirstBadToken,
"'.dynamicType' is deprecated. Use 'type(of: ...)' instead", ())

//------------------------------------------------------------------------------
Expand Down
3 changes: 0 additions & 3 deletions include/swift/Parse/Tokens.def
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,6 @@ KEYWORD(__COLUMN__)
KEYWORD(__FUNCTION__)
KEYWORD(__DSO_HANDLE__)

// FIXME(SE-0096): REMOVE ME
KEYWORD(dynamicType)

// Pattern keywords.
KEYWORD(_)

Expand Down
1 change: 0 additions & 1 deletion lib/Basic/StringExtras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ bool swift::canBeArgumentLabel(StringRef identifier) {

bool swift::canBeMemberName(StringRef identifier) {
return llvm::StringSwitch<bool>(identifier)
.Case("dynamicType", false)
.Case("init", false)
.Case("Protocol", false)
.Case("self", false)
Expand Down
84 changes: 44 additions & 40 deletions lib/Parse/ParseExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,32 @@ getMagicIdentifierLiteralKind(tok Kind) {
}
}

/// See if type(of: <expr>) 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. 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();
}
return true;
}

/// parseExprPostfix
///
Expand Down Expand Up @@ -1095,8 +1121,8 @@ ParserResult<Expr> 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: <expr>)'.
if (canParseTypeOf(*this)) {
Result = parseExprTypeOf();
break;
}
Expand Down Expand Up @@ -1418,35 +1444,25 @@ ParserResult<Expr> 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
// Handle "x.self" expr.
if (Tok.is(tok::kw_self)) {
Result = makeParserResult(
new (Context) DotSelfExpr(Result.get(), TokLoc, consumeToken()));
continue;
}

// 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: ");

// HACK: Arbitrary.
auto loc = range.Start;
auto dt = new (Context) DynamicTypeExpr(loc, loc, Result.get(), loc, Type());
dt->setImplicit();
Result = makeParserResult(dt);
continue;
// fallthrough to an UnresolvedDotExpr.
}


// Handle "x.self" expr.
if (Tok.is(tok::kw_self)) {
Result = makeParserResult(
new (Context) DotSelfExpr(Result.get(), TokLoc, consumeToken()));
continue;
}


// If we have '.<keyword><code_complete>', try to recover by creating
// an identifier with the same spelling as the keyword.
Expand Down Expand Up @@ -3030,26 +3046,14 @@ ParserResult<Expr> 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.
Expand Down
1 change: 0 additions & 1 deletion lib/Parse/ParseType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ ParserResult<TypeRepr> Parser::parseTypeSimple(Diag<> MessageID,
consumeToken(tok::code_complete);
return makeParserCodeCompletionResult<TypeRepr>();
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.
Expand Down
4 changes: 2 additions & 2 deletions lib/SILOptimizer/Mandatory/DIMemoryUseCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
12 changes: 6 additions & 6 deletions test/1_stdlib/TestAffineTransform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
Expand All @@ -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])
}
Expand Down
12 changes: 6 additions & 6 deletions test/1_stdlib/TestCalendar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
Expand All @@ -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])
}
Expand Down
12 changes: 6 additions & 6 deletions test/1_stdlib/TestCharacterSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
Expand All @@ -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])
}
Expand Down
12 changes: 6 additions & 6 deletions test/1_stdlib/TestData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
Expand All @@ -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])
}
Expand Down
24 changes: 12 additions & 12 deletions test/1_stdlib/TestDate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
Expand All @@ -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])
}
Expand All @@ -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])
}
Expand All @@ -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])
}
Expand Down
12 changes: 6 additions & 6 deletions test/1_stdlib/TestDateInterval.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
Expand All @@ -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])
}
Expand Down
12 changes: 6 additions & 6 deletions test/1_stdlib/TestIndexPath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
Expand All @@ -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])
}
Expand Down
Loading