Skip to content

[TypeInfo] Fails to parse types defined in class #60657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
aleho opened this issue Jun 3, 2025 · 3 comments
Closed

[TypeInfo] Fails to parse types defined in class #60657

aleho opened this issue Jun 3, 2025 · 3 comments

Comments

@aleho
Copy link
Contributor

aleho commented Jun 3, 2025

Symfony version(s) affected

7.3.0

Description

In 7.3 type info crashes when it encounters a doc block referencing other types.

The types are only for PHPStan or IDE auto completion and shouldn't have any significance to Symfony. The error occurs in a live component that has a service injected with such annotations.

Symfony\Component\TypeInfo\Exception\UnsupportedException
Cannot resolve "list<MyType>".

DomainException
Unhandled "MyType" identifier.

How to reproduce

Have type info parse the doc block of this class:

<?php

/**
 * @phpstan-type MyType array{
 *     key1: string,
 *     key2?: bool,
 * }
 * 
 * @phpstan-type TypesList list<MyType>
 */
readonly class Example
{
}

Possible Solution

No response

Additional Context

No response

@stof
Copy link
Member

stof commented Jun 3, 2025

Can you provide the stack trace of the exceptions ?

@mtarld
Copy link
Contributor

mtarld commented Jun 3, 2025

This might be resolved thanks to #60641

@aleho
Copy link
Contributor Author

aleho commented Jun 3, 2025

This might be resolved thanks to #60641

Cool, it actually is! (I saw that issue but read the report only and didn't think my problem was related to Doctrine collections.)

nicolas-grekas added a commit that referenced this issue Jun 4, 2025
This PR was merged into the 7.3 branch.

Discussion
----------

[TypeInfo] Fix type alias resolving

| Q             | A
| ------------- | ---
| Branch?       | 7.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fixes #60598, fixes #60657
| License       | MIT

Take other type aliases into account when resolving type aliases, no matter the order they're defined.

Commits
-------

b778a80 [TypeInfo] Fix type alias resolving
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants