Skip to content

Commit

Permalink
Add more tests for private(set) properties implicit final
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Oct 5, 2024
1 parent 0b7c768 commit ccc8820
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
3 changes: 1 addition & 2 deletions src/main/php/lang/ast/emit/AsymmetricVisibility.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ protected function emitProperty($result, $property) {
$modifiers & MODIFIER_PROTECTED && $modifiers&= ~0x0000800;
} else if ($modifiers & 0x0001000) {
$checks= [$this->private($property->name, 'modify private(set)')];
$modifiers & MODIFIER_PRIVATE && $modifiers&= ~0x0001000;
$modifiers|= MODIFIER_FINAL;
$modifiers & MODIFIER_PRIVATE ? $modifiers&= ~0x0001000 : $modifiers|= MODIFIER_FINAL;
}

// Emit XP meta information for the reflection API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,19 @@ public function protected_set_reflection() {
);
}

#[Test]
public function private_set_implicitely_final_in_reflection() {
#[Test, Values(['protected', 'public'])]
public function private_set_implicitely_final_in_reflection($modifier) {
$t= $this->declare('class %T {
public private(set) string $fixture= "Test";
'.$modifier.' private(set) string $fixture= "Test";
}');

Assert::equals(
'public final private(set) string $fixture',
$modifier.' final private(set) string $fixture',
$t->property('fixture')->toString()
);
}

#[Test, Values(['protected', 'public'])]
#[Test, Values(['private', 'protected', 'public'])]
public function same_modifier_for_get_and_set($modifier) {
$t= $this->declare('class %T {
'.$modifier.' '.$modifier.'(set) string $fixture= "Test";
Expand All @@ -136,18 +136,6 @@ public function same_modifier_for_get_and_set($modifier) {
);
}

#[Test]
public function private_modifier_for_get_and_set() {
$t= $this->declare('class %T {
private private(set) string $fixture= "Test";
}');

Assert::equals(
'private final string $fixture',
$t->property('fixture')->toString()
);
}

#[Test]
public function interaction_with_hooks() {
$t= $this->declare('class %T {
Expand Down

0 comments on commit ccc8820

Please sign in to comment.