github carthage-software/mago 1.0.0-beta.9
Mago 1.0.0-beta.9

latest release: 1.0.0-beta.10
one day ago

Mago 1.0.0-beta.9

This release focuses on deep type inference for ::class comparisons. It also includes a new linter rule to help modernize your code, along with several important bug fixes and community contributions.


✨ Features

🧠 Smarter ::class Analysis

The analyzer is now significantly smarter about the ::class magic constant, enabling more powerful and precise type narrowing.

  • ::class as instanceof: A condition like if ($var::class === A::class) is now treated as an instanceof check, correctly narrowing the type of $var to A within the block. This works across all control structures, including if, switch, and match, and correctly handles final vs. non-final classes. (Closes #367)
  • Improved class-string Logic: This is powered by a completely overhauled understanding of class-string types. The analyzer can now reconcile literal class strings from unions and resolves $foo::class on final objects to a precise literal type.
  • Clearer Type Display: To make this distinction obvious, literal class strings are now displayed as class-string('Foo'), while generic class strings remain class-string<Foo>, making error messages much easier to understand.

🕵️ New Linter Rule: prefer-arrow-function

A new linter rule, prefer-arrow-function, has been added to the Best Practices category. It identifies traditional closures that can be simplified to the more concise arrow function syntax and provides a potentially unsafe autofix.


🐛 Bug Fixes

  • Analyzer: Fixed incorrect type inference for iterators, especially when only a value type is provided (e.g., Iterator<Value>). A new, more precise return type handler for the SPL function iterator_to_array has also been added. (Closes #359)
  • Analyzer: Fixed an issue where the type of a class constant that references another constant (e.g., const A = B::C) was not being fully resolved, leading to more accurate type inference. (Closes #363)
  • Analyzer: Corrected a bug where variables in a foreach by-reference loop (... as &$var) were sometimes reported as undefined. A new warning (reference-reused-from-confusing-scope) has also been added to detect a common source of bugs with lingering references after a loop. (Closes #369)
  • Docblock Parser: The parsing of @param tags is now more robust, correctly normalizing the variable name and handling trailing punctuation, by-reference (&), and variadic (...) syntax. Thanks to @z4nder! (Closes #376)

📝 Documentation & Community

  • The documentation for Helix users has been updated to use the project's mago.toml by default. Thanks to @Bleksak! (Closes #349)
  • For contributors, a Nix flake has been added to provide a reproducible development environment. Thanks to @z4nder! (Closes #372)
  • A sitemap has been generated for the documentation website to improve discoverability.

🤝 New Contributors


Full Changelog: 1.0.0-beta.8...1.0.0-beta.9

Don't miss a new mago release

NewReleases is sending notifications on new releases.