Skip to content

Commit be27584

Browse files
committed
ObjectType - make class line part of the cache key
1 parent 36649d3 commit be27584

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

src/Type/ObjectType.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,15 @@ public function describe(VerbosityLevel $level): string
391391
$preciseNameCallback,
392392
$preciseWithSubtracted,
393393
function () use ($preciseWithSubtracted): string {
394-
return $preciseWithSubtracted() . '-' . static::class . '-' . $this->describeAdditionalCacheKey();
394+
$reflection = $this->classReflection;
395+
$line = '';
396+
if ($reflection !== null) {
397+
$line .= '-';
398+
$line .= (string) $reflection->getNativeReflection()->getStartLine();
399+
$line .= '-';
400+
}
401+
402+
return $preciseWithSubtracted() . '-' . static::class . '-' . $line . $this->describeAdditionalCacheKey();
395403
}
396404
);
397405
}
@@ -412,6 +420,13 @@ private function describeCache(): string
412420
$description .= sprintf('~%s', $this->subtractedType->describe(VerbosityLevel::cache()));
413421
}
414422

423+
$reflection = $this->classReflection;
424+
if ($reflection !== null) {
425+
$description .= '-';
426+
$description .= (string) $reflection->getNativeReflection()->getStartLine();
427+
$description .= '-';
428+
}
429+
415430
return $description;
416431
}
417432

tests/PHPStan/Analyser/AnalyserIntegrationTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,12 @@ public function testBug5527(): void
441441
$this->assertCount(0, $errors);
442442
}
443443

444+
public function testBug5639(): void
445+
{
446+
$errors = $this->runAnalyse(__DIR__ . '/data/bug-5639.php');
447+
$this->assertCount(0, $errors);
448+
}
449+
444450
/**
445451
* @param string $file
446452
* @return \PHPStan\Analyser\Error[]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Bug5639;
4+
5+
if (\version_compare(\PHP_VERSION, '7.0', '<'))
6+
{
7+
class Foo extends \Exception {
8+
function __toString(): string {
9+
$result = \sprintf("%s\n\nin %s on line %s", $this->message, $this->file, $this->line);
10+
return $result;
11+
}
12+
}
13+
}
14+
else
15+
{
16+
class Foo extends \Error {
17+
function __toString(): string {
18+
$result = \sprintf("%s\n\nin %s on line %s", $this->message, $this->file, $this->line);
19+
return $result;
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)