Skip to content

analyzer: mago does not infer parameter types of closure arguments #281

@bendavies

Description

@bendavies

🐞 Describe the Bug

i think the following code procudes a false positive.
mago 1.0.0-alpha.7

🔄 Steps to Reproduce

mago analyse

⚙️ Configuration (mago.toml)

# Mago configuration file
# For more information, see https://mago.carthage.software/#/getting-started/configuration
php_version = "8.3.0"

[source]
paths = ["bin/", "src/", "test/"]
includes = ["vendor"]

[format]
print_width = 180
tab_width = 4
use_tabs = false
null_type_hint = "question"
always_break_named_arguments_list = false

📜 Command Output

 ./mago --version
mago 1.0.0-alpha.7

error[mixed-argument]: Invalid argument type for argument #1 of `Owsy\ReleaseTool\Github\Value\Repository::fromFullName`: expected `string`, but found `mixed`.
   ┌─ src/Github/Value/Repositories.php:22:13
   │
21 │           $instance->repositories = Vec\values(Vec\map($payload, static fn(array $payload): Repository => Repository::fromFullName(
   │ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────'
22 │ │             $payload['name'],
   │ │             ^^^^^^^^^^^^^^^^ Argument has type `mixed`
23 │ │             \array_key_exists('alias', $payload) ? $payload['alias'] : null,
24 │ │         )));
   │ ╰─────────' Arguments to this method are incorrect
   │
   = The type `mixed` is too general and does not match the expected type `string`.
   = Help: Add specific type hints or assertions to the argument value.

error[mixed-argument]: Invalid argument type for argument #2 of `Owsy\ReleaseTool\Github\Value\Repository::fromFullName`: expected `null|string`, but found `mixed`.
   ┌─ src/Github/Value/Repositories.php:23:13
   │
21 │           $instance->repositories = Vec\values(Vec\map($payload, static fn(array $payload): Repository => Repository::fromFullName(
   │ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────'
22 │ │             $payload['name'],
23 │ │             \array_key_exists('alias', $payload) ? $payload['alias'] : null,
   │ │             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Argument has type `mixed`
24 │ │         )));
   │ ╰─────────' Arguments to this method are incorrect
   │

📂 PHP Code Sample (If Applicable)

<?php

    /** @param array<int, array{name: string, alias?: ?string}> $payload */
    public static function fromPayload(array $payload): self
    {
        $instance = new self();

        $instance->repositories = Vec\values(Vec\map($payload, static fn(array $payload): Repository => Repository::fromFullName(
            $payload['name'],
            \array_key_exists('alias', $payload) ? $payload['alias'] : null,
        )));

        return $instance;
    }

🖥️ Operating System

macOS

📦 How did you install Mago?

Composer (composer require carthage-software/mago)

📝 Additional Context

No response

Metadata

Metadata

Assignees

Labels

Priority: HighAfter critical issues are fixed, handle these before any further issues.Status: AcceptedThe issue’s subject and resolution approach is confirmed.Subject: AnalyzerAn issue or PR related to the static analyzer/type checker.Type: EnhancementRequest for additions or changes that improve existing functionality.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions