Skip to content

[TypeInfo] Fix handling ConstFetchNode #60820

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

Merged
merged 1 commit into from
Jun 27, 2025

Conversation

norkunas
Copy link
Contributor

@norkunas norkunas commented Jun 18, 2025

Q A
Branch? 7.2
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #...
License MIT

I cannot upgrade to 7.3 because I get:

  In StringTypeResolver.php line 88:
!!                                                                                 
!!    Cannot resolve "array{requirement: ProductLicense::SYSTEM_REQUIREMENT_*, va  
!!    lue: non-empty-string}".                                                     
!!                                                                                 
!!  
!!  In StringTypeResolver.php line 142:
!!                                                                                 
!!    Unhandled "PHPStan\PhpDocParser\Ast\ConstExpr\ConstFetchNode" constant expr  
!!    ession.                                                                      
!!                                                                                 

@carsonbot

This comment was marked as outdated.

@carsonbot carsonbot added this to the 7.4 milestone Jun 18, 2025
@norkunas norkunas changed the base branch from 7.4 to 7.2 June 18, 2025 11:22
@norkunas
Copy link
Contributor Author

Hmm, this is not the right fix :(

@norkunas norkunas force-pushed the typeinfo-const-fetch-node branch from 38d6ac6 to 526b002 Compare June 18, 2025 11:26
@norkunas norkunas requested a review from dunglas as a code owner June 18, 2025 11:26
@norkunas norkunas force-pushed the typeinfo-const-fetch-node branch from 526b002 to 6e237a9 Compare June 18, 2025 11:42
@norkunas
Copy link
Contributor Author

Changed implementation from returning Type::string() to any union-scalar

@stof
Copy link
Member

stof commented Jun 18, 2025

Constants are not even restricted to scalars in recent PHP versions.

The right fix would involve looking at the fetched constants.

@OskarStark OskarStark changed the title [TypeInfo] Fix handling ConstFetchNode [TypeInfo] Fix handling ConstFetchNode Jun 18, 2025
@OskarStark OskarStark modified the milestones: 7.4, 7.2 Jun 18, 2025
@norkunas norkunas force-pushed the typeinfo-const-fetch-node branch from 6e237a9 to 48f648b Compare June 19, 2025 09:55
@norkunas
Copy link
Contributor Author

I've updated implementation

@norkunas norkunas force-pushed the typeinfo-const-fetch-node branch 3 times, most recently from 4173b66 to 606a4ab Compare June 19, 2025 10:23
@norkunas
Copy link
Contributor Author

I'm not sure how to fix the failing serializer test. For me it looks like that it's an invalid test, because it defines self::* on an anonymous class but does not define any constant. Then later of course it fails because it's an union type, but for now when no matched constants were found it returns Type::null and as property defines also null, it tries to pass Type::null to Type::union twice.

@norkunas
Copy link
Contributor Author

@stof @mtarld so I just fixed the wrong test from Serializer, please review when you can :)

@norkunas
Copy link
Contributor Author

I'm not sure how to fix property info though, as test passes for me locally

Copy link
Contributor

@mtarld mtarld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failures are because symfony/property-info requires either:

  • symfony/type-info:^7.1 (low-deps)
  • symfony/type-info:7.4-dev (high-deps)

Both of these are not including your change (7.4-dev will once this PR will be merged I guess).

But for the low-deps, Maybe you can add a condition? Something like:

if (class_exists(NullableType::class)) { // <- this class was introduced in 7.2
    yield ['f', Type::union(Type::string(), Type::null())];
} else {
    yield ['f', null];
}

@mtarld
Copy link
Contributor

mtarld commented Jun 27, 2025

But I don't know if we need to consider this as a BC break (as it was not a valid type anyway) 🤔

@norkunas norkunas force-pushed the typeinfo-const-fetch-node branch 2 times, most recently from d520350 to ec86f71 Compare June 27, 2025 11:05
@norkunas
Copy link
Contributor Author

Thanks, updated

@norkunas norkunas force-pushed the typeinfo-const-fetch-node branch from ec86f71 to 6f49fc6 Compare June 27, 2025 11:24
@stof
Copy link
Member

stof commented Jun 27, 2025

For the lowest-deps job, I suggest instead bumping the min version of type-info in property-info to use ^7.2.8 (i.e. the next 7.2 release that will contain the fix). It makes maintenance easier than having conditional test assertions depending on the version, while type-into 7.1 is EOL anyway.

@mtarld
Copy link
Contributor

mtarld commented Jun 27, 2025

Agreed, this will make things much more easier.

@norkunas norkunas force-pushed the typeinfo-const-fetch-node branch from 6f49fc6 to 78c60fe Compare June 27, 2025 12:07
@norkunas
Copy link
Contributor Author

Thank you, both

@norkunas norkunas force-pushed the typeinfo-const-fetch-node branch 2 times, most recently from 7729498 to 6440799 Compare June 27, 2025 12:28
@nicolas-grekas nicolas-grekas force-pushed the typeinfo-const-fetch-node branch from d0fdf06 to 03cc607 Compare June 27, 2025 15:23
@nicolas-grekas
Copy link
Member

Thank you @norkunas.

@nicolas-grekas nicolas-grekas merged commit 4e3a96f into symfony:7.2 Jun 27, 2025
7 of 11 checks passed
@norkunas norkunas deleted the typeinfo-const-fetch-node branch June 27, 2025 15:24
This was referenced Jun 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy