Skip to content

Instantly share code, notes, and snippets.

@dasl-
Created November 6, 2023 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dasl-/12fe1fa8322c4bc8b9b551de3102d960 to your computer and use it in GitHub Desktop.
Save dasl-/12fe1fa8322c4bc8b9b551de3102d960 to your computer and use it in GitHub Desktop.
diff --git a/src/Phan/Analysis/PostOrderAnalysisVisitor.php b/src/Phan/Analysis/PostOrderAnalysisVisitor.php
index a7557675d..1d51b9c63 100644
--- a/src/Phan/Analysis/PostOrderAnalysisVisitor.php
+++ b/src/Phan/Analysis/PostOrderAnalysisVisitor.php
@@ -1621,31 +1621,31 @@ class PostOrderAnalysisVisitor extends AnalysisVisitor
// Check for failing to return a value, or returning a value in a void method.
if ($method_return_type->hasRealTypeSet()) {
if (!$this->checkIsValidReturnExpressionForType($node, $method_return_type->asRealUnionType(), $method)) {
return $context;
}
}
// This leaves functions which aren't syntactically generators.
// Figure out what is actually being returned
// TODO: Properly check return values of array shapes
foreach ($this->getReturnTypes($context, $expr, $node->lineno) as $lineno => [$expression_type, $inner_node]) {
// If there is no declared type, see if we can deduce
// what it should be based on the return type
if ($method_return_type->isEmpty()
- || $method->isReturnTypeUndefined()
+ || $method->isReturnTypeUndefined() || true // see config: allow_overriding_vague_return_types
) {
if (!$is_trait) {
$method->setIsReturnTypeUndefined(true);
// Set the inferred type of the method based
// on what we're returning
$method->setUnionType($method->getUnionType()->withUnionType($expression_type));
}
// No point in comparing this type to the
// type we just set
continue;
}
// Check if the return type is compatible with the declared return type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment