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

Fix failing case for const analyzer. #7503

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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',
],
];
}
}