Skip to content

Commit 90d9688

Browse files
committed
[Typechecker] Do not check tuple labels for a function call
It's okay to have two function parameters with the same external label, as long as the internal labels are different. If not, we already emit a diagnostic for it, so no need to check
1 parent 935128c commit 90d9688

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,16 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E,
6464
class DiagnoseWalker : public ASTWalker {
6565
SmallPtrSet<Expr*, 4> AlreadyDiagnosedMetatypes;
6666
SmallPtrSet<DeclRefExpr*, 4> AlreadyDiagnosedBitCasts;
67-
68-
// Keep track of acceptable DiscardAssignmentExpr's.
67+
68+
/// Keep track of acceptable DiscardAssignmentExpr's.
6969
SmallPtrSet<DiscardAssignmentExpr*, 2> CorrectDiscardAssignmentExprs;
7070

7171
/// Keep track of the arguments to CallExprs.
7272
SmallPtrSet<Expr *, 2> CallArgs;
7373

74+
/// Keep track of function call
75+
ApplyExpr *applyExpr;
76+
7477
bool IsExprStmt;
7578

7679
public:
@@ -137,6 +140,7 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E,
137140
// Check function calls, looking through implicit conversions on the
138141
// function and inspecting the arguments directly.
139142
if (auto *Call = dyn_cast<ApplyExpr>(E)) {
143+
applyExpr = Call;
140144
// Record call arguments.
141145
CallArgs.insert(Call->getArg());
142146

@@ -247,25 +251,27 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E,
247251

248252
// Diagnose tuple expressions with duplicate element label
249253
if (auto *tupleExpr = dyn_cast<TupleExpr>(E)) {
250-
auto diagnose = false;
254+
if (!applyExpr) {
255+
auto diagnose = false;
251256

252-
llvm::SmallDenseSet<Identifier> names;
253-
names.reserve(tupleExpr->getNumElements());
257+
llvm::SmallDenseSet<Identifier> names;
258+
names.reserve(tupleExpr->getNumElements());
254259

255-
for (auto name : tupleExpr->getElementNames()) {
256-
if (name.empty())
257-
continue;
260+
for (auto name : tupleExpr->getElementNames()) {
261+
if (name.empty())
262+
continue;
258263

259-
if (names.count(name) == 1) {
260-
diagnose = true;
261-
break;
262-
}
264+
if (names.count(name) == 1) {
265+
diagnose = true;
266+
break;
267+
}
263268

264-
names.insert(name);
265-
}
269+
names.insert(name);
270+
}
266271

267-
if (diagnose) {
268-
TC.diagnose(tupleExpr->getLoc(), diag::tuple_duplicate_label);
272+
if (diagnose) {
273+
TC.diagnose(tupleExpr->getLoc(), diag::tuple_duplicate_label);
274+
}
269275
}
270276
}
271277

0 commit comments

Comments
 (0)