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
Psalm v5: __toString
of some types does not return exact
return type anymore
#7985
Comments
Hey @boesing, can you reproduce the issue on https://psalm.dev ? |
This would probably be an effect of #7409 But I don't get how it happens. Calling |
I at least have failing codeception tests regarding this. Will see if I can debug the reason. |
It seems that in case of a psalm/src/Psalm/Type/Union.php Line 371 in 894e4e4
psalm/src/Psalm/Type/Union.php Line 381 in f960d71
|
Oh I see, it was in a union. Could you try pushing a PR to change that to true? I think this will have other unwanted effects but I can't remember which. CI should tell us that |
I probably just gonna switch to I guess you knew what you did there and thus I better not question that 😂 |
Honestly, the whole thing was a mess before :( __toString was generally used to return a less detailed version of a type but it was not consistent, some function were calling other and then were overriden to call something else entirely. And nothing was documented. We have a few BC break for Psalm 5 linked to this PR
To give you a slight idea, here's what happened in 4.x: Calling __toString on TString returns Calling getKey on TString returns Calling getId on TString returns So I had to make choices and break things in some places. I kept the original idea that __toString should be the one used for debug and that can be less detailed while getId should always be the more detailed but this could break things in some places when relying on the output of __toString Disclaimer: I'm aware this is still a mess. For example, Union::__toString use less detailed types but Atomic::__toString use more detailed types. (IIRC, it's because one is used by Psalm for tests so I can't change that), but at least, it reduces the complexity of the system. It could probably still be improved and I'd be surprised if we don't refactor that once again in Psalm 6 ! |
Yah, for my use-case, Thanks for explanation! |
In psalm v4, using
(string) $type
on an instance ofTNumericString
returnednumeric-string
.As of psalm v5, this now returns
string
.Is this an expected behavior?
The text was updated successfully, but these errors were encountered: