diff options
Diffstat (limited to 'source/slang/slang-check-expr.cpp')
| -rw-r--r-- | source/slang/slang-check-expr.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp index d2f338e65..425548518 100644 --- a/source/slang/slang-check-expr.cpp +++ b/source/slang/slang-check-expr.cpp @@ -3229,6 +3229,40 @@ Expr* SemanticsExprVisitor::visitInvokeExpr(InvokeExpr* expr) if (auto newExpr = convertToLogicOperatorExpr(expr)) return newExpr; + // Check for comma operator usage and emit warning if not in for-loop side effect context + // Skip warning in Slang 2026+ mode where parentheses create tuples + if (!isSlang2026OrLater(this)) + { + bool exprIsInfixExpr = false; + InfixExpr* infixExpr = nullptr; + if (auto candidateInfixExpr = as<InfixExpr>(expr)) + { + exprIsInfixExpr = true; + infixExpr = candidateInfixExpr; + } + + bool functionExprIsVarExpr = false; + VarExpr* varExpr = nullptr; + if (exprIsInfixExpr) + { + if (auto candidateVarExpr = as<VarExpr>(infixExpr->functionExpr)) + { + functionExprIsVarExpr = true; + varExpr = candidateVarExpr; + } + } + + if (functionExprIsVarExpr && varExpr->name && varExpr->name->text == ",") + { + // Allow comma operators in for-loop side effects and expand expressions without + // warning + if (!getInForLoopSideEffect() && !m_parentExpandExpr) + { + getSink()->diagnose(infixExpr, Diagnostics::commaOperatorUsedInExpression); + } + } + } + expr->functionExpr = CheckTerm(expr->functionExpr); if (auto baseType = as<DeclRefType>(expr->functionExpr->type)) |
