Skip to content
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

Truthy check fails to refine type #1014

Closed
muglug opened this issue May 17, 2018 · 2 comments
Closed

Truthy check fails to refine type #1014

muglug opened this issue May 17, 2018 · 2 comments

Comments

@muglug
Copy link
Contributor

muglug commented May 17, 2018

$s = rand(0, 1) ? 0 : 1;

if ($s) {
  $s = 3;
}

if ($s === 1) {}

Expected: Strict comparison using === between 0|3 and 1 will always evaluate to false.
Actual: No issue

Fixed by making the comparison explicit:

$s = rand(0, 1) ? 0 : 1;

if ($s === 1) {
  $s = 3;
}

if ($s === 1) {}
@ondrejmirtes ondrejmirtes modified the milestone: 0.10 May 17, 2018
@ondrejmirtes ondrejmirtes added this to the NodeScopeResolver bugs milestone Jan 12, 2019
jlherren added a commit to jlherren/phpstan-src that referenced this issue Oct 11, 2020
ondrejmirtes pushed a commit to jlherren/phpstan-src that referenced this issue Oct 12, 2020
ondrejmirtes added a commit that referenced this issue Oct 12, 2020
phpstan/phpstan-src@242c9ad Sort numeric types in UnionType deterministically
phpstan/phpstan-src@c605f47 Add TypeUtils::falsey() and add '0' to be falsey
phpstan/phpstan-src@35b8f84 Add TypeUtils::truthy() and make it work correctly
phpstan/phpstan-src@455a286 Add tests for propagation of truthy/falsey values
phpstan/phpstan-src@0688c41 Fix linting for PHP <7.3
phpstan/phpstan-src@69958e2 Add test for fixed bug #1014
phpstan/phpstan-src@5b88a8b Moved new methods to StaticTypeFactory
@ondrejmirtes
Copy link
Member

Fixed in: phpstan/phpstan-src#339

