Skip to content

Commit

Permalink
Fix #2348 - ensure all functions and methods return some type
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Nov 14, 2019
1 parent b3a15e8 commit 5e17a9a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -918,6 +918,10 @@ function (array $_) : bool {
} }
} }


if (!isset($stmt->inferredType)) {
$stmt->inferredType = Type::getMixed();
}

return null; return null;
} }
} }
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1126,5 +1126,9 @@ function (Assertion $assertion) use ($generic_params) : Assertion {
if (!$config->remember_property_assignments_after_call && !$context->collect_initializations) { if (!$config->remember_property_assignments_after_call && !$context->collect_initializations) {
$context->removeAllObjectVars(); $context->removeAllObjectVars();
} }

if (!isset($stmt->inferredType)) {
$stmt->inferredType = Type::getMixed();
}
} }
} }
39 changes: 39 additions & 0 deletions tests/FunctionCallTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1172,6 +1172,45 @@ function strtr_wrapper($str, array $replace_pairs) {
array_intersect_key([], [], [], [], []);', array_intersect_key([], [], [], [], []);',
'assertions' => [], 'assertions' => [],
], ],
'arrayIntersectKeyNoReturnType' => [
'<?php
/**
* @psalm-suppress MissingReturnType
*/
function unknown() {
return ["x" => "hello"];
}
class C {
/**
* @psalm-suppress MissingReturnType
*/
public static function unknownStatic() {
return ["x" => "hello"];
}
/**
* @psalm-suppress MissingReturnType
*/
public static function unknownInstance() {
return ["x" => "hello"];
}
}
/**
* @psalm-suppress MixedArgument
*/
function sdn(array $s) : void {
$r = array_intersect_key(unknown(), array_filter($s));
if (empty($r)) {}
$r = array_intersect_key(C::unknownStatic(), array_filter($s));
if (empty($r)) {}
$r = array_intersect_key((new C)->unknownInstance(), array_filter($s));
if (empty($r)) {}
}',
],
'arrayReduce' => [ 'arrayReduce' => [
'<?php '<?php
$arr = [2, 3, 4, 5]; $arr = [2, 3, 4, 5];
Expand Down

0 comments on commit 5e17a9a

Please sign in to comment.