Skip to content

Commit e9cb62d

Browse files
authored
Merge pull request #17987 from brentdax/youll-get-no-argument
2 parents 568d081 + e797fe5 commit e9cb62d

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

include/swift/AST/Expr.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3817,11 +3817,17 @@ class ApplyExpr : public Expr {
38173817

38183818
/// The argument being passed to it, and whether it's a 'super' argument.
38193819
llvm::PointerIntPair<Expr *, 1, bool> ArgAndIsSuper;
3820+
3821+
/// Returns true if \c e could be used as the call's argument. For most \c ApplyExpr
3822+
/// subclasses, this means it is a \c ParenExpr, \c TupleExpr, or
3823+
/// \c TupleShuffleExpr.
3824+
bool validateArg(Expr *e) const;
38203825

38213826
protected:
38223827
ApplyExpr(ExprKind Kind, Expr *Fn, Expr *Arg, bool Implicit, Type Ty = Type())
38233828
: Expr(Kind, Implicit, Ty), Fn(Fn), ArgAndIsSuper(Arg, false) {
38243829
assert(classof((Expr*)this) && "ApplyExpr::classof out of date");
3830+
assert(validateArg(Arg) && "Arg is not a permitted expr kind");
38253831
Bits.ApplyExpr.ThrowsIsSet = false;
38263832
}
38273833

@@ -3832,8 +3838,7 @@ class ApplyExpr : public Expr {
38323838

38333839
Expr *getArg() const { return ArgAndIsSuper.getPointer(); }
38343840
void setArg(Expr *e) {
3835-
assert((getKind() != ExprKind::Binary || isa<TupleExpr>(e)) &&
3836-
"BinaryExprs must have a TupleExpr as the argument");
3841+
assert(validateArg(e) && "Arg is not a permitted expr kind");
38373842
ArgAndIsSuper = {e, ArgAndIsSuper.getInt()};
38383843
}
38393844

@@ -5120,6 +5125,15 @@ inline bool Expr::isInfixOperator() const {
51205125
return isa<BinaryExpr>(this) || isa<IfExpr>(this) ||
51215126
isa<AssignExpr>(this) || isa<ExplicitCastExpr>(this);
51225127
}
5128+
5129+
inline bool ApplyExpr::validateArg(Expr *e) const {
5130+
if (isa<SelfApplyExpr>(this))
5131+
return true;
5132+
else if (isa<BinaryExpr>(this))
5133+
return isa<TupleExpr>(e);
5134+
else
5135+
return isa<ParenExpr>(e) || isa<TupleExpr>(e) || isa<TupleShuffleExpr>(e);
5136+
}
51235137

51245138
inline Expr *const *CollectionExpr::getTrailingObjectsPointer() const {
51255139
if (auto ty = dyn_cast<ArrayExpr>(this))

lib/IDE/CodeCompletion.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3297,7 +3297,10 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
32973297
// escape and there isn't a better way to allocate scratch Expr nodes.
32983298
UnresolvedDeclRefExpr UDRE(op->getName(), DeclRefKind::PostfixOperator,
32993299
DeclNameLoc(expr->getSourceRange().End));
3300-
PostfixUnaryExpr opExpr(&UDRE, expr);
3300+
ParenExpr parenExpr(expr->getSourceRange().Start, expr,
3301+
expr->getSourceRange().End,
3302+
/*hasTrailingClosure=*/false);
3303+
PostfixUnaryExpr opExpr(&UDRE, &parenExpr);
33013304
Expr *tempExpr = &opExpr;
33023305
ConcreteDeclRef referencedDecl;
33033306
if (auto T = getTypeOfCompletionContextExpr(

lib/Sema/CSApply.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7360,9 +7360,8 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
73607360
return cs.getType(E);
73617361
};
73627362

7363-
auto callSubExpr = CallExpr::create(tc.Context, body, escapable, {}, {},
7364-
/*trailing closure*/ false,
7365-
/*implicit*/ true, Type(), getType);
7363+
auto callSubExpr = CallExpr::createImplicit(tc.Context, body, {escapable}, {}, getType);
7364+
cs.cacheSubExprTypes(callSubExpr);
73667365
cs.setType(callSubExpr, resultType);
73677366

73687367
auto replacement = new (tc.Context)
@@ -7414,10 +7413,8 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
74147413
return cs.getType(E);
74157414
};
74167415

7417-
auto callSubExpr = CallExpr::create(tc.Context, body, opaqueValue, {},
7418-
{}, /*trailing closure*/ false,
7419-
/*implicit*/ true,
7420-
Type(), getType);
7416+
auto callSubExpr = CallExpr::createImplicit(tc.Context, body, {opaqueValue}, {}, getType);
7417+
cs.cacheSubExprTypes(callSubExpr);
74217418
cs.setType(callSubExpr, resultTy);
74227419

74237420
auto replacement = new (tc.Context)

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -986,8 +986,10 @@ namespace {
986986

987987
std::pair<bool, Expr *> walkToExprPre(Expr *expr) override {
988988
// If this is a call, record the argument expression.
989-
if (auto call = dyn_cast<CallExpr>(expr)) {
990-
CallArgs.insert(call->getArg());
989+
if (auto call = dyn_cast<ApplyExpr>(expr)) {
990+
if (!isa<SelfApplyExpr>(expr)) {
991+
CallArgs.insert(call->getArg());
992+
}
991993
}
992994

993995
// If this is an unresolved member with a call argument (e.g.,

0 commit comments

Comments
 (0)