File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -716,7 +716,8 @@ function Parser:expressionPow(scope)
716716 local lhs = self :tableOrFunctionLiteral (scope );
717717
718718 if (consume (self , TokenKind .Symbol , " ^" )) then
719- local rhs = self :expressionPow (scope );
719+ -- Allow unary operators on the rhs (e.g. 2 ^ #x, 2 ^ -x) while preserving right-associativity. ~ SpinnySpiwal
720+ local rhs = self :expressionUnary (scope );
720721 return Ast .PowExpression (lhs , rhs , true );
721722 end
722723
Original file line number Diff line number Diff line change 22-- Syntax Test Suite
33-- Target: Unparser
44-- Author: SpinnySpiwal
5- -- Purpose: Validate appropriate unparser functionality, specifically in unseen edge cases.
5+ -- Purpose: Validate appropriate parser & unparser functionality, specifically in unseen edge cases.
6+ -- Update 1: Added test for precedence bug fix in expressionPow.
67-- ============================================================
78
89local char = (" " ).char
@@ -17,3 +18,21 @@ local ok = pcall(function(...)
1718 print (" hello " .. ... )
1819end )
1920print (ok and " no" or " yes" )
21+
22+ local function getString ()
23+ return " this string is 24 chars!"
24+ end
25+
26+ -- Test for precedence bug fix in expressionPow
27+ if 2 ^ # getString () == 16777216 then
28+ print (" TEST 1 PASSED" )
29+ else
30+ print (" TEST 1 FAILED" )
31+ end
32+
33+ -- Check if it still works the other way around
34+ if (# getString ()) ^ 2 == 576 then
35+ print (" TEST 2 PASSED" )
36+ else
37+ print (" TEST 2 FAILED" )
38+ end
You can’t perform that action at this time.
0 commit comments