Repository: phpbench/phpbench (php)

Issue:
Expression: Cannot multiply two unparenthesised array accesses
```
subject_params[0] * subject_params[0]
```

results in:

```
In PrettyErrorEvaluator.php line 69:                                                                                                    
                                                                                                                                        
  Expected "PhpBench\Expression\Ast\NumberNode" but got "PhpBench\Expression\Ast\ListNode":                                             
                                                                                                                                        
      Size: (variant_params[0] * variant_params[0])                                                                                     
                                 --------------                                              
                                                                                                                                        
                                                                    
In MainEvaluator.php line 40:                                       
                                                                                            
  Expected "PhpBench\Expression\Ast\NumberNode" but got "PhpBench\Expression\Ast\ListNode"  
                                                                                            In PrettyErrorEvaluator.php line 69:                                                                                                    
```
                                                                                            

Pull request:
Access precedence
Fixes #910

Patch:
diff --git a/lib/Expression/NodeEvaluator/ArithmeticOperatorEvaluator.php b/lib/Expression/NodeEvaluator/ArithmeticOperatorEvaluator.php
index fcc27660..cc786df4 100644
--- a/lib/Expression/NodeEvaluator/ArithmeticOperatorEvaluator.php
+++ b/lib/Expression/NodeEvaluator/ArithmeticOperatorEvaluator.php
@@ -22,6 +22,7 @@ class ArithmeticOperatorEvaluator implements NodeEvaluator
         }
 
         $leftValue = $evaluator->evaluateType($node->left(), NumberNode::class, $params);
+
         $rightValue = $evaluator->evaluateType($node->right(), NumberNode::class, $params);
 
         $value = $this->evaluateNode($node, $leftValue->value(), $rightValue->value());
diff --git a/lib/Expression/Parselet/ArrayAccessParselet.php b/lib/Expression/Parselet/ArrayAccessParselet.php
index 2bfff824..02663f16 100644
--- a/lib/Expression/Parselet/ArrayAccessParselet.php
+++ b/lib/Expression/Parselet/ArrayAccessParselet.php
@@ -28,6 +28,6 @@ class ArrayAccessParselet implements InfixParselet
 
     public function precedence(): int
     {
-        return Precedence::COMPARISON_EQUALITY;
+        return Precedence::ACCESS;
     }
 }
diff --git a/lib/Expression/Precedence.php b/lib/Expression/Precedence.php
index 893ba317..af60fdea 100644
--- a/lib/Expression/Precedence.php
+++ b/lib/Expression/Precedence.php
@@ -4,6 +4,7 @@ namespace PhpBench\Expression;
 
 final class Precedence
 {
+    public const ACCESS = 120;
     public const AS = 110;
     public const PRODUCT = 100;
     public const SUM = 90;


Test patch:
diff --git a/tests/Unit/Expression/Parselet/ArithmeticOperatorParseletTest.php b/tests/Unit/Expression/Parselet/ArithmeticOperatorParseletTest.php
index 9bd5b0af..2eeebba0 100644
--- a/tests/Unit/Expression/Parselet/ArithmeticOperatorParseletTest.php
+++ b/tests/Unit/Expression/Parselet/ArithmeticOperatorParseletTest.php
@@ -34,6 +34,14 @@ class ArithmeticOperatorParseletTest extends ParseletTestCase
         yield ['1 + 2', [], '3'];
 
         yield ['1 + 2 * 3 / 5 * 6 - 1', [], (string)(1 + 2 * 3 / 5 * 6 - 1)];
+
+        yield ['foo + foo', [
+            'foo' => 1,
+        ], '2'];
+
+        yield ['foo[0] + foo[0] * foo[0]', [
+            'foo' => [1],
+        ], '2'];
     }
 
     /**