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

The supplied range exceeds the maximum array size #6375

Closed
voku opened this issue Jan 15, 2022 · 9 comments
Closed

The supplied range exceeds the maximum array size #6375

voku opened this issue Jan 15, 2022 · 9 comments

Comments

@voku
Copy link
Contributor

voku commented Jan 15, 2022

Bug report

I see this error message The supplied range exceeds the maximum array size: start=-2147483648 end=2147483647 after the update to v1.4.0.

write(3, "Uncaught ValueError: The supplie"..., 199Uncaught ValueError: The supplied range exceeds the maximum array size: start=-2147483648 end=2147483647 in /home/lmoelleken/testing/git/phpstan-
...
#1 /home/lmoelleken/testing/git/phpstan-src/src/Type/Constant/ConstantArrayType.php(462): PHPStan\Type\Constant\ConstantArrayTypeBuilder->setOffsetValueType()
#2 /home/lmoelleken/testing/git/phpstan-src/src/Rules/Arrays/OffsetAccessAssignmentRule.php(75): PHPStan\Type\Constant\ConstantArrayType->setOffsetValueType()
#3 /home/lmoelleken/testing/git/phpstan-src/src/Analyser/FileAnalyser.php(83): PHPStan\Rules\Arrays\OffsetAccessAssignmentRule->processNode()
#4 /home/lmoelleken/testing/git/phpstan-src/src/Node/ClassStatementsGatherer.php(108): PHPStan\Analyser\FileAnalyser->PHPStan\Analyser\{closure}()
#5 /home/lmoelleken/testing/git/phpstan-src/src/Analyser/NodeScopeResolver.php(500): PHPStan\Node\ClassStatementsGatherer->__invoke()
#6 /home/lmoelleken/testing/git/phpstan-src/src/Analyser/NodeScopeResolver.php(3117): PHPStan\Analyser\NodeScopeResolver::PHPStan\Analyser\{closure}()
#7 /home/lmoelleken/testing/git/phpstan-src/src/Analyser/NodeScopeResolver.php(1717): PHPStan\Analyser\NodeScopeResolver->processAssignVar()
#8 /home/lmoelleken/testing/git/phpstan-src/src/Analyser/NodeScopeResolver.php(565): PHPStan\Analyser\NodeScopeResolver->processExprNode()
#9 /home/lmoelleken/testing/git/phpstan-src/src/Analyser/NodeScopeResolver.php(256): PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#10 /home/lmoelleken/testing/git/phpstan-src/src/Analyser/NodeScopeResolver.php(516): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()
#11 /home/lmoelleken/testing/git/phpstan-src/src/Analyser/NodeScopeResolver.php(256): PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#12 /home/lmoelleken/testing/git/phpstan-src/src/Analyser/NodeScopeResolver.php(621): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()
#13 /home/lmoelleken/testing/git/phpstan-src/src/Analyser/NodeScopeResolver.php(216): PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#14 /home/lmoelleken/testing/git/phpstan-src/src/Analyser/FileAnalyser.php(199): PHPStan\Analyser\NodeScopeResolver->processNodes()
#15 /home/lmoelleken/testing/git/phpstan-src/src/Analyser/Analyser.php(71): PHPStan\Analyser\FileAnalyser->analyseFile()
#16 /home/lmoelleken/testing/git/phpstan-src/src/Command/AnalyserRunner.php(73): PHPStan\Analyser\Analyser->analyse()
#17 /home/lmoelleken/testing/git/phpstan-src/src/Command/AnalyseApplication.php(189): PHPStan\Command\AnalyserRunner->runAnalyser()
#18 /home/lmoelleken/testing/git/phpstan-src/src/Command/AnalyseApplication.php(90): PHPStan\Command\AnalyseApplication->runAnalyser()
#19 /home/lmoelleken/testing/git/phpstan-src/src/Command/AnalyseCommand.php(238): PHPStan\Command\AnalyseApplication->analyse()
#20 /home/lmoelleken/testing/git/phpstan-src/vendor/symfony/console/Command/Command.php(298): PHPStan\Command\AnalyseCommand->execute()
#21 /home/lmoelleken/testing/git/phpstan-src/vendor/symfony/console/Application.php(1005): Symfony\Component\Console\Command\Command->run()
#22 /home/lmoelleken/testing/git/phpstan-src/vendor/symfony/console/Application.php(299): Symfony\Component\Console\Application->doRunCommand()
#23 /home/lmoelleken/testing/git/phpstan-src/vendor/symfony/console/Application.php(171): Symfony\Component\Console\Application->doRun()
#24 /home/lmoelleken/testing/git/phpstan-src/bin/phpstan(128): Symfony\Component\Console\Application->run()
#25 /home/lmoelleken/testing/git/phpstan-src/bin/phpstan(129): {closure}()

Code snippet that reproduces the problem

Sadly, I can't find the root cause of the problem because it's a legacy class with ~2000 lines of code and the error message says nothing about why or where. :-/ I tried to delete random methods from the class and at some point it works, but if I only delete one of the methods it will fail again?

Expected output

Non error.

Did PHPStan help you today? Did it make you happy in any way?

Not today, but I already had one of those "make one change in codebase and then fix errors until phpstan stops complaining, then run it, and it works first time" moments. :)

@mergeable
Copy link

mergeable bot commented Jan 15, 2022

This bug report is missing a link to reproduction on phpstan.org.

It will most likely be closed after manual review.

@ondrejmirtes
Copy link
Member

Hi, a minimal example would definitely help here. Try deleting code from the file until the error no longer shows. Go one step back - the error now reproduces. Now delete some other code and verify the problem still shows. You'll end up with a minimal example.

@ondrejmirtes
Copy link
Member

This might fix it: phpstan/phpstan-src@86b9306

Please test phpstan/phpstan dev-master to see if it fixes it.

@voku
Copy link
Contributor Author

voku commented Jan 21, 2022

@ondrejmirtes It's not fixed. But I had some time for analyzing and I think that the problem is this line https://github.com/phpstan/phpstan-src/blob/1aef99d3c0bf5edb7448622f45376923c7e4aa3c/src/Type/Constant/ConstantArrayTypeBuilder.php#L114 in combination with values like this: int<-2147483648,2147483647> ... maybe it wasn't my best idea to add all int-ranges from the database into PHP.

@staabm
Copy link
Contributor

staabm commented Jan 24, 2022

Fwiw, I am using similar int ranges in phppstan-dba, and did not yet hit this error

https://github.com/staabm/phpstan-dba/blob/4d1c84b2dd4241ab9aee1f8e111a84e9d1df6313/src/Types/MysqlIntegerRanges.php#L31

@voku
Copy link
Contributor Author

voku commented Jan 24, 2022

The foreach (range(... thing is only used in the ConstantArrayTypeBuilder class.

@ondrejmirtes ondrejmirtes reopened this Jan 28, 2022
@voku
Copy link
Contributor Author

voku commented Jan 28, 2022

fix: phpstan/phpstan-src#934

@ondrejmirtes
Copy link
Member

Fixed by: phpstan/phpstan-src@d3f968d

@github-actions
Copy link

github-actions bot commented Mar 2, 2022

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 Mar 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants