From 039304020c4544a6cd0b8905739b48a3b1032240 Mon Sep 17 00:00:00 2001 From: alwaysLinger <43213269+alwaysLinger@users.noreply.github.com> Date: Tue, 13 Oct 2026 23:25:46 +0800 Subject: [PATCH 1/2] fix(compiler): write inherited promoted properties into their declared slot --- src/Generator/PropertyPromotion.php | 6 +++- .../promotion-inherited-private-scope.phpt | 29 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tests/compiler/object_ctor/promotion-inherited-private-scope.phpt diff --git a/src/Generator/PropertyPromotion.php b/src/Generator/PropertyPromotion.php index f59c1b99..3338c5bb 100644 --- a/src/Generator/PropertyPromotion.php +++ b/src/Generator/PropertyPromotion.php @@ -24,7 +24,11 @@ protected function genPropertyPromotion(ArgInfo $argInfo): string return 'this_.' . $this->getNativeObjectPropertyCppName($property, $this->classDef) . ' = ' . $value . ';' . PHP_EOL; } - $code .= 'this_.setProperty(' . $this->genCharPtr($propertyName) . ', ' . $argInfo->name . ')'; + $scope = $this->class !== '' + ? $this->getClassEntryPtr($this->getFullClassName()) + : 'nullptr'; + $code .= 'typephp_write_property_scoped(this_, ' + . $this->genCharPtr($propertyName) . ', ' . $argInfo->name . ', ' . $scope . ')'; $code .= ";\n"; return $code; } diff --git a/tests/compiler/object_ctor/promotion-inherited-private-scope.phpt b/tests/compiler/object_ctor/promotion-inherited-private-scope.phpt new file mode 100644 index 00000000..3dec531d --- /dev/null +++ b/tests/compiler/object_ctor/promotion-inherited-private-scope.phpt @@ -0,0 +1,29 @@ +--TEST-- +Constructor promotion writes inherited private promoted properties into the declared slot +--FILE-- + +--EXPECT-- +object(ChildCls)#1 (1) { + ["name":"ParentCls":private]=> + string(5) "hello" +} +object(ParentCls)#2 (1) { + ["name":"ParentCls":private]=> + string(6) "direct" +} From c04dbf75094273d82e975db2ed7fbf3db0e3b84b Mon Sep 17 00:00:00 2001 From: alwaysLinger <43213269+alwaysLinger@users.noreply.github.com> Date: Wed, 14 Oct 2026 00:15:11 +0800 Subject: [PATCH 2/2] test(phpunit): expect scoped write from genPropertyPromotion --- phpunit/src/TraitsTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/phpunit/src/TraitsTest.php b/phpunit/src/TraitsTest.php index 4bb014e5..af6a7f27 100644 --- a/phpunit/src/TraitsTest.php +++ b/phpunit/src/TraitsTest.php @@ -198,7 +198,10 @@ public function testGenPropertyPromotion(): void $argInfo->type = 'php::Str'; $result = $this->invoke('genPropertyPromotion', $argInfo); - $this->assertStringContainsString('this_.setProperty', $result); + $this->assertStringContainsString( + 'typephp_write_property_scoped(this_, "title", title, nullptr)', + $result, + ); $this->assertStringContainsString('title', $result); }