Skip to content

Commit ee6a07e

Browse files
committed
fix incorrect circular dependency if multiple stubbed types (trait+interface, or trait+extends,...) are used
1 parent 5ece935 commit ee6a07e

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

src/Psalm/Internal/Codebase/Populator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ private function populateClassLikeStorage(ClassLikeStorage $storage, array $depe
251251

252252
$dependency->populated = false;
253253
unset($dependency->invalid_dependencies[$fq_classlike_name_lc]);
254-
$this->populateClassLikeStorage($dependency, $dependent_classlikes);
254+
$this->populateClassLikeStorage($dependency, $dependency->dependent_classlikes);
255255
}
256256

257257
unset($this->invalid_class_storages[$fq_classlike_name_lc]);

tests/StubTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,56 @@ public function run_stubbed($x): float {
12451245
$this->analyzeFile($file_path, new Context());
12461246
}
12471247

1248+
public function testUseOnlyStubbedTraitAndInterface(): void
1249+
{
1250+
$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
1251+
TestConfig::loadFromXML(
1252+
dirname(__DIR__),
1253+
'<?xml version="1.0"?>
1254+
<psalm
1255+
errorLevel="1"
1256+
>
1257+
<projectFiles>
1258+
<directory name="src" />
1259+
</projectFiles>
1260+
1261+
<stubs>
1262+
<file name="tests/fixtures/stubs/trait.phpstub" />
1263+
<file name="tests/fixtures/stubs/interface.phpstub" />
1264+
</stubs>
1265+
</psalm>',
1266+
),
1267+
);
1268+
1269+
$file_path = (string) getcwd() . '/src/somefile.php';
1270+
1271+
$this->addFile(
1272+
$file_path,
1273+
'<?php
1274+
namespace Foo;
1275+
1276+
class A implements StubbedInterface {
1277+
use StubbedTrait;
1278+
1279+
public function run(): float {
1280+
return $this->run_stubbed_trait(rand(7, 9));
1281+
}
1282+
1283+
/**
1284+
* @param int $x
1285+
*/
1286+
public function run_stubbed($x): float {
1287+
return $x . "";
1288+
}
1289+
}',
1290+
);
1291+
1292+
$this->expectExceptionMessage('InvalidReturnType');
1293+
$this->expectException(CodeException::class);
1294+
1295+
$this->analyzeFile($file_path, new Context());
1296+
}
1297+
12481298
public function testStubFileWithExtendedStubbedClass(): void
12491299
{
12501300
$this->project_analyzer = $this->getProjectAnalyzerWithConfig(

0 commit comments

Comments
 (0)