Repository navigation
Conversation
…y, or the reverse, and one without a native type vimeo#7767 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Behaviour change
|
|
I found these snippets: https://psalm.dev/r/935f8cf961<?php
/** @psalm-suppress MissingConstructor */
class A {
public int $prop;
}
/** @psalm-suppress MissingConstructor */
class B extends A {
// Illegal: readwrite -> readonly
public readonly int $prop;
}https://psalm.dev/r/11c464ac18<?php
/** @psalm-suppress MissingConstructor */
class A {
public readonly int $prop;
}
/** @psalm-suppress MissingConstructor */
class B extends A {
// Illegal: readonly -> readwrite
public int $prop;
}https://psalm.dev/r/d41b8e5778<?php
class Foobar
{
/** @var string */
public readonly $foo;
public function __construct()
{
$this->foo = "";
}
} |
✅ Performance: unchanged · Types: unchanged
How to read this table
head ed33de6 · base b4f6909 (merge-base) · workflow run |
…ck type The redeclaration itself is now reported as OverriddenPropertyAccess first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ve type once vimeo#7767 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…psalm into fix/7767-readonly-redeclaration
|
Follow-up (8501df9), after the Bugbot finding "Duplicate missing type readonly class": confirmed. In a Edited existing test (b90b057): |
|
bugbot review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 2b78ea0. Configure here.
orklah
left a comment
There was a problem hiding this comment.
Thanks for this, both checks match real PHP fatal errors and the tests reproduce cleanly. One false positive though: PHP only rejects a readonly/non-readonly redeclaration when the parent property is not abstract, and since PHP 8.4 a readonly property may implement an abstract get-only hooked property. This now reports an OverriddenPropertyAccess on valid code:
<?php
abstract class AbstractHooked {
abstract public int $x { get; }
}
final class ReadonlyImpl extends AbstractHooked {
public function __construct(public readonly int $x) {}
}
// OverriddenPropertyAccess: Property ReadonlyImpl::$x cannot redeclare the non-readonly property AbstractHooked::$x as readonlyCould you skip the comparison when the parent property is abstract (Psalm doesn't record that yet, $stmt->isAbstract() in the scanner would do), and add this case to readonlyPropertyRedeclaredWhereItIsAllowed with php_version 8.4?
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A property redeclared with or without
readonlyPsalm misses the PHP fatal error of a child class that redeclares a parent's property as
readonly, or areadonlyone as non-readonly.Before
After
A
readonlyproperty with only a docblock typePsalm misses the PHP fatal error of a
readonlyproperty that has no native type.Before
After
Refs #7767