From 5929c83e8c6de220de129c1e852e152f001bf443 Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Sat, 16 Mar 2024 17:57:13 +0100 Subject: [PATCH] Implement short set in accordance with RFC See https://wiki.php.net/rfc/property-hooks#short-set, changed from original --- src/main/php/lang/ast/emit/PropertyHooks.class.php | 2 +- .../lang/ast/unittest/emit/PropertyHooksTest.class.php | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/php/lang/ast/emit/PropertyHooks.class.php b/src/main/php/lang/ast/emit/PropertyHooks.class.php index 6ab32d17..747722f1 100755 --- a/src/main/php/lang/ast/emit/PropertyHooks.class.php +++ b/src/main/php/lang/ast/emit/PropertyHooks.class.php @@ -142,7 +142,7 @@ protected function emitProperty($result, $property) { $method, new Signature($hook->parameter ? [$hook->parameter] : [new Parameter('value', null)], null), null === $hook->expression ? null : [$this->rewriteHook( - $hook->expression, + $hook->expression instanceof Block ? $hook->expression : new Assignment($virtual, '=', $hook->expression), $property->name, $virtual, $literal diff --git a/src/test/php/lang/ast/unittest/emit/PropertyHooksTest.class.php b/src/test/php/lang/ast/unittest/emit/PropertyHooksTest.class.php index 0a1b7542..366091d1 100755 --- a/src/test/php/lang/ast/unittest/emit/PropertyHooksTest.class.php +++ b/src/test/php/lang/ast/unittest/emit/PropertyHooksTest.class.php @@ -55,7 +55,7 @@ public function run() { #[Test] public function set_expression() { $r= $this->run('class %T { - public $test { set => $this->test= ucfirst($value); } + public $test { set => ucfirst($value); } public function run() { $this->test= "test"; @@ -96,7 +96,7 @@ public function get_and_set_using_property() { $r= $this->run('class %T { public $test { get => $this->test; - set => $this->test= ucfirst($value); + set => ucfirst($value); } public function run() { @@ -128,7 +128,7 @@ public function run() { public function typed_set() { $r= $this->run('use util\\Bytes; class %T { public string $test { - set(string|Bytes $arg) => $this->test= ucfirst($arg); + set(string|Bytes $arg) => ucfirst($arg); } public function run() { @@ -144,7 +144,7 @@ public function run() { public function typed_mismatch() { $this->run('class %T { public string $test { - set(int $times) => $this->test= $times." times"; + set(int $times) => $times." times"; } public function run() { @@ -203,7 +203,7 @@ public function reflection() { $t= $this->declare('class %T { public string $test { get => $this->test; - set => $this->test= ucfirst($value); + set => ucfirst($value); } }');