ondrejmirtes added a commit that referenced this issue Oct 12, 2020
phpstan/phpstan-src@0c9a4eb Read PHPDocs from PHP 8 stubs
phpstan/phpstan-src@7abfcfe Fix PHP 8.0 PHPStan build
phpstan/phpstan-src@302c7ba Fix
phpstan/phpstan-src@2c8390a Fix
phpstan/phpstan-src@3d1d930 ClassReflection::getName() returns class-string
phpstan/phpstan-src@d015be3 Moved this test to phpstan/phpstan as E2E test
phpstan/phpstan-src@3803ab7 Fix build
phpstan/phpstan-src@22871e7 PHP 8 stubs - test that everything can be parsed
phpstan/phpstan-src@4033321 Updated BetterReflection
phpstan/phpstan-src@287b8b8 Fix variadic parameter after optional
phpstan/phpstan-src@3640fcd Fix build
phpstan/phpstan-src@2cd7001 Fix reporting overriden variadics
phpstan/phpstan-src@aa59aaf Fix
phpstan/phpstan-src@04087a8 Fix
phpstan/phpstan-src@620f367 PHP 8 - overriding method has less parameters but the last one is variadic
phpstan/phpstan-src@75e28e8 Fix
phpstan/phpstan-src@7785e12 socket_addrinfo_lookup signature
phpstan/phpstan-src@15ccf5a SplFixedArray is Aggregate, not Iterable on PHP 8
phpstan/phpstan-src@bac94eb This is a parse error always anyway
phpstan/phpstan-src@5a65a67 NodeTraverser is no longer a shared service
phpstan/phpstan-src@a231694 RequireParenthesesForNestedTernaryRule on PHP 8
phpstan/phpstan-src@b6c1d87 Prevented weird bug
phpstan/phpstan-src@093d92f Some fixes for PHP 8
phpstan/phpstan-src@1f47d69 Fix Memcache::get signature
phpstan/phpstan-src@6835f4c Fix build
phpstan/phpstan-src@c9b20c1 Possible fix
phpstan/phpstan-src@63bcf20 FilterVarDynamicReturnTypeExtension - lazy
phpstan/phpstan-src@17bc26f Fix
phpstan/phpstan-src@a2b8dc7 Memory optimization using linked list
phpstan/phpstan-src@c201a37 Increase memory limit for tests
phpstan/phpstan-src@f152327 Disregard PHP 8 stubs for methods and functions with multiple variants
phpstan/phpstan-src@8f28721 Fix error
phpstan/phpstan-src@7ce2e54 First parameter of SimpleXMLElement::children() accepts null
phpstan/phpstan-src@6fbe405 Fix CS
phpstan/phpstan-src@e1a8a49 Revert "Use functionMap parameter name instead of PHP 8 stub name"
phpstan/phpstan-src@b87dba1 PHP 8 stubs - parameter name array has always type array
phpstan/phpstan-src@71e7550 functionMap - synchronized some of parameter names with PHP 8 stubs to have the test always pass
phpstan/phpstan-src@4ce285b Fix tests
phpstan/phpstan-src@0c87f16 Synchronize substr() parameter name
phpstan/phpstan-src@242c9ad Sort numeric types in UnionType deterministically
phpstan/phpstan-src@c605f47 Add TypeUtils::falsey() and add '0' to be falsey
phpstan/phpstan-src@35b8f84 Add TypeUtils::truthy() and make it work correctly
phpstan/phpstan-src@455a286 Add tests for propagation of truthy/falsey values
phpstan/phpstan-src@0688c41 Fix linting for PHP <7.3
phpstan/phpstan-src@69958e2 Add test for fixed bug #1014
phpstan/phpstan-src@5b88a8b Moved new methods to StaticTypeFactory
phpstan/phpstan-src@7a4b50d Prevent internal error
phpstan/phpstan-src@ebce7de Fixed bug with uncertain variables merging in root scope
phpstan/phpstan-src@f0b80bc Update PHP 8 stubs
phpstan/phpstan-src@c54e495 Dynamic return type extension for `pow()`
ondrejmirtes added a commit that referenced this issue Oct 16, 2020
phpstan/phpstan-src@c9b20c1 Possible fix
phpstan/phpstan-src@63bcf20 FilterVarDynamicReturnTypeExtension - lazy
phpstan/phpstan-src@17bc26f Fix
phpstan/phpstan-src@a2b8dc7 Memory optimization using linked list
phpstan/phpstan-src@c201a37 Increase memory limit for tests
phpstan/phpstan-src@f152327 Disregard PHP 8 stubs for methods and functions with multiple variants
phpstan/phpstan-src@8f28721 Fix error
phpstan/phpstan-src@7ce2e54 First parameter of SimpleXMLElement::children() accepts null
phpstan/phpstan-src@6fbe405 Fix CS
phpstan/phpstan-src@e1a8a49 Revert "Use functionMap parameter name instead of PHP 8 stub name"
phpstan/phpstan-src@b87dba1 PHP 8 stubs - parameter name array has always type array
phpstan/phpstan-src@71e7550 functionMap - synchronized some of parameter names with PHP 8 stubs to have the test always pass
phpstan/phpstan-src@4ce285b Fix tests
phpstan/phpstan-src@0c87f16 Synchronize substr() parameter name
phpstan/phpstan-src@242c9ad Sort numeric types in UnionType deterministically
phpstan/phpstan-src@c605f47 Add TypeUtils::falsey() and add '0' to be falsey
phpstan/phpstan-src@35b8f84 Add TypeUtils::truthy() and make it work correctly
phpstan/phpstan-src@455a286 Add tests for propagation of truthy/falsey values
phpstan/phpstan-src@0688c41 Fix linting for PHP <7.3
phpstan/phpstan-src@69958e2 Add test for fixed bug #1014
phpstan/phpstan-src@5b88a8b Moved new methods to StaticTypeFactory
phpstan/phpstan-src@7a4b50d Prevent internal error
phpstan/phpstan-src@ebce7de Fixed bug with uncertain variables merging in root scope
phpstan/phpstan-src@f0b80bc Update PHP 8 stubs
phpstan/phpstan-src@c54e495 Dynamic return type extension for `pow()`
phpstan/phpstan-src@a093f92 Fix an intersection with NeverType
phpstan/phpstan-src@4a74d7c Fix GenericClassStringType being equal when it's not
phpstan/phpstan-src@8c13aea Fix intersection of iterable and array
phpstan/phpstan-src@e44246a Fixed test
phpstan/phpstan-src@5eaf71b Update dependencies
phpstan/phpstan-src@7a38424 Remove clashing duplicated file
phpstan/phpstan-src@5f2d42c Support for throw expression (PHP 8.0)
phpstan/phpstan-src@41c4e02 Correct hash function stub return type
phpstan/phpstan-src@4be8d5a Fix build
phpstan/phpstan-src@ea43e81 Fixed nested ternary
phpstan/phpstan-src@b32eb49 Fixed build
phpstan/phpstan-src@57472f9 Fixed build
phpstan/phpstan-src@4d81b68 Renamed stubs
phpstan/phpstan-src@8c5ee83 Debugging messages for parallel analysis
phpstan/phpstan-src@43ae839 Cleanup
phpstan/phpstan-src@8a731f7 TestCase - pass current PhpVersion to PhpStormStubsSourceStubber's constructor
phpstan/phpstan-src@842b468 Fixed casting CurlHandle to (int)
phpstan/phpstan-src@f9a6538 Test accepting numeric strings
phpstan/phpstan-src@a4038b2 Support non-empty-array and non-empty-list
phpstan/phpstan-src@af5921e Fixed SimpleXMLElement bug
phpstan/phpstan-src@befb743 Fix SimpleXMLElement iterable type on PHP 8
phpstan/phpstan-src@8113f38 Report real file with a parse error
phpstan/phpstan-src@869f27b FuzzyRelativePathHelper - relativize path even when outside of analysed paths (like vendor)
phpstan/phpstan-src@cec1be7 Support ::class on expression (PHP 8.0)
phpstan/phpstan-src@2d98ddd Revert "Debugging messages for parallel analysis"
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants