Skip to content

Recursive array type not validated #1892

@bdsl

Description

@bdsl

Code:

<?php

/**
* @psalm-type recursiveData array<string, string|recursiveData> 
*
* @return recursiveData
*/
function foo(): array {
    return ['id' => 'bar', 'key' => ['baz' => 'fred']];
}

Actual output at https://psalm.dev/r/d19ae42a39

Psalm output (using commit 5c76b3c):

ERROR: InvalidReturnStatement - 8:12 - The type 'array{id: string(bar), key: array{baz: string(fred)}}' does not match the declared return type 'array<string, string|recursiveData>' for foo

ERROR: InvalidReturnType - 5:13 - The declared return type 'array<string, string|recursiveData>' for foo is incorrect, got 'array{id: string, key: array{baz: string}}'

Expected output:

No issues!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions