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

23 hours ago

Mago 1.0.0-beta.12

This release is packed with major improvements to the static analyzer, focusing on enhanced type inference for
arrays, closures, and ArrayAccess objects. We've also added support for recursive closures and array
unpacking on all iterables.

🚀 Features

  • Array Unpacking on Iterables: The array spread operator (...) now works on all iterable types, not just arrays. You can now unpack any object that implements Traversable, and Mago will correctly infer the key and value types. (#361)
  • Smarter Psl\Regex Analysis: A special type provider has been added for Psl\Regex\capture_groups. Mago can now infer a precise shape for the returned type based on the capture group names you provide, giving you much better type safety when working with regular expressions. (#364)

🐛 Bug Fixes

  • Recursive Closures: You can now write recursive closures without getting an undefined-variable error. The analyzer now correctly handles the pattern where a closure takes a reference to itself (e.g., $fn = function () use (&$fn) { ... };). (#368)
  • Closure Call Return Types: Invoking a closure assigned to a variable (e.g., $a = fn() => 'foo'; $b = $a();) now correctly uses the specific inferred return type ('foo') instead of falling back to a generic mixed. (#355)
  • Array Assignment on null: Assigning to an index on a null or non-existent variable (e.g., $a = null; $a[] = 1;) now correctly promotes the variable to an array type, matching PHP's runtime behavior. (#360)
  • Shaped Array Inference: Fixed a critical bug where the analyzer would "forget" the shape of an array being built inside a loop, leading to false-positive errors. Type information is now correctly preserved. (#366)
  • ArrayAccess Append: Appending to an ArrayAccess object with a non-negative-int key type now correctly infers the new key as non-negative-int instead of a general int. (#362)
  • Enums with self & static: Corrected an issue where self and static were not being properly resolved to the enum's type within its own methods, eliminating false-positive errors. (#357)
  • array_search Stub: The built-in stub for array_search has been corrected to reflect that the $needle is a value from the array, not a key. (#358)

🔧 Internal Changes

  • Ecosystem CI Check: A new CI workflow has been added to automatically run Mago against popular downstream projects. This helps us catch potential backward-compatibility breaks before they are released.

Full Changelog: 1.0.0-beta.11...1.0.0-beta.12

Don't miss a new mago release

NewReleases is sending notifications on new releases.