Skip to content

Fix: expand imported type aliases in provider checks - #266

Merged
alies-dev merged 60 commits into
psalm:masterfrom
alies-dev:fix/249-type-alias-params
Nov 10, 2026
Merged

alies-dev merged 60 commits into
psalm:masterfrom
alies-dev:fix/249-type-alias-params

Conversation

@alies-dev

@alies-dev alies-dev commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

A test parameter typed with an imported type alias is compared with the provider's datasets without expanding the alias, so the message names type-alias(...) and differs from the same parameter typed with the shape.

Before

/** @psalm-type Options = array{host: string} */
final class Connection {}

/** @psalm-import-type Options from Connection */
final class MyTestCase extends TestCase {
    /**
     * @return list<array{array<string, string>}>
     * @psalm-pure
     */
    public static function provide(): array {
        return [[['host' => 'x']]];
    }

    /**
     * @param Options $options
     */
    #[DataProvider('provide')]
    public function testAlias(array $options): void { // InvalidArgument: Argument 1 of NS\MyTestCase::testAlias expects type-alias(NS\Connection::Options), array<string, string> provided by NS\MyTestCase::provide():(list<list{array<string, string>}>)
        $this->assertSame('x', $options['host']);
    }
}

After

    public function testAlias(array $options): void { // ArgumentTypeCoercion: Argument 1 of NS\MyTestCase::testAlias expects array{host: string}, but parent type array<string, string> provided by NS\MyTestCase::provide():(list<list{array<string, string>}>)

self in a trait's provider and test types is resolved to the class using the trait.

Fixes #249

# Conflicts:
#	tests/acceptance/TestCase.feature
…ercion

# Conflicts:
#	tests/acceptance/TestCase.feature
…params

# Conflicts:
#	tests/acceptance/TestCase.feature
# Conflicts:
#	tests/acceptance/TestCase.feature
…alizers

# Conflicts:
#	tests/acceptance/TestCase.feature
…tests

# Conflicts:
#	tests/acceptance/TestCase.feature
# Conflicts:
#	tests/acceptance/TestCase.feature
# Conflicts:
#	tests/acceptance/Datasets.feature
# Conflicts:
#	src/Hooks/TestCaseHandler.php
#	tests/acceptance/Datasets.feature
# Conflicts:
#	src/Hooks/TestCaseHandler.php
#	tests/acceptance/DataProviders.feature
# Conflicts:
#	tests/acceptance/ProviderReturnTypes.feature
# Conflicts:
#	tests/acceptance/Datasets.feature
# Conflicts:
#	tests/acceptance/Datasets.feature
# Conflicts:
#	tests/acceptance/Datasets.feature
Psalm has resolved parents, traits, aliases and insteadof into declaring_method_ids by AfterCodebasePopulated, so a setUp() not declared by TestCase or a #[Before] method of any declaring class is an initializer. This replaces the manual trait walk, the setUp alias special case and the descendant loop.
# Conflicts:
#	tests/acceptance/DeadCode.feature
# Conflicts:
#	tests/acceptance/Initializers.feature
Check the test name before the method visibility.
…params

# Conflicts:
#	src/Hooks/TestCaseHandler.php
#	tests/acceptance/Datasets.feature
@alies-dev
alies-dev merged commit 7258e8a into psalm:master Nov 10, 2026
8 checks passed
@alies-dev
alies-dev deleted the fix/249-type-alias-params branch November 10, 2026 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Imported type aliases in test parameters are not expanded in provider checks

1 participant