Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Readonly class not marking props readonly, fatal error not detected #11029

Open
dkarlovi opened this issue Jun 27, 2024 · 1 comment
Open

Readonly class not marking props readonly, fatal error not detected #11029

dkarlovi opened this issue Jun 27, 2024 · 1 comment

Comments

@dkarlovi
Copy link
Contributor

dkarlovi commented Jun 27, 2024

https://psalm.dev/r/e675241c02

This causes a fatal error with PHP 8.3

https://3v4l.org/bb3Qn#v8.3.8

With @psalm-immutable it works. This also works correctly https://psalm.dev/r/219055d746

Copy link

psalm-github-bot bot commented Jun 27, 2024

I found these snippets:

https://psalm.dev/r/e675241c02
<?php

readonly class Service
{
    public function __construct(private string $s)
    {}
    
    public function set(string $s): void
    {
        $this->s = $s;
    }
}

$s = new Service('a');
$s->set('b');
Psalm output (using commit 16b24bd):

No issues!
https://psalm.dev/r/219055d746
<?php

class Service
{
    public function __construct(private readonly string $s)
    {}
    
    public function set(string $s): void
    {
        $this->s = $s;
    }
}

$s = new Service('a');
$s->set('b');
Psalm output (using commit 16b24bd):

ERROR: InaccessibleProperty - 10:9 - Service::$s is marked readonly

@dkarlovi dkarlovi changed the title Readonly class not marked as immutable by default Readonly class not marked as immutable by default, fatal error not detected Jun 27, 2024
@dkarlovi dkarlovi changed the title Readonly class not marked as immutable by default, fatal error not detected Readonly class not marking props readonly, fatal error not detected Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant