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

Crash in the assert reconciier #9984

Closed
SCIF opened this issue Jul 2, 2023 · 5 comments · Fixed by #10123
Closed

Crash in the assert reconciier #9984

SCIF opened this issue Jul 2, 2023 · 5 comments · Fixed by #10123

Comments

@SCIF
Copy link
Contributor

SCIF commented Jul 2, 2023

https://psalm.dev/r/be04c357aa

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/be04c357aa
<?php

class A {
    /** @var array{0?: int, 1?: 'foo'|'bar'} */
    private array $in;

    /** @psalm-assert-if-true array{0: int} $this->in */
    public function test(): bool
    {
        return true;
    }

    /** @psalm-assert-if-true array{0: int, 1: 'bar'} $this->in */
    public function test2(): bool
    {
        return false;
    }
}

$a = new A;
if ($a->test()) {
    echo '1';
} elseif ($a->test2()) {
    echo '12';
}
Psalm output (using commit 8d1876a):

ERROR: MissingConstructor - 5:19 - A has an uninitialized property A::$in, but no constructor

@SCIF SCIF changed the title Crash in assert reconcilier Crash in the assert reconciier Jul 2, 2023
@SCIF
Copy link
Contributor Author

SCIF commented Jul 2, 2023

A little bit weird why cloud interpreter has not crashed. My local one is crashed

@ygottschalk
Copy link
Contributor

Can you post the stack trace of the crash and the exact version you are using locally?

@SCIF
Copy link
Contributor Author

SCIF commented Jul 3, 2023

@ygottschalk ,

Target PHP version: 8.2 (inferred from current PHP version) Enabled extensions: redis (unsupported extensions: igbinary, imagick, zend-opcache).
Scanning files...
Analyzing files...

Uncaught RuntimeException: PHP Error: Undefined array key 0 in /app/vendor/vimeo/psalm/src/Psalm/Type/Reconciler.php:427 for command with CLI args "./vendor/bin/psalm --no-cache --threads=1 --ignore-baseline 1.php" in /app/vendor/vimeo/psalm/src/Psalm/Internal/ErrorHandler.php:75
Stack trace:
#0 /app/vendor/vimeo/psalm/src/Psalm/Type/Reconciler.php(427): Psalm\Internal\ErrorHandler::Psalm\Internal\{closure}(2, 'Undefined array...', '/app/v...', 427)
#1 /app/vendor/vimeo/psalm/src/Psalm/Type/Reconciler.php(153): Psalm\Type\Reconciler::addNestedAssertions(Array, Array)
#2 /app/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseIfAnalyzer.php(215): Psalm\Type\Reconciler::reconcileKeyedTypes(Array, Array, Array, Array, Array, Array, Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Array, false, Object(Psalm\CodeLocation))
#3 /app/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Block/IfElseAnalyzer.php(281): Psalm\Internal\Analyzer\Statements\Block\IfElse\ElseIfAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Stmt\ElseIf_), Object(Psalm\Internal\Scope\IfScope), Object(Psalm\Context), Object(Psalm\Context), Object(Psalm\Codebase), 389)
#4 /app/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php(514): Psalm\Internal\Analyzer\Statements\Block\IfElseAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Stmt\If_), Object(Psalm\Context))
#5 /app/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php(194): Psalm\Internal\Analyzer\StatementsAnalyzer::analyzeStatement(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Stmt\If_), Object(Psalm\Context), NULL)
#6 /app/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FileAnalyzer.php(179): Psalm\Internal\Analyzer\StatementsAnalyzer->analyze(Array, Object(Psalm\Context), NULL, true)
#7 /app/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(1591): Psalm\Internal\Analyzer\FileAnalyzer->analyze()
#8 /app/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(522): Psalm\Internal\Codebase\Analyzer->analysisWorker(0, '/app/1...')
#9 /app/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(272): Psalm\Internal\Codebase\Analyzer->doAnalysis(Object(Psalm\Internal\Analyzer\ProjectAnalyzer), 1)
#10 /app/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php(1078): Psalm\Internal\Codebase\Analyzer->analyzeFiles(Object(Psalm\Internal\Analyzer\ProjectAnalyzer), 1, false, false)
#11 /app/vendor/vimeo/psalm/src/Psalm/Internal/Cli/Psalm.php(372): Psalm\Internal\Analyzer\ProjectAnalyzer->checkPaths(Array)
#12 /app/vendor/vimeo/psalm/psalm(9): Psalm\Internal\Cli\Psalm::run(Array)
#13 /app/vendor/bin/psalm(119): include('/app/v...')
#14 {main}
(Psalm 5.13.1@086b94371304750d1c673315321a55d15fc59015 crashed due to an uncaught Throwable)

@orklah
Copy link
Collaborator

orklah commented Jul 3, 2023

yeah, that should definitely not happen.

Ironically, Psalm warned that this was dangerous and it was ignored:

<code>$type[0][0]</code>

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

Successfully merging a pull request may close this issue.

4 participants