@@ -20,6 +20,19 @@ use emmylua_parser::{
2020 LuaNameExpr , LuaUnaryExpr , LuaVarExpr ,
2121} ;
2222
23+ //======================================================================================
24+ // Helper functions
25+ //======================================================================================
26+
27+ /// Check if an expression is a vararg (...) literal
28+ fn is_vararg_expr ( expr : & LuaExpr ) -> bool {
29+ if let LuaExpr :: LiteralExpr ( lit) = expr {
30+ matches ! ( lit. get_literal( ) , Some ( LuaLiteralToken :: Dots ( _) ) )
31+ } else {
32+ false
33+ }
34+ }
35+
2336//======================================================================================
2437// NEW API: ExpDesc-based expression compilation (Lua 5.4 compatible)
2538//======================================================================================
@@ -585,11 +598,14 @@ fn compile_binary_expr_desc(c: &mut Compiler, expr: &LuaBinaryExpr) -> Result<Ex
585598 let concat_base = c. freereg ;
586599 alloc_register ( c) ; // for left operand copy
587600 alloc_register ( c) ; // for right operand
588-
601+
589602 emit_move ( c, concat_base, left_reg) ;
590603 emit_move ( c, concat_base + 1 , right_reg) ;
591- emit ( c, Instruction :: encode_abc ( OpCode :: Concat , concat_base, 1 , 0 ) ) ;
592-
604+ emit (
605+ c,
606+ Instruction :: encode_abc ( OpCode :: Concat , concat_base, 1 , 0 ) ,
607+ ) ;
608+
593609 result_reg = concat_base;
594610 // Reset freereg to result_reg + 1 (concat consumes right operand)
595611 c. freereg = result_reg + 1 ;
@@ -1676,10 +1692,10 @@ fn compile_binary_expr_to(
16761692 emit_move ( c, concat_reg, left_reg) ;
16771693 emit_move ( c, concat_reg + 1 , right_reg) ;
16781694 emit ( c, Instruction :: encode_abc ( OpCode :: Concat , concat_reg, 1 , 0 ) ) ;
1679-
1695+
16801696 // Reset freereg (concat consumes right operand)
16811697 c. freereg = concat_reg + 1 ;
1682-
1698+
16831699 if let Some ( d) = dest {
16841700 if d != concat_reg {
16851701 emit_move ( c, d, concat_reg) ;
@@ -2618,8 +2634,7 @@ fn compile_table_expr_to(
26182634 if field. is_value_field ( ) {
26192635 // Check if it's a simple value (not ... or call as last element)
26202636 if let Some ( value_expr) = field. get_value_expr ( ) {
2621- let is_dots = matches ! ( & value_expr, LuaExpr :: LiteralExpr ( lit)
2622- if matches!( lit. get_literal( ) , Some ( LuaLiteralToken :: Dots ( _) ) ) ) ;
2637+ let is_dots = is_vararg_expr ( & value_expr) ;
26232638 let is_call = matches ! ( & value_expr, LuaExpr :: CallExpr ( _) ) ;
26242639 let is_last = i == fields. len ( ) - 1 ;
26252640
@@ -2684,8 +2699,7 @@ fn compile_table_expr_to(
26842699 if field. is_value_field ( ) {
26852700 // Array element or special case (vararg/call at end)
26862701 if let Some ( value_expr) = field. get_value_expr ( ) {
2687- let is_dots = matches ! ( & value_expr, LuaExpr :: LiteralExpr ( lit)
2688- if matches!( lit. get_literal( ) , Some ( LuaLiteralToken :: Dots ( _) ) ) ) ;
2702+ let is_dots = is_vararg_expr ( & value_expr) ;
26892703 let is_call = matches ! ( & value_expr, LuaExpr :: CallExpr ( _) ) ;
26902704
26912705 if is_last_field && is_dots {
0 commit comments