vimeo / psalm

A static analysis tool for finding errors in PHP applications
https://psalm.dev
MIT License
5.55k stars 660 forks source link

Upcast allows to modify immutable objects #6896

Open weirdan opened 2 years ago

weirdan commented 2 years ago

https://psalm.dev/r/a3c5fd12fd?php=8.1 https://3v4l.org/AVKtm

PHPStan requires additional check to make sure property exists but otherwise behaves the same: https://phpstan.org/r/31d907e0-9e34-40c2-b0a3-76d4588eab65

Hack doesn't seem to have a functioning readonly implementation.

TypeScript requires jumping through some hoops, but ultimately allows the same: https://www.typescriptlang.org/play?#code/MYGwhgzhAEDC0G8BQ1XQE4FMwBMD2AdiAJ7QCWAXNAQK4C2ARputALzQCMA3EgL5JIAZjQLAALmULQ6NMWDF50ACjxU8DAFaZxASioA3PGRyIUaMoOhLMADzIQxEFQBpoAcjJudO02j-Q8ADoyNmgAFgAmHj9+fiERcUkCaFt7RwAeABVXAGkUmzFMAhwYAAV0PAAHZjFiHMxiAD4lM1R1DSps1uhKisqqHKQ9AM1yGEzoADJoACVtRRx0nNcRAGsCPAB3AkbfNCwxGnRkgHlNbTFA3rwFWurAgAtIE+3yqpriQOAwEBAVTVc10qOh4cWAhAc0GAoQImE2cB4MjkCmUwBBSHBBAgeBAmECIDwAHMlGiuEA

psalm-github-bot[bot] commented 2 years ago

I found these snippets:

https://psalm.dev/r/a3c5fd12fd ```php i = 42; } $c = new C; mutator($c); ``` ``` Psalm output (using commit e07e359): No issues! ```