Skip to content

Commit 40c8fb2

Browse files
committed
VoidType - accept null
1 parent 71f6c4d commit 40c8fb2

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/Type/VoidType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function acceptsWithReason(Type $type, bool $strictTypes): AcceptsResult
6666
return $type->isAcceptedWithReasonBy($this, $strictTypes);
6767
}
6868

69-
return AcceptsResult::createFromBoolean($type instanceof self);
69+
return new AcceptsResult($type->isVoid()->or($type->isNull()), []);
7070
}
7171

7272
public function isSuperTypeOf(Type $type): TrinaryLogic

tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,4 +988,9 @@ public function testBug6653(): void
988988
$this->analyse([__DIR__ . '/data/bug-6653.php'], []);
989989
}
990990

991+
public function testBug10291(): void
992+
{
993+
$this->analyse([__DIR__ . '/data/bug-10291.php'], []);
994+
}
995+
991996
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Bug10291;
4+
5+
class HelloWorld
6+
{
7+
/** @return void|int */
8+
public function sayHello()
9+
{
10+
return rand(0, 1) ? 17 : null;
11+
}
12+
13+
/**
14+
* @param bool $something
15+
* @return void|int
16+
*/
17+
public function sayHello2($something)
18+
{
19+
if ($something) {
20+
return rand(0, 1);
21+
} else {
22+
return $this->myrand();
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)