You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Treat Expr\UnaryMinus with scalar operand as scalar literal in isExprSafeToProjectThroughVariable and comparison type specifying
- In PHP Parser v5, negative literals like `-1` are represented as
`Expr\UnaryMinus(Scalar\Int_(1))`, not `Scalar\Int_(-1)`. The
`isExprSafeToProjectThroughVariable` filter in AssignHandler only
checked for `instanceof Node\Scalar`, missing the `UnaryMinus` wrapper.
This allowed a sure type with expression string `"-1"` (a numeric
string) to enter the conditional expressions array. PHP's array key
autocasting then turned it into an integer key, causing a TypeError
when passed to `addConditionalExpressions(string $exprString, ...)`.
- Added `Expr\UnaryMinus && $expr->expr instanceof Node\Scalar` to the
filter in `isExprSafeToProjectThroughVariable`, matching what
`MutatingScope::filterBySpecifiedTypes` already does.
- Added the same `UnaryMinus(Scalar)` check to TypeSpecifier's
`Smaller`/`SmallerOrEqual` handling, which skips creating sure types
for scalar literals but was missing the negated-scalar case.
- Added defensive `(string)` casts in three locations in AssignHandler
where expression string keys from `getSureTypes()`/`getSureNotTypes()`
are consumed, matching the pattern already used in
`MutatingScope::filterBySpecifiedTypes`.
0 commit comments