fix(compiler): infer concat expressions as strings

pull/19/head
韩天峰 1 month ago
parent 20b54e3961
commit 39bec62e15
  1. 9
      phpunit/src/SsaAnalysisTest.php
  2. 3
      src/CompilerBase.php

@ -1263,6 +1263,15 @@ class SsaAnalysisTest extends TestCase
}
}
public function testDetectTypeOfConcatExpressions(): void
{
$concat = new Expr\BinaryOp\Concat(new Scalar\LNumber(1), new Scalar\String_(''));
$concatAssign = new Expr\AssignOp\Concat(new Expr\Variable('value'), new Scalar\LNumber(2));
$this->assertSame(Type::STR, $this->invoke('detectTypeOfExpr', $concat));
$this->assertSame(Type::STR, $this->invoke('detectTypeOfExpr', $concatAssign));
}
public function testDetectSsaDefTypeNull(): void
{
$ssaVar = new SsaVar(1, 'x');

@ -2299,6 +2299,9 @@ class CompilerBase implements PropertyAccessContext
case 'Expr_Array':
case 'Expr_Cast_Array':
return Type::ARRAY;
case 'Expr_BinaryOp_Concat':
case 'Expr_AssignOp_Concat':
return Type::STR;
case 'Expr_BinaryOp_Plus':
case 'Expr_BinaryOp_Minus':
case 'Expr_BinaryOp_Mul':

Loading…
Cancel
Save