mago icon indicating copy to clipboard operation
mago copied to clipboard

Invalid errors

Open ADmad opened this issue 5 months ago • 2 comments

🐞 Describe the Bug

Invalid errors

🔄 Steps to Reproduce

Run mago analyze for the code given below

⚙️ Configuration (mago.toml)

.

📜 Command Output

error[invalid-argument]: Invalid argument type for argument #2 of `array_reduce`: expected `(callable('I.array_reduce() extends mixed|null, list{int(1)|int(2)}): 'I.array_reduce() extends mixed)`, but found `string('array_merge')`.
  ┌─ src/mago_test.php:4:5
  │
2 │ var_dump(array_reduce(
  │          ------------ Arguments to this function are incorrect
3 │     ['a' => [1], 'b' => [2]],
4 │     'array_merge',
  │     ^^^^^^^^^^^^^ This has type `string('array_merge')`
  │
  = The provided type `string('array_merge')` is not compatible with the expected type `(callable('I.array_reduce() extends mixed|null, list{int(1)|int(2)}): 'I.array_reduce() extends mixed)`.
  = Help: Change the argument value to match `(callable('I.array_reduce() extends mixed|null, list{int(1)|int(2)}): 'I.array_reduce() extends mixed)`, or update the parameter's type declaration.

error[no-value]: Argument #1 passed to function `var_dump` has type `never`, meaning it cannot produce a value.
  ┌─ src/mago_test.php:2:10
  │
2 │   var_dump(array_reduce(
  │ ╭──────────^
3 │ │     ['a' => [1], 'b' => [2]],
4 │ │     'array_merge',
5 │ │     []
6 │ │ ));
  │ ╰─^ This argument expression results in type `never`
  │
  = The `never` type indicates this expression will not complete to produce a value.
  = This often occurs in unreachable code, due to impossible conditional logic, or if an expression always exits (e.g., `throw`, `exit()`).
  = Help: Review preceding logic to ensure this argument can receive a value, or remove if unreachable.

📂 PHP Code Sample (If Applicable)

<?php
var_dump(array_reduce(
    ['a' => [1], 'b' => [2]],
    'array_merge',
    []
));

🖥️ Operating System

Linux

📦 How did you install Mago?

Installation Script (curl | bash)

📝 Additional Context

No response

ADmad avatar Sep 11 '25 18:09 ADmad

note that this gives issues even when changing 'array_merge' to array_merge(...)

Bleksak avatar Sep 12 '25 18:09 Bleksak

This is a feature we lack support for. we need to update our type comparator to allow strings that refer to functions when comparing with callable. we currently only allow closures and other other callables.

azjezz avatar Sep 12 '25 19:09 azjezz

fixed. sorry that it took a while :)

https://mago.carthage.software/playground#019b094f-464a-3d33-9663-7251956af0cd

azjezz avatar Dec 10 '25 17:12 azjezz