fix(parser): preserve numeric variable types (#85) - #86
Closed
jefyokta wants to merge 2 commits into
Closed
Conversation
Contributor
Author
|
i forgot to test to build tpc with the new tpc, anyway https://github.com/swoole/phpx/blob/f5663b75c313d817680d26fcae021d67ef32e4f6/include/phpx.h#L2680 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #85.
Numeric variables were being converted to
php::Varwhennative_typeswas not enabled. This allowed variables initially inferred as numeric types to be reassigned to incompatible types.For example:
Previously, this was allowed because
$xwas converted tophp::Var.This change preserves the inferred numeric type by default, making its behavior consistent with other inferred types such as
string,array, andobject.The reassignment above will now be rejected because
$xis inferred asphp::Int.Expected behavior
native_typesshould no longer be required to strictly preserve the inferred numeric type.Implementation
The change is made in
getNativeType():This method is only called once, so changing this behavior does not introduce additional conversion paths or require broader changes to the type inference logic. the only one line that call it:
typephp/src/Parser/AssignOpTrait.php
Lines 650 to 652 in 87c7eda
If the intended design is that strict numeric type inference should explicitly require
native_types, this PR can be rejected accordingly.