Skip to content

Commit b2c8670

Browse files
committed
[Typechecker] Check for CallExpr only, not ApplyExpr. Also, check for EnumElementDecl separately
1 parent 505f8db commit b2c8670

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,12 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E,
7171
/// Keep track of the arguments to CallExprs.
7272
SmallPtrSet<Expr *, 2> CallArgs;
7373

74-
/// Keep track of function call
75-
ApplyExpr *applyExpr;
76-
7774
bool IsExprStmt;
7875

7976
public:
8077
TypeChecker &TC;
8178
const DeclContext *DC;
79+
CallExpr *funcCallExpr = nullptr;
8280

8381
DiagnoseWalker(TypeChecker &TC, const DeclContext *DC, bool isExprStmt)
8482
: IsExprStmt(isExprStmt), TC(TC), DC(DC) {}
@@ -137,10 +135,13 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E,
137135
}
138136
}
139137

138+
if (cast_or_null<CallExpr>(E)) {
139+
funcCallExpr = cast<CallExpr>(E);
140+
}
141+
140142
// Check function calls, looking through implicit conversions on the
141143
// function and inspecting the arguments directly.
142144
if (auto *Call = dyn_cast<ApplyExpr>(E)) {
143-
applyExpr = Call;
144145
// Record call arguments.
145146
CallArgs.insert(Call->getArg());
146147

@@ -251,7 +252,14 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E,
251252

252253
// Diagnose tuple expressions with duplicate element label
253254
if (auto *tupleExpr = dyn_cast<TupleExpr>(E)) {
254-
if (!applyExpr) {
255+
// FIXME: Duplicate labels on enum payloads should be diagnosed
256+
// when declared, not when called.
257+
bool isEnumCase = funcCallExpr
258+
? cast_or_null<EnumElementDecl>(
259+
funcCallExpr->getCalledValue()) != nullptr
260+
: false;
261+
262+
if (!funcCallExpr || isEnumCase) {
255263
auto diagnose = false;
256264

257265
llvm::SmallDenseSet<Identifier> names;

0 commit comments

Comments
 (0)