Skip to content

Commit 936cea5

Browse files
committed
Fix
1 parent 1b90cf3 commit 936cea5

File tree

4 files changed

+60
-2
lines changed

4 files changed

+60
-2
lines changed

src/Type/Generic/TemplateTypeTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function equals(Type $type): bool
9292
return $type instanceof self
9393
&& $type->scope->equals($this->scope)
9494
&& $type->name === $this->name
95-
&& $this->bound->equals($type);
95+
&& $this->bound->equals($type->bound);
9696
}
9797

9898
public function isAcceptedBy(Type $acceptingType, bool $strictTypes): TrinaryLogic

tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,4 +444,9 @@ public function testBug4590(): void
444444
]);
445445
}
446446

447+
public function testTemplateStringBound(): void
448+
{
449+
$this->analyse([__DIR__ . '/data/template-string-bound.php'], []);
450+
}
451+
447452
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace TemplateStringBound;
4+
5+
/** @template T of string */
6+
class Foo
7+
{
8+
9+
/** @var T */
10+
private $value;
11+
12+
/**
13+
* @param T $value
14+
*/
15+
public function __construct($value)
16+
{
17+
$this->value = $value;
18+
}
19+
20+
/**
21+
* @return T
22+
*/
23+
public function getValue(): string
24+
{
25+
return $this->value;
26+
}
27+
28+
}
29+
30+
/** @template T of int */
31+
class Bar
32+
{
33+
34+
/** @var T */
35+
private $value;
36+
37+
/**
38+
* @param T $value
39+
*/
40+
public function __construct($value)
41+
{
42+
$this->value = $value;
43+
}
44+
45+
/**
46+
* @return T
47+
*/
48+
public function getValue(): int
49+
{
50+
return $this->value;
51+
}
52+
53+
}

tests/PHPStan/Type/StringTypeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public function dataAccepts(): iterable
162162
new StringType(),
163163
TemplateTypeVariance::createInvariant()
164164
)->toArgument(),
165-
TrinaryLogic::createNo(),
165+
TrinaryLogic::createYes(),
166166
];
167167
}
168168

0 commit comments

Comments
 (0)