Skip to content

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Feb 18, 2022

Copy link
Contributor Author

@staabm staabm Feb 18, 2022

Choose a reason for hiding this comment

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

extracted the duplicated logic of the 2 json extensions into this re-usable class - which should also work for other methods using INT-bitwise flags.

After this PR is merged, we can use this new service in other extensions which also do bitwise flag stuff

Comment on lines 57 to 77
Copy link
Contributor Author

@staabm staabm Feb 18, 2022

Choose a reason for hiding this comment

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

the actual fix for the bug 6654 was the missing UnionType handling

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

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

This needs to work on yes/no/maybe basis with TrinaryLogic.

  1. Yes - we know that JSON_THROW_ON_ERROR is present - for example a constant integer or a constant reference.
  2. No - we know that JSON_THROW_ON_ERROR is not present - for example string, or a constant integer that doesn't include the value.
  3. Maybe - JSON_THROW_ON_ERROR might be present - for example int or mixed type.

@clxmstaab clxmstaab force-pushed the bitwise branch 5 times, most recently from 251f3d4 to 132ad93 Compare February 23, 2022 12:38
@staabm
Copy link
Contributor Author

staabm commented Feb 23, 2022

reworked to use Trinary. added test-coverage.

Copy link
Member

Choose a reason for hiding this comment

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

Even if the constant is not known by the ReflectionProvider, we could support this case for AST-driven analysis. If the expression is ConstFetch of $constName or even a bitwise combination where one of the parts is $constName, we can return Yes.

Copy link
Contributor Author

@staabm staabm Mar 2, 2022

Choose a reason for hiding this comment

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

I am not sure what todo with this feedback.

do you mean we should add AST-driven analysis with this PR? or in a future PR?


when the ReflectionProvider doesn't know the constant, and we therefore cannot judge what the value-type of the constant is (is it a string? is it a int? which constant-int value has it), IMO we cannot analyse whether its contained in a given expression, can we? or would you judge the constant just by its name, no matter what the value is?

do you see this "constant is not know to the ReflectionProvider" as an essential case, or is it a edge case which can be done later?

Copy link
Member

Choose a reason for hiding this comment

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

I think it's just about an if that could easily be added. If we ask BitwiseFlagHelper about a FOO_CONSTANT and we see the AST contains a ConstFetch of FOO_CONSTANT, we don't need to verify the value because we know it's the same thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I figured it out

@clxmstaab clxmstaab force-pushed the bitwise branch 4 times, most recently from 9a4dcdd to 1370ee2 Compare March 6, 2022 09:23
@staabm staabm force-pushed the bitwise branch 2 times, most recently from 44d6361 to 5412e18 Compare March 10, 2022 21:05
@ondrejmirtes ondrejmirtes merged commit cf27b2b into phpstan:1.5.x Mar 17, 2022
@ondrejmirtes
Copy link
Member

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handling of JSON_THROW_ON_ERROR with optional bitwise flags

3 participants