Repository navigation
fix(enum): report a circular reference of an enum case value instead of crashing - #14350
Conversation
…of crashing vimeo#14299 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
✅ Performance: unchanged · Types: unchanged
How to read this table
head d8306ff · base 3a3fdf6 (merge-base) · workflow run |
|
Behaviour change
|
orklah
left a comment
There was a problem hiding this comment.
Thanks! The CircularReference report works for the case itself, the class-constant side, a self-cycle
between two cases, and readers such as match, tryFrom(), from() and ->value.
But getValue() now returns null for a circular case, and two of its callers assert that a backed case
always has a value, so this still crashes:
enum Level: int {
case Low = Limits::MIN + 1;
}
final class Limits {
public const MIN = Level::Low->value;
}
/** @param value-of<Level> $v */
function takesValue(int $v): void {}
// Uncaught AssertionError: assert($case_value !== null) in src/Psalm/Type/Atomic/TValueOf.php:52The same asserts are in TValueOf::getValueTypeForNamedObject() (both branches) and in
SimpleAssertionReconciler (around lines 3104 and 3120). They already crash on master when a case value is an
undefined constant (case A = NOPE + 1; with value-of<E>), so handling null there (falling back to
mixed, as AtomicPropertyFetchAnalyzer::handleEnumValue() does) fixes both. Could you do that and add a
test case with value-of<Level>?
…ed for that case getValue() is null for a case in a circular reference or of an undefined constant: TValueOf and the value-of reconciliation take mixed for it instead of asserting a value, which crashed. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Pushed d8306ff (master merged in). |
Psalm crashes with an uncaught
CircularReferenceExceptionwhen an enum case value and a class constant refer to each other and the case value is read.Before
After
Fixes #14299