diff --git a/src/sksl/dsl/DSLStatement.cpp b/src/sksl/dsl/DSLStatement.cpp index f51e4310a4..b4a13bfc6e 100644 --- a/src/sksl/dsl/DSLStatement.cpp +++ b/src/sksl/dsl/DSLStatement.cpp @@ -34,12 +34,13 @@ DSLStatement::DSLStatement(DSLBlock block) DSLStatement::DSLStatement(DSLExpression expr) { std::unique_ptr skslExpr = expr.release(); if (skslExpr) { - fStatement = SkSL::ExpressionStatement::Make(ThreadContext::Context(), std::move(skslExpr)); + fStatement = SkSL::ExpressionStatement::Convert(ThreadContext::Context(), + std::move(skslExpr)); } } DSLStatement::DSLStatement(std::unique_ptr expr) - : fStatement(SkSL::ExpressionStatement::Make(ThreadContext::Context(), std::move(expr))) { + : fStatement(SkSL::ExpressionStatement::Convert(ThreadContext::Context(), std::move(expr))) { SkASSERT(this->hasValue()); } diff --git a/src/sksl/ir/SkSLExpressionStatement.cpp b/src/sksl/ir/SkSLExpressionStatement.cpp index 40f408e6cb..6fb483a35b 100644 --- a/src/sksl/ir/SkSLExpressionStatement.cpp +++ b/src/sksl/ir/SkSLExpressionStatement.cpp @@ -12,11 +12,19 @@ namespace SkSL { -std::unique_ptr ExpressionStatement::Make(const Context& context, - std::unique_ptr expr) { +std::unique_ptr ExpressionStatement::Convert(const Context& context, + std::unique_ptr expr) { + // Expression-statements need to represent a complete expression. + // Report an error on intermediate expressions, like FunctionReference or TypeReference. if (expr->isIncomplete(context)) { return nullptr; } + return ExpressionStatement::Make(context, std::move(expr)); +} + +std::unique_ptr ExpressionStatement::Make(const Context& context, + std::unique_ptr expr) { + SkASSERT(!expr->isIncomplete(context)); if (context.fConfig->fSettings.fOptimize) { // Expression-statements without any side effect can be replaced with a Nop. diff --git a/src/sksl/ir/SkSLExpressionStatement.h b/src/sksl/ir/SkSLExpressionStatement.h index f5afcd7c77..a517a7c608 100644 --- a/src/sksl/ir/SkSLExpressionStatement.h +++ b/src/sksl/ir/SkSLExpressionStatement.h @@ -24,8 +24,11 @@ public: : INHERITED(expression->fPosition, kStatementKind) , fExpression(std::move(expression)) {} - // Creates an SkSL expression-statement. Note that there is never any type-coercion and no error - // cases are reported; any Expression can be an ExpressionStatement. + // Creates an SkSL expression-statement; reports errors via ErrorReporter. + static std::unique_ptr Convert(const Context& context, + std::unique_ptr expr); + + // Creates an SkSL expression-statement; reports errors via assertion. static std::unique_ptr Make(const Context& context, std::unique_ptr expr);