Skip to content

Commit 22baf56

Browse files
authored
Merge pull request #11695 from kkmuffme/duplicate-error-for-abstract-method-trait
Fix duplicate error for abstract methods in traits if the issue is due to the implementer
2 parents 28dc127 + 918d4a4 commit 22baf56

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/Psalm/Internal/Analyzer/ClassAnalyzer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1752,7 +1752,7 @@ private function analyzeClassMethod(
17521752
$declaring_method_storage,
17531753
$this->fq_class_name,
17541754
$implementer_method_storage->visibility,
1755-
new CodeLocation($source, $stmt),
1755+
$implementer_method_storage->stmt_location ?? new CodeLocation($source, $stmt),
17561756
$implementer_method_storage->suppressed_issues,
17571757
false,
17581758
);

tests/TraitTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,22 @@ public function fooFoo(string $a): void {
11521152
}',
11531153
'error_message' => 'MethodSignatureMismatch',
11541154
],
1155+
'dontReportImplementerErrorOnAbstractTraitMethodTwice' => [
1156+
'code' => '<?php
1157+
trait B {
1158+
abstract public function run();
1159+
}
1160+
1161+
final class A {
1162+
use B;
1163+
1164+
#[Override]
1165+
public function run(string $foo): string {
1166+
return $foo;
1167+
}
1168+
}',
1169+
'error_message' => 'MethodSignatureMismatch - src' . DIRECTORY_SEPARATOR . 'somefile.php:9:',
1170+
],
11551171
'missingTraitPropertyType' => [
11561172
'code' => '<?php
11571173
trait T {

0 commit comments

Comments
 (0)