Skip to content

Commit 2f1a88c

Browse files
committed
Sema: Fold PackElementExpr(TypeExpr(R)) => TypeExpr(PackReferenceTypeRepr(R))
1 parent 075150c commit 2f1a88c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/Sema/PreCheckExpr.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,6 +1487,7 @@ bool PreCheckExpression::exprLooksLikeAType(Expr *expr) {
14871487
isa<ParenExpr>(expr) ||
14881488
isa<ArrowExpr>(expr) ||
14891489
isa<PackExpansionExpr>(expr) ||
1490+
isa<PackElementExpr>(expr) ||
14901491
isa<TupleExpr>(expr) ||
14911492
(isa<ArrayExpr>(expr) &&
14921493
cast<ArrayExpr>(expr)->getElements().size() == 1) ||
@@ -1984,6 +1985,15 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) {
19841985
}
19851986
}
19861987

1988+
// Fold a PackElementExpr into a TypeExpr when the element is a TypeExpr
1989+
if (auto *element = dyn_cast<PackElementExpr>(E)) {
1990+
if (auto *refExpr = dyn_cast<TypeExpr>(element->getPackRefExpr())) {
1991+
auto *repr = new (Ctx) PackReferenceTypeRepr(element->getStartLoc(),
1992+
refExpr->getTypeRepr());
1993+
return new (Ctx) TypeExpr(repr);
1994+
}
1995+
}
1996+
19871997
return nullptr;
19881998
}
19891999

0 commit comments

Comments
 (0)