Mago 1.9.1
Patch release with several analyzer and formatter bug fixes, plus support for @psalm-mutation-free annotations.
✨ Features
Codex (Type System)
@psalm-mutation-freeand@psalm-external-mutation-freeannotations: The codex scanner now recognizes these Psalm annotations and maps them to Mago's internal mutation-free flags, improving interoperability with Psalm-annotated codebases (#1157)
🐛 Bug Fixes
Analyzer
- Property narrowings preserved across pure and mutation-free function calls: Previously, all property type narrowings were cleared after any function call that received an object argument. The analyzer now preserves property narrowings when the called function is marked as
@pure,@mutation-free, or@external-mutation-free, since these functions are guaranteed not to mutate the object's state (#1157) - Generic type parameters preserved during
instanceofnarrowing on sealed class hierarchies: When narrowing a generic type (e.g.,Result<T>) withinstanceofagainst a sealed inheritor (e.g.,Success<T>), the type parameters from the parent type are now correctly carried over to the narrowed type, preventing unexpectednevertype results (#1156) - Non-existent classes detected in
@varannotations andinstanceofRHS: The analyzer now reportsnon-existent-class-likeerrors for undefined types used in@vardocblock annotations and on the right-hand side ofinstanceofexpressions, matching the existing behavior for parameter types, return types, and property types (#1007) - Possibly undefined keys in unions of sealed/unsealed arrays: Fixed incorrect
undefined-string-array-indexerrors when accessing keys on union types containing both sealed and unsealed array variants (e.g.,array{foo: int, ...}|array{foo: int}). The unsealed variant's generic parameters are now properly considered when determining whether a key might exist (#1154) - Deduplicated undefined key errors across union variants: When accessing a non-existent key on a union of multiple keyed arrays, the
undefined-string-array-indexerror is now reported only once instead of once per union variant
Formatter
- Trailing comments preserved on opening parenthesis line in multiline parameter lists: Fixed a bug where end-of-line inline comments (e.g.,
// @phpstan-ignore method.unused) on method signatures with multiline parameter lists were incorrectly moved to the next line (#1153)
Prelude (Type Stubs)
DateTimeImmutableandDateTimeZonemethods annotated as mutation-free: Methods onDateTimeImmutableandDateTimeZonethat do not modify state are now annotated with@mutation-free, preventing false positive property narrowing invalidations when calling these methods (#1157)ReflectionClass::getReflectionConstants()return type: Added missing return type information (#1152)
Documentation
- Removed undocumented
space_after_colon_in_enum_backing_typesetting: Removed a reference to a non-existent formatter setting from the configuration reference documentation (#1151)
🙏 Thank You
Contributors
A huge thank you to everyone who contributed code to this release:
Issue Reporters
Thank you to everyone who reported issues that shaped this release:
Full Changelog: 1.9.0...1.9.1