1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Fix return {expr} checks for void functions

This commit is contained in:
Matt Brown 2017-12-14 12:50:02 -05:00
parent d440e4bbb1
commit 52c414f1d2
3 changed files with 15 additions and 2 deletions

View File

@ -172,7 +172,7 @@ abstract class SourceChecker implements StatementsSource
throw new \UnexpectedValueException('$source cannot be null');
}
return $this->source->addSuppressedIssues($new_issues);
$this->source->addSuppressedIssues($new_issues);
}
/**
@ -186,7 +186,7 @@ abstract class SourceChecker implements StatementsSource
throw new \UnexpectedValueException('$source cannot be null');
}
return $this->source->removeSuppressedIssues($new_issues);
$this->source->removeSuppressedIssues($new_issues);
}
/**

View File

@ -908,6 +908,10 @@ class StatementsChecker extends SourceChecker implements StatementsSource
$stmt->inferredType = Type::parseString($var_comment->type);
} elseif (isset($stmt->expr->inferredType)) {
$stmt->inferredType = $stmt->expr->inferredType;
if ($stmt->inferredType->isVoid()) {
$stmt->inferredType = Type::getNull();
}
} else {
$stmt->inferredType = Type::getMixed();
}

View File

@ -538,6 +538,15 @@ class ReturnTypeTest extends TestCase
}',
'error_message' => 'ReservedWord',
],
'disallowReturningExplicitVoid' => [
'<?php
function returnsVoid() : void {}
function alsoReturnsVoid() : void {
return returnsVoid();
}',
'error_message' => 'InvalidReturnStatement',
],
];
}
}