1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-12 01:09:38 +01:00
Commit Graph

9203 Commits

Author SHA1 Message Date
orklah
a8a659895f add failing test 2021-09-19 19:30:02 +02:00
orklah
f789ab0655 add test and allow checking in already inferred types instead of just relying on statements from PHPParser for assertions 2021-09-19 19:30:02 +02:00
orklah
ae0586b0e6 fix shift inference 2021-09-19 19:30:02 +02:00
orklah
bae5b2cf96 remove type when assertion contradicts the current type 2021-09-19 19:30:02 +02:00
orklah
e0e34bec33 allow intersections and add test 2021-09-19 19:30:02 +02:00
orklah
c26f403e7e fix an old bug with inverting positive int + allow inverting TIntRange 2021-09-19 19:30:02 +02:00
orklah
488c13b7c5 handle bit operations and add test 2021-09-19 19:30:02 +02:00
orklah
9994a91915 help Psalm understand the types 2021-09-19 19:30:02 +02:00
orklah
6f050359ce refactor int vs int range arithmetic by converting everything to range and add tests 2021-09-19 19:30:02 +02:00
orklah
4e9abcdf53 regenerate baseline 2021-09-19 19:30:02 +02:00
orklah
0227894176 fix code 2021-09-19 19:30:02 +02:00
orklah
d2f73d3adb fix and test minus case 2021-09-19 19:30:01 +02:00
orklah
d919a53674 rename method too 2021-09-19 19:30:01 +02:00
orklah
9ab46ff3e0 rename class because it handles Div too now 2021-09-19 19:30:01 +02:00
orklah
2dd16f9e22 simplify code 2021-09-19 19:30:01 +02:00
orklah
def7d31566 fix positive-numeric assertion 2021-09-19 19:30:01 +02:00
orklah
6d059b9c8f fix CS 2021-09-19 19:30:01 +02:00
orklah
b5b2677ee3 allow negating inferiorto/superiorto 2021-09-19 19:30:01 +02:00
orklah
b3a62c76dd add tests and use getNewHighestBound at one place 2021-09-19 19:30:01 +02:00
orklah
c20c1b5002 better div and modulo inference 2021-09-19 19:30:01 +02:00
orklah
05fb0c326d fix CS 2021-09-19 19:30:01 +02:00
orklah
3ad60cfdb9 Allow combining and improve comparison 2021-09-19 19:30:00 +02:00
orklah
e10b0fc3e9 use TIntRange in isAlwaysTruthy 2021-09-19 19:30:00 +02:00
orklah
edff17134d improve test 2021-09-19 19:30:00 +02:00
orklah
55b45853de try not to remove null after a positive-numeric assertion 2021-09-19 19:30:00 +02:00
orklah
219e425894 handle nightmare isset assertions 2021-09-19 19:30:00 +02:00
orklah
7d6ede61fd fix test 2021-09-19 19:30:00 +02:00
orklah
ee75586fbf expand test and fix assertions 2021-09-19 19:30:00 +02:00
orklah
d2e1388473 Allow inferior-to and superior-to even with negated numbers 2021-09-19 19:30:00 +02:00
orklah
21ceaa7dc7 reconcile positive-int with superior/inferior to 2021-09-19 19:30:00 +02:00
orklah
61d1d1660d handle the div case when even if min/max are integers, there may be float between them 2021-09-19 19:30:00 +02:00
orklah
168b1d8f0f fix wrong check with contains 2021-09-19 19:30:00 +02:00
orklah
9505411738 remove type by key instead of targetting global int 2021-09-19 19:30:00 +02:00
orklah
d9d9fa67a6 remove faulty test 2021-09-19 19:29:59 +02:00
orklah
c3afe103c5 allow asserting positive int on an int range 2021-09-19 19:29:59 +02:00
orklah
4682c4be5e remove unnecessary var 2021-09-19 19:29:59 +02:00
orklah
3a8afe07be fix test 2021-09-19 19:29:59 +02:00
orklah
86afff61c5 allow combining TIntRange with other ints 2021-09-19 19:29:59 +02:00
orklah
8325378e23 support inverted comparison and remove null after value comparison 2021-09-19 19:29:59 +02:00
orklah
ca4c18c30d put assertions back 2021-09-19 19:29:59 +02:00
orklah
1dcdaea117 int range arithmetics 2021-09-19 19:29:59 +02:00
Bruce Weirdan
3082a82a21
Merge pull request #6505 from orklah/DomDocumentProperties
add PropertyTypeProvider for DomDocument
2021-09-18 14:05:57 +03:00
orklah
57d0336a9c fix wrong result type 2021-09-18 08:49:52 +02:00
orklah
a1bd339cc1 add PropertyTypeProvider for DomDocument 2021-09-18 08:40:34 +02:00
Bruce Weirdan
37362b333c
Merge pull request #6503 from orklah/TClassString_inference 2021-09-17 21:54:54 +03:00
orklah
e9f3d5ba06 assert from TClassString 2021-09-17 20:05:25 +02:00
Bruce Weirdan
e4c6f97646
Merge pull request #6502 from pawel-slowik/get_browser_nullable_1st_arg 2021-09-17 20:27:22 +03:00
Paweł Słowik
2e51a9a8a7 Permit null user_agent to get_browser() 2021-09-17 16:46:27 +02:00
Morris Jobke
cf49eea09e
Catch ComplicatedExpressionException in ArrayFilterReturnTypeProvider
Many errors like this happened:

