Skip to content

Commit 00aad22

Browse files
committed
[AST] Store a source location for '.element' in MaterializePackExpr.
1 parent 5091886 commit 00aad22

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

include/swift/AST/Expr.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3659,14 +3659,18 @@ class MaterializePackExpr final : public Expr {
36593659
/// The expression from which to materialize a pack.
36603660
Expr *FromExpr;
36613661

3662-
MaterializePackExpr(Expr *fromExpr, bool implicit, Type type)
3662+
/// The source location of \c .element
3663+
SourceLoc ElementLoc;
3664+
3665+
MaterializePackExpr(Expr *fromExpr, SourceLoc elementLoc,
3666+
Type type, bool implicit)
36633667
: Expr(ExprKind::MaterializePack, implicit, type),
3664-
FromExpr(fromExpr) {}
3668+
FromExpr(fromExpr), ElementLoc(elementLoc) {}
36653669

36663670
public:
36673671
static MaterializePackExpr *create(ASTContext &ctx, Expr *fromExpr,
3668-
bool implicit = false,
3669-
Type type = Type());
3672+
SourceLoc elementLoc, Type type,
3673+
bool implicit = false);
36703674

36713675
Expr *getFromExpr() const { return FromExpr; }
36723676

@@ -3679,7 +3683,7 @@ class MaterializePackExpr final : public Expr {
36793683
}
36803684

36813685
SourceLoc getEndLoc() const {
3682-
return FromExpr->getEndLoc();
3686+
return ElementLoc;
36833687
}
36843688

36853689
static bool classof(const Expr *E) {

lib/AST/Expr.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,8 +1307,10 @@ PackElementExpr::create(ASTContext &ctx, SourceLoc eachLoc, Expr *packRefExpr,
13071307

13081308
MaterializePackExpr *
13091309
MaterializePackExpr::create(ASTContext &ctx, Expr *fromExpr,
1310-
bool implicit, Type type) {
1311-
return new (ctx) MaterializePackExpr(fromExpr, implicit, type);
1310+
SourceLoc elementLoc,
1311+
Type type, bool implicit) {
1312+
return new (ctx) MaterializePackExpr(fromExpr, elementLoc,
1313+
type, implicit);
13121314
}
13131315

13141316
SequenceExpr *SequenceExpr::create(ASTContext &ctx, ArrayRef<Expr*> elements) {

lib/Sema/CSApply.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3415,10 +3415,10 @@ namespace {
34153415
}
34163416

34173417
case OverloadChoiceKind::MaterializePack: {
3418-
auto packType = simplifyType(cs.getType(expr));
3418+
auto packType = solution.getResolvedType(expr);
34193419
return cs.cacheType(
34203420
MaterializePackExpr::create(cs.getASTContext(),
3421-
base, /*implicit=*/false,
3421+
base, expr->getEndLoc(),
34223422
packType));
34233423
}
34243424

0 commit comments

Comments
 (0)