Skip to content

Commit 333fdbc

Browse files
committed
[MiscDiagnostics] Store a reference to a call node together with its arguments
1 parent 1ca4d7c commit 333fdbc

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ static void diagSyntacticUseRestrictions(const Expr *E, const DeclContext *DC,
7777
SmallPtrSet<DeclRefExpr*, 4> AlreadyDiagnosedBitCasts;
7878

7979
/// Keep track of the arguments to CallExprs.
80-
SmallPtrSet<Expr *, 2> CallArgs;
80+
/// Key -> an argument expression,
81+
/// Value -> a call argument is associated with.
82+
llvm::SmallDenseMap<Expr *, Expr *, 2> CallArgs;
8183

8284
bool IsExprStmt;
8385

@@ -141,30 +143,30 @@ static void diagSyntacticUseRestrictions(const Expr *E, const DeclContext *DC,
141143
checkUseOfMetaTypeName(Base);
142144

143145
if (auto *OLE = dyn_cast<ObjectLiteralExpr>(E)) {
144-
CallArgs.insert(OLE->getArg());
146+
CallArgs.insert({OLE->getArg(), E});
145147
}
146148

147149
if (auto *SE = dyn_cast<SubscriptExpr>(E))
148-
CallArgs.insert(SE->getIndex());
150+
CallArgs.insert({SE->getIndex(), E});
149151

150152
if (auto *DSE = dyn_cast<DynamicSubscriptExpr>(E))
151-
CallArgs.insert(DSE->getIndex());
153+
CallArgs.insert({DSE->getIndex(), E});
152154

153155
if (auto *KPE = dyn_cast<KeyPathExpr>(E)) {
154156
// raise an error if this KeyPath contains an effectful member.
155157
checkForEffectfulKeyPath(KPE);
156158

157159
for (auto Comp : KPE->getComponents()) {
158160
if (auto *Arg = Comp.getIndexExpr())
159-
CallArgs.insert(Arg);
161+
CallArgs.insert({Arg, E});
160162
}
161163
}
162164

163165
// Check function calls, looking through implicit conversions on the
164166
// function and inspecting the arguments directly.
165167
if (auto *Call = dyn_cast<ApplyExpr>(E)) {
166168
// Record call arguments.
167-
CallArgs.insert(Call->getArg());
169+
CallArgs.insert({Call->getArg(), E});
168170

169171
// Warn about surprising implicit optional promotions.
170172
checkOptionalPromotions(Call);

0 commit comments

Comments
 (0)