Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/Rules/Traits/ConflictingTraitConstantsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ public function processNode(Node $node, Scope $scope): array
$classConstantValueType = $this->initializerExprTypeResolver->getType($const->value, InitializerExprContext::fromClassReflection($classReflection));
$traitConstantValueType = $this->initializerExprTypeResolver->getType(
$immediateTraitConstant->getValueExpression(),
InitializerExprContext::fromClass(
$immediateTraitConstant->getDeclaringClass()->getName(),
$immediateTraitConstant->getDeclaringClass()->getFileName() !== false ? $immediateTraitConstant->getDeclaringClass()->getFileName() : null,
),
InitializerExprContext::fromClassReflection($classReflection),
);
if ($classConstantValueType->equals($traitConstantValueType)) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,10 @@ public function testBug13119(): void
$this->analyse([__DIR__ . '/data/bug-13119.php'], []);
}

#[RequiresPhp('>= 8.2')]
public function testBug11351(): void
{
$this->analyse([__DIR__ . '/data/bug-11351.php'], []);
}

}
45 changes: 45 additions & 0 deletions tests/PHPStan/Rules/Traits/data/bug-11351.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php // lint >= 8.2

declare(strict_types = 1);

namespace Bug11351;

trait TA
{
protected const A = [
self::CA => 'CA',
];
}

class A
{
use TA;
public const CA = 'abc';
}

trait TB
{
protected const B = [
'key' => self::CB,
];
}

class B
{
use TB;
public const CB = 'value';
}

trait TC
{
protected const C = [
self::CC1 => self::CC2,
];
}

class C
{
use TC;
public const CC1 = 'key';
public const CC2 = 'value';
}
Loading