Skip to content

Instantly share code, notes, and snippets.

@dasl-
Created August 5, 2024 22:31
Show Gist options
  • Save dasl-/c0187c3602fb0caa8afb34324e3f90c5 to your computer and use it in GitHub Desktop.
Save dasl-/c0187c3602fb0caa8afb34324e3f90c5 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..2f02e2619 100644
--- a/src/Phan/Analysis/PostOrderAnalysisVisitor.php
+++ b/src/Phan/Analysis/PostOrderAnalysisVisitor.php
@@ -1632,6 +1632,7 @@ class PostOrderAnalysisVisitor extends AnalysisVisitor
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
+ // TODO: this check could be performed outside the for loop? more efficient.
if ($method_return_type->isEmpty()
|| $method->isReturnTypeUndefined()
) {
@@ -1641,11 +1642,11 @@ class PostOrderAnalysisVisitor extends AnalysisVisitor
// 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;
+ // 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.
@@ -1664,7 +1665,7 @@ class PostOrderAnalysisVisitor extends AnalysisVisitor
// For functions that aren't syntactically Generators,
// update the set/existence of return values.
- if ($method->isReturnTypeModifiable() && !$is_mismatch) {
+ if (($method->isReturnTypeModifiable() && !$is_mismatch) || !$method->hasDependentReturnType()) {
// Add the new type to the set of values returned by the
// method
$method->setUnionType($method->getUnionType()->withUnionType($expression_type));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment