Skip to content

Commit

Permalink
Merge pull request #7503 from AndrolGenhald/bugfix/fix-const-analyzer…
Browse files Browse the repository at this point in the history
…-failing-assert

Fix failing case for const analyzer.
  • Loading branch information
orklah committed Jan 28, 2022
2 parents 1a6f968 + 282518c commit 47a2545
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Expand Up @@ -79,6 +79,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
ini-values: zend.assertions=1, assert.exception=1
tools: composer:v2
coverage: none
extensions: decimal
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/windows-ci.yml
Expand Up @@ -49,6 +49,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
ini-values: zend.assertions=1, assert.exception=1
tools: composer:v2
coverage: none

Expand Down
Expand Up @@ -759,7 +759,7 @@ public static function analyze(
/**
* Get the const storage from the parent or interface that this class is overriding.
*
* @return array{ClassLikeStorage, ?ClassConstantStorage}|null
* @return array{ClassLikeStorage, ClassConstantStorage}|null
*/
private static function getOverriddenConstant(
ClassLikeStorage $class_storage,
Expand Down Expand Up @@ -837,6 +837,10 @@ private static function getOverriddenConstant(
}
}

if ($parent_const_storage === null) {
$parent_const_storage = $interface_const_storage;
}

foreach ($interface_overrides as $_ => $issue) {
IssueBuffer::maybeAdd(
$issue,
Expand All @@ -845,6 +849,7 @@ private static function getOverriddenConstant(
}

if ($parent_classlike_storage !== null) {
assert($parent_const_storage !== null);
return [$parent_classlike_storage, $parent_const_storage];
}
return null;
Expand Down
31 changes: 25 additions & 6 deletions tests/ConstantTest.php
Expand Up @@ -447,9 +447,9 @@ public function getA(): array {
return self::C;
}
}',
[],
[],
'8.1',
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.1',
],
'resolveCalculatedConstant' => [
'code' => '<?php
Expand Down Expand Up @@ -1364,9 +1364,9 @@ class Baz implements Bar
public const BAR="foobar";
}
',
[],
[],
'8.1',
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.1',
],
'inheritedConstDoesNotOverride' => [
'code' => '<?php
Expand Down Expand Up @@ -1823,6 +1823,25 @@ interface Bar extends Foo
',
'error_message' => 'OverriddenInterfaceConstant',
],
'overrideClassConstFromInterfaceWithExtraIrrelevantInterface' => [
'code' => '<?php
interface Foo
{
/** @var non-empty-string */
public const BAR="baz";
}
interface Bar {}
class Baz implements Foo, Bar
{
public const BAR="";
}
',
'error_message' => "LessSpecificClassConstantType",
'ignored_issues' => [],
'php_version' => '8.1',
],
];
}
}

0 comments on commit 47a2545

Please sign in to comment.