Try to provide literal int types when possible (fixes #6966)#7071
Try to provide literal int types when possible (fixes #6966)#7071orklah merged 11 commits intovimeo:masterfrom ricardoboss:issue-6966-argumenttypecoercion_for_typecasted_vars
Conversation
|
Thanks! You have to enable the return type provider in FunctionReturnTypeProvider first |
|
I made an error in my explanation. round only returns floats: That shouldn't be an issue however, what you have to do to fix #6966 is check if you have a TLiteralInt or a TLiteralFloat in the num_arg. If it is, you should return a TLiteralFloat with the rounded value of what was in num_arg. |
|
I need to implement the CastAnalyzer too. So this is should really be a draft PR. |
|
I'm struggling to get the actual values with which the |
|
try a |
|
E.g. |
|
@ricardoboss is this ready for review? |
|
Yes! Sorry I didn't notify you... |
|
No worries, we'll check that :) |
|
@orklah can you take a look again? |
orklah
left a comment
There was a problem hiding this comment.
See comment above. Can you add some tests too?
|
@ricardoboss do you need some help to design the tests? Could you also rebase to solve the conflicts? |
|
Will do a rebase! I haven't had time to write tests yet. Haven't forgot it either. |
|
Sorry for not coming back to this earlier, I don't get notifications for commits so I didn't see this change. I'll take a look. Don't hesitate to ping me or leave a comment when you change things |
|
Seems fine. Can you rebase and fix the Code Style error please? |
|
Can you write a test for this? I would like to see how you test this behavior. I will do a rebase when I get time to do so |
|
For the cast one, you can add a test in ValueTest.php in providerValidCodeParse with the code: For the round one, you can add a test in FunctionCallTest.php in providerValidCodeParse with the code |
|
Thanks! |
|
The missing cast analyzer things are added in this PR now #8366 and this PR is cherry-picked to 4.x |
…meo#6966) (vimeo#7071) * Fixed vimeo#6966 * Only accept >= 0 values for mode argument in round() * Made round() only return float or literal float values and remove unneeded test * Registered RoundReturnTypeProvider * Updated cast analyzer to handle single string literal int values as literal ints * Fixed psalm errors * Fix invalid property accesses * Addressed comments * Added Tests * Marked RoundReturnTypeProvider as internal * Fixed CS
…meo#6966) (vimeo#7071) * Fixed vimeo#6966 * Only accept >= 0 values for mode argument in round() * Made round() only return float or literal float values and remove unneeded test * Registered RoundReturnTypeProvider * Updated cast analyzer to handle single string literal int values as literal ints * Fixed psalm errors * Fix invalid property accesses * Addressed comments * Added Tests * Marked RoundReturnTypeProvider as internal * Fixed CS
…meo#6966) (vimeo#7071) * Fixed vimeo#6966 * Only accept >= 0 values for mode argument in round() * Made round() only return float or literal float values and remove unneeded test * Registered RoundReturnTypeProvider * Updated cast analyzer to handle single string literal int values as literal ints * Fixed psalm errors * Fix invalid property accesses * Addressed comments * Added Tests * Marked RoundReturnTypeProvider as internal * Fixed CS
…meo#6966) (vimeo#7071) * Fixed vimeo#6966 * Only accept >= 0 values for mode argument in round() * Made round() only return float or literal float values and remove unneeded test * Registered RoundReturnTypeProvider * Updated cast analyzer to handle single string literal int values as literal ints * Fixed psalm errors * Fix invalid property accesses * Addressed comments * Added Tests * Marked RoundReturnTypeProvider as internal * Fixed CS
…meo#6966) (vimeo#7071) * Fixed vimeo#6966 * Only accept >= 0 values for mode argument in round() * Made round() only return float or literal float values and remove unneeded test * Registered RoundReturnTypeProvider * Updated cast analyzer to handle single string literal int values as literal ints * Fixed psalm errors * Fix invalid property accesses * Addressed comments * Added Tests * Marked RoundReturnTypeProvider as internal * Fixed CS
…meo#6966) (vimeo#7071) * Fixed vimeo#6966 * Only accept >= 0 values for mode argument in round() * Made round() only return float or literal float values and remove unneeded test * Registered RoundReturnTypeProvider * Updated cast analyzer to handle single string literal int values as literal ints * Fixed psalm errors * Fix invalid property accesses * Addressed comments * Added Tests * Marked RoundReturnTypeProvider as internal * Fixed CS
…meo#6966) (vimeo#7071) * Fixed vimeo#6966 * Only accept >= 0 values for mode argument in round() * Made round() only return float or literal float values and remove unneeded test * Registered RoundReturnTypeProvider * Updated cast analyzer to handle single string literal int values as literal ints * Fixed psalm errors * Fix invalid property accesses * Addressed comments * Added Tests * Marked RoundReturnTypeProvider as internal * Fixed CS
…meo#6966) (vimeo#7071) * Fixed vimeo#6966 * Only accept >= 0 values for mode argument in round() * Made round() only return float or literal float values and remove unneeded test * Registered RoundReturnTypeProvider * Updated cast analyzer to handle single string literal int values as literal ints * Fixed psalm errors * Fix invalid property accesses * Addressed comments * Added Tests * Marked RoundReturnTypeProvider as internal * Fixed CS
…meo#6966) (vimeo#7071) * Fixed vimeo#6966 * Only accept >= 0 values for mode argument in round() * Made round() only return float or literal float values and remove unneeded test * Registered RoundReturnTypeProvider * Updated cast analyzer to handle single string literal int values as literal ints * Fixed psalm errors * Fix invalid property accesses * Addressed comments * Added Tests * Marked RoundReturnTypeProvider as internal * Fixed CS
This PR fixes #6966.
I added a return type provider for the
roundfunction, which will now try to return a literalfloat, which can then be used for further analysis.The second change involves modifying the
CastAnalyzerto also return a literalintwhen possible. I also tried to simplify the code a bit.