Skip to content

Commit 1857c6c

Browse files
committed
Native return type void can be combined with PHPDoc type never
1 parent 2a8bc1d commit 1857c6c

3 files changed

Lines changed: 34 additions & 4 deletions

File tree

src/Type/TypehintHelper.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ public static function decideType(
103103
{
104104
if ($phpDocType !== null && !$phpDocType instanceof ErrorType) {
105105
if ($type instanceof VoidType) {
106+
if ($phpDocType instanceof NeverType && $phpDocType->isExplicit()) {
107+
return $phpDocType;
108+
}
109+
106110
return new VoidType();
107111
}
108112
if (

tests/PHPStan/Rules/Methods/MethodSignatureRuleTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,6 @@ public function testBug4003(): void
232232
'Parameter #1 $test (string) of method Bug4003\Ipsum::doFoo() should be compatible with parameter $test (int) of method Bug4003\Lorem::doFoo()',
233233
38,
234234
],
235-
[
236-
'Return type (void) of method Bug4003\Amet::bar() should be compatible with return type (*NEVER*) of method Bug4003\Dolor::bar()',
237-
54,
238-
],
239235
]);
240236
}
241237

@@ -280,4 +276,11 @@ public function testBug4023(): void
280276
$this->analyse([__DIR__ . '/data/bug-4023.php'], []);
281277
}
282278

279+
public function testBug4006(): void
280+
{
281+
$this->reportMaybes = true;
282+
$this->reportStatic = true;
283+
$this->analyse([__DIR__ . '/data/bug-4006.php'], []);
284+
}
285+
283286
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Bug4006;
4+
5+
interface Foo
6+
{
7+
8+
/**
9+
* @return never
10+
*/
11+
public function bar();
12+
13+
}
14+
15+
class Bar implements Foo
16+
{
17+
18+
public function bar(): void
19+
{
20+
throw new \Exception();
21+
}
22+
23+
}

0 commit comments

Comments
 (0)