Skip to content

spurious error in specific combination of namespace blocks and function declaration with phpdoc type annotation #13831

@claudepache

Description

@claudepache

Bug report

I encountered a strange spurious PHPStan error in the following setting:

// Any non-global namespace block ...
namespace foo {
	// ...
}

// ... followed by a global namespace block ...
namespace {

   // ... and a function declaration here with completed type information in phpdoc
    // will trigger the spurious error:

    /** @return list<string> */
    function qux(): array {   // <-- ??? `missingType.iterableValue` error
        return [ random_bytes(16) ];
    }
	
    \PHPStan\dumpType(qux()); // ok: list<string>
}

(If you are curious: I encountered this issue in my stub file, and I’ve worked around it by reordering the namespace blocks.)

Code snippet that reproduces the problem

https://phpstan.org/r/c714d401-a96b-4e88-b0c8-8ad956180e61

Expected output

No error on line 15.

Did PHPStan help you today? Did it make you happy in any way?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions