@@ -1042,8 +1042,6 @@ bool LuauVisitor::visit(LSLUnaryExpression *un_expr)
10421042 }
10431043
10441044 // Everything below here should be a (post|pre)(incr|decr) operator operating on an lvalue.
1045- auto *parent = un_expr->getParent ();
1046-
10471045 LUAU_ASSERT (un_expr->getChildExpr ()->getNodeSubType () == NODE_LVALUE_EXPRESSION);
10481046 auto *lvalue = (LSLLValueExpression *)un_expr->getChildExpr ();
10491047 auto *lvalue_sym = lvalue->getSymbol ();
@@ -1069,7 +1067,7 @@ bool LuauVisitor::visit(LSLUnaryExpression *un_expr)
10691067 // Especially important of mutating unary operators like `++bar` where
10701068 // they may be their own statement, and we don't necessarily care about
10711069 // pushing the result.
1072- const bool want_result = (parent && parent-> getNodeType () != NODE_STATEMENT );
1070+ const bool want_result = un_expr-> getResultNeeded ( );
10731071
10741072 // Pre-allocated by buildFunction() to ensure index < 256 for LOP_ADDK/SUBK
10751073 const auto one_const_idx = addConstantUnder (lvalue->getType ()->getOneValue (), UINT8_MAX);
@@ -1146,12 +1144,11 @@ bool LuauVisitor::visit(LSLBinaryExpression* bin_expr)
11461144 // assignment is very special
11471145 if (op == ' =' )
11481146 {
1149- auto *parent = bin_expr->getParent ();
11501147 // Basically, do we have to move this result for whoever asked for it.
11511148 // Often `=` is used as if it were a statement, but it's also an expression
11521149 // in LSL, which means that it can be used like `foo = bar = baz = 1`;
11531150 // Only MOVE the result to the target register if we'll actually end up using it.
1154- const bool want_result = (parent && parent-> getNodeType () != NODE_STATEMENT );
1151+ const bool want_result = bin_expr-> getResultNeeded ( );
11551152
11561153 // The left-hand side of `=` _must_ be an lvalue
11571154 LUAU_ASSERT (lhs->getNodeSubType () == NODE_LVALUE_EXPRESSION);
@@ -1160,7 +1157,7 @@ bool LuauVisitor::visit(LSLBinaryExpression* bin_expr)
11601157
11611158 uint8_t source_reg;
11621159 bool have_truncated_float = false ;
1163- if (auto *member = lval->getMember ())
1160+ if (lval->getMember () != nullptr )
11641161 {
11651162 // Evaluate this first, it may be re-used if we need to use the result of the
11661163 // assignment expression.
@@ -1223,8 +1220,7 @@ bool LuauVisitor::visit(LSLBinaryExpression* bin_expr)
12231220 // An evil, demonic operator, only exists for int *= float
12241221 if (op == OP_MUL_ASSIGN)
12251222 {
1226- auto *parent = bin_expr->getParent ();
1227- const bool want_result = (parent && parent->getNodeType () != NODE_STATEMENT);
1223+ const bool want_result = bin_expr->getResultNeeded ();
12281224
12291225 // assignment is special
12301226 LUAU_ASSERT (lhs->getNodeSubType () == NODE_LVALUE_EXPRESSION);
@@ -1261,11 +1257,14 @@ bool LuauVisitor::visit(LSLBinaryExpression* bin_expr)
12611257 mBuilder ->emitABC (LOP_MOVE, source_reg, func_reg, 0 );
12621258
12631259 // Something actually wants to capture the result of the `*=`,
1264- // pass it along .
1260+ // but that's not allowed in LSL. Throw a runtime error .
12651261 if (want_result)
12661262 {
1267- mBuilder ->emitABC (LOP_LSL_DOUBLE2FLOAT, floaty_reg, floaty_reg, 0 );
1268- maybeMove (expected_target, floaty_reg);
1263+ auto err_func_reg = allocReg (bin_expr);
1264+ pushImport (err_func_reg, " error" );
1265+ const auto msg_const_idx = addConstantString (sref (" cannot take result of integer *= float" ), INT16_MAX);
1266+ mBuilder ->emitAD (LOP_LOADK, allocReg (bin_expr), msg_const_idx);
1267+ mBuilder ->emitABC (LOP_CALL, err_func_reg, 1 + 1 , 0 + 1 );
12691268 }
12701269 return false ;
12711270 }
0 commit comments