Skip to content

Commit

Permalink
Add BCHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Jul 25, 2024
1 parent 957854c commit 9681144
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
use Psalm\Internal\Analyzer\Statements\Expression\YieldAnalyzer;
use Psalm\Internal\Analyzer\Statements\Expression\YieldFromAnalyzer;
use Psalm\Internal\Analyzer\StatementsAnalyzer;
use Psalm\Internal\BCHelper;
use Psalm\Internal\FileManipulation\FileManipulationBuffer;
use Psalm\Internal\Type\TemplateResult;
use Psalm\Issue\RiskyTruthyFalsyComparison;
Expand Down Expand Up @@ -456,7 +457,9 @@ private static function handleExpression(
return MatchAnalyzer::analyze($statements_analyzer, $stmt, $context);
}

if ($stmt instanceof PhpParser\Node\Expr\Throw_ && $analysis_php_version_id >= 8_00_00) {
if ($stmt instanceof PhpParser\Node\Expr\Throw_
&& ($analysis_php_version_id >= 8_00_00 || !BCHelper::usePHPParserV4())
) {
return ThrowAnalyzer::analyze($statements_analyzer, $stmt, $context);
}

Expand Down
14 changes: 14 additions & 0 deletions src/Psalm/Internal/BCHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Psalm\Internal;

/**
* @internal
*/
final class BCHelper
{
public static function usePHPParserV4(): bool
{
return class_exists('\PhpParser\Node\Stmt\Throw');
}
}

0 comments on commit 9681144

Please sign in to comment.