Skip to content

Commit c305cb0

Browse files
committed
[Sema] Re-enable placeholder type parsing and folding
1 parent 990fc4b commit c305cb0

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

lib/Parse/ParsePattern.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,6 @@ static ParserStatus parseDefaultArgument(
152152
/// Determine whether we are at the start of a parameter name when
153153
/// parsing a parameter.
154154
bool Parser::startsParameterName(bool isClosure) {
155-
// '_' cannot be a type, so it must be a parameter name.
156-
if (Tok.is(tok::kw__))
157-
return true;
158-
159155
// To have a parameter name here, we need a name.
160156
if (!Tok.canBeArgumentLabel())
161157
return false;

lib/Parse/ParseType.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ LayoutConstraint Parser::parseLayoutConstraint(Identifier LayoutConstraintID) {
157157
/// type-simple '!'
158158
/// type-collection
159159
/// type-array
160+
/// '_'
160161
ParserResult<TypeRepr> Parser::parseTypeSimple(
161162
Diag<> MessageID, ParseTypeReason reason) {
162163
ParserResult<TypeRepr> ty;
@@ -189,6 +190,9 @@ ParserResult<TypeRepr> Parser::parseTypeSimple(
189190
ty = parseTypeCollection();
190191
break;
191192
}
193+
case tok::kw__:
194+
ty = makeParserResult(new (Context) PlaceholderTypeRepr(consumeToken()));
195+
break;
192196
case tok::kw_protocol:
193197
if (startsWithLess(peekToken())) {
194198
ty = parseOldStyleProtocolComposition();
@@ -1469,6 +1473,9 @@ bool Parser::canParseType() {
14691473
if (!consumeIf(tok::r_square))
14701474
return false;
14711475
break;
1476+
case tok::kw__:
1477+
consumeToken();
1478+
break;
14721479

14731480

14741481
default:

lib/Sema/PreCheckExpr.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,8 +1534,18 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) {
15341534
return simplifyNestedTypeExpr(UDE);
15351535
}
15361536

1537-
// TODO: Fold DiscardAssignmentExpr into a placeholder type here once parsing
1538-
// them is supported.
1537+
// Fold '_' into a placeholder type if it hasn't been marked as a "correct"
1538+
// discard assignment expr (on the LHS of an assignment). If we're inside a
1539+
// SequenceExpr, skip this step since we might have a correct
1540+
// DiscardAssignmentExpr that hasn't been marked as correct yet. The whole
1541+
// tree will be rechecked once SequenceExpr folding completes, anyway.
1542+
if (auto *DAE = dyn_cast<DiscardAssignmentExpr>(E)) {
1543+
if (!CorrectDiscardAssignmentExprs.count(DAE) && SequenceExprDepth == 0) {
1544+
auto *placeholderRepr =
1545+
new (getASTContext()) PlaceholderTypeRepr(DAE->getLoc());
1546+
return new (getASTContext()) TypeExpr(placeholderRepr);
1547+
}
1548+
}
15391549

15401550
// Fold T? into an optional type when T is a TypeExpr.
15411551
if (isa<OptionalEvaluationExpr>(E) || isa<BindOptionalExpr>(E)) {
@@ -1742,6 +1752,8 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) {
17421752
return nullptr;
17431753
if (auto *TyE = dyn_cast<TypeExpr>(E))
17441754
return TyE->getTypeRepr();
1755+
if (auto *DAE = dyn_cast<DiscardAssignmentExpr>(E))
1756+
return new (getASTContext()) PlaceholderTypeRepr(DAE->getLoc());
17451757
if (auto *TE = dyn_cast<TupleExpr>(E))
17461758
if (TE->getNumElements() == 0)
17471759
return TupleTypeRepr::createEmpty(ctx, TE->getSourceRange());

0 commit comments

Comments
 (0)