```
Uncaught Exception: Psalm\Exception\ComplicatedExpressionException
Stack trace in the forked worker:
 #0 /Users/morris/Projects/abc/vendor/vimeo/psalm/src/Psalm/Internal/Algebra.php(606): Psalm\Internal\Algebra::groupImpossibilities(Array)
 #1 /Users/morris/Projects/abc/vendor/vimeo/psalm/src/Psalm/Internal/Algebra/FormulaGenerator.php(255): Psalm\Internal\Algebra::negateFormula(NULL)
 #2 /Users/morris/Projects/abc/vendor/vimeo/psalm/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayFilterReturnTypeProvider.php(249): Psalm\Internal\Algebra\FormulaGenerator::getFormula(2818034, 2818034, Object(PhpParser\Node\Expr\BinaryOp\Identical), 'Guzzle\\Plugin\\C...', Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(Psalm\Codebase))
 #3 /Users/morris/Projects/abc/vendor/vimeo/psalm/src/Psalm/Internal/Provider/FunctionReturnTypeProvider.php(159): Psalm\Internal\Provider\ReturnTypeProvider\ArrayFilterReturnTypeProvider::getFunctionReturnType(Object(Psalm\Plugin\EventHandler\Event\FunctionReturnTypeProviderEvent))
 #4 /Users/morris/Projects/abc/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallReturnTypeFetcher.php(59): Psalm\Internal\Provider\FunctionReturnTypeProvider->getReturnType(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), 'array_filter', Object(PhpParser\Node\Expr\FuncCall), Object(Psalm\Context), Object(Psalm\CodeLocation))
 #5 /Users/morris/Projects/abc/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallAnalyzer.php(197): Psalm\Internal\Analyzer\Statements\Expression\Call\FunctionCallReturnTypeFetcher::fetch(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(Psalm\Codebase), Object(PhpParser\Node\Expr\FuncCall), Object(PhpParser\Node\Name), 'array_filter', true, false, NULL, Object(Psalm\Type\Atomic\TCallable), Object(Psalm\Internal\Type\TemplateResult), Object(Psalm\Context))
 #6 /Users/morris/Projects/abc/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php(263): Psalm\Internal\Analyzer\Statements\Expression\Call\FunctionCallAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\FuncCall), Object(Psalm\Context))
 #7 /Users/morris/Projects/abc/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php(43): Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer::handleExpression(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\FuncCall), Object(Psalm\Context), false, NULL, false)
 #8 /Users/morris/Projects/abc/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php(200): Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\FuncCall), Object(Psalm\Context))
 #9 /Users/morris/Projects/abc/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallAnalyzer.php(149): Psalm\Internal\Analyzer\Statements\Expression\Call\ArgumentsAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Array, Array, 'array_values', true, Object(Psalm\Context))
 #10 /Users/morris/Projects/abc/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php(263): Psalm\Internal\Analyzer\Statements\Expression\Call\FunctionCallAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\FuncCall), Object(Psalm\Context))
 #11 /Users/morris/Projects/abc/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php(43): Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer::handleExpression(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\FuncCall), Object(Psalm\Context), false, NULL, false)
 #12 /Users/morris/Projects/abc/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php(144): Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\FuncCall), Object(Psalm\Context))
 #13 /Users/morris/Projects/abc/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php(517): Psalm\Internal\Analyzer\Statements\ReturnAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Stmt\Return_), Object(Psalm\Context))
 #14 /Users/morris/Projects/abc/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php(185): Psalm\Internal\Analyzer\StatementsAnalyzer::analyzeStatement(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Stmt\Return_), Object(Psalm\Context), Object(Psalm\Context))
 #15 /Users/morris/Projects/abc/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php(433): Psalm\Internal\Analyzer\StatementsAnalyzer->analyze(Array, Object(Psalm\Context), Object(Psalm\Context), true)
 #16 /Users/morris/Projects/abc/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClassAnalyzer.php(1782): Psalm\Internal\Analyzer\FunctionLikeAnalyzer->analyze(Object(Psalm\Context), Object(Psalm\Internal\Provider\NodeDataProvider), Object(Psalm\Context))
 #17 /Users/morris/Projects/abc/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClassAnalyzer.php(404): Psalm\Internal\Analyzer\ClassAnalyzer->analyzeClassMethod(Object(PhpParser\Node\Stmt\ClassMethod), Object(Psalm\Storage\ClassLikeStorage), Object(Psalm\Internal\Analyzer\ClassAnalyzer), Object(Psalm\Context), Object(Psalm\Context))
 #18 /Users/morris/Projects/abc/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FileAnalyzer.php(214): Psalm\Internal\Analyzer\ClassAnalyzer->analyze(Object(Psalm\Context), Object(Psalm\Context))
 #19 /Users/morris/Projects/abc/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(348): Psalm\Internal\Analyzer\FileAnalyzer->analyze(NULL)
 #20 /Users/morris/Projects/abc/vendor/vimeo/psalm/src/Psalm/Internal/Fork/Pool.php(194): Psalm\Internal\Codebase\Analyzer->Psalm\Internal\Codebase\{closure}(369, '/Users/morris/P...')
 #21 /Users/morris/Projects/abc/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(414): Psalm\Internal\Fork\Pool->__construct(Array, Object(Closure), Object(Closure), Object(Closure), Object(Closure))
 #22 /Users/morris/Projects/abc/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(277): Psalm\Internal\Codebase\Analyzer->doAnalysis(Object(Psalm\Internal\Analyzer\ProjectAnalyzer), 7)
 #23 /Users/morris/Projects/abc/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php(640): Psalm\Internal\Codebase\Analyzer->analyzeFiles(Object(Psalm\Internal\Analyzer\ProjectAnalyzer), 7, false, true)
 #24 /Users/morris/Projects/abc/vendor/vimeo/psalm/src/Psalm/Internal/Cli/Psalm.php(359): Psalm\Internal\Analyzer\ProjectAnalyzer->check('/Users/morris/P...', true)
 #25 /Users/morris/Projects/abc/vendor/vimeo/psalm/psalm(4): Psalm\Internal\Cli\Psalm::run(Array)
 #26 {main} in /Users/morris/Projects/abc/vendor/vimeo/psalm/src/Psalm/Internal/Fork/Pool.php:366
Stack trace:
 #0 /Users/morris/Projects/abc/vendor/vimeo/psalm/src/Psalm/Internal/Fork/Pool.php(400): Psalm\Internal\Fork\Pool->readResultsFromChildren()
 #1 /Users/morris/Projects/abc/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(488): Psalm\Internal\Fork\Pool->wait()
 #2 /Users/morris/Projects/abc/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(277): Psalm\Internal\Codebase\Analyzer->doAnalysis(Object(Psalm\Internal\Analyzer\ProjectAnalyzer), 7)
 #3 /Users/morris/Projects/abc/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php(640): Psalm\Internal\Codebase\Analyzer->analyzeFiles(Object(Psalm\Internal\Analyzer\ProjectAnalyzer), 7, false, true)
 #4 /Users/morris/Projects/abc/vendor/vimeo/psalm/src/Psalm/Internal/Cli/Psalm.php(359): Psalm\Internal\Analyzer\ProjectAnalyzer->check('/Users/morris/P...', true)
 #5 /Users/morris/Projects/abc/vendor/vimeo/psalm/psalm(4): Psalm\Internal\Cli\Psalm::run(Array)
 #6 {main}
(Psalm 4.10.0@916b098b008f6de4543892b1e0651c1c3b92cbfa crashed due to an uncaught Throwable)
```

This change catches the exception and just omits the results here.

Disclaimer: I just added the code like @orklah said in https://github.com/vimeo/psalm/pull/6489#issuecomment-921057199.

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
2021-09-17 09:41:05 +02:00
Bruce Weirdan
b857d0b0f7
Merge pull request #6494 from simPod/template 2021-09-17 02:50:35 +03:00