From 39bec62e15e37e0fe173fff4982840dc37c6f68f Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Tue, 14 Jul 2026 12:38:24 +0800 Subject: [PATCH] fix(compiler): infer concat expressions as strings --- phpunit/src/SsaAnalysisTest.php | 9 +++++++++ src/CompilerBase.php | 3 +++ 2 files changed, 12 insertions(+) diff --git a/phpunit/src/SsaAnalysisTest.php b/phpunit/src/SsaAnalysisTest.php index 89396f87..e0739242 100644 --- a/phpunit/src/SsaAnalysisTest.php +++ b/phpunit/src/SsaAnalysisTest.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'); diff --git a/src/CompilerBase.php b/src/CompilerBase.php index 2d8f90dd..36da7790 100644 --- a/src/CompilerBase.php +++ b/src/CompilerBase.php @@ -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':