Skip to content

Commit

Permalink
Allow missing return for unions with void type
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 12, 2020
1 parent 9665e16 commit e208c05
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Rules/Missing/MissingReturnRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public function processNode(Node $node, Scope $scope): array
throw new \PHPStan\ShouldNotHappenException();
}

if ($returnType instanceof VoidType) {
$isVoidSuperType = $returnType->isSuperTypeOf(new VoidType());
if ($isVoidSuperType->yes()) {
return [];
}

Expand Down
13 changes: 13 additions & 0 deletions tests/PHPStan/Rules/Missing/data/missing-return.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,16 @@ public function bodySpecifiedVoidTReturn3(): \Generator
}

}

class VoidUnion
{

/**
* @return int|void
*/
public function doFoo()
{
echo 'test';
}

}

0 comments on commit e208c05

Please sign in to comment.