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:
parent
d440e4bbb1
commit
52c414f1d2
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -538,6 +538,15 @@ class ReturnTypeTest extends TestCase
|
||||
}',
|
||||
'error_message' => 'ReservedWord',
|
||||
],
|
||||
'disallowReturningExplicitVoid' => [
|
||||
'<?php
|
||||
function returnsVoid() : void {}
|
||||
|
||||
function alsoReturnsVoid() : void {
|
||||
return returnsVoid();
|
||||
}',
|
||||
'error_message' => 'InvalidReturnStatement',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user