Skip to content
Permalink
Browse files

Fix #2046 - trigger PossiblyNullArgument when in union with mixed

  • Loading branch information...
muglug committed Aug 23, 2019
1 parent 5a1604d commit 738ba81185abbdd25d5e99940080c2f713ec1da1
@@ -83,6 +83,10 @@ public static function analyze(
$context->inside_call = true;
if (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->name, $context) === false) {
if (!$was_in_call) {
$context->inside_call = false;
}
return;
}
@@ -2335,20 +2335,22 @@ public static function checkFunctionArgumentType(
// fall through
}
if (!$function_param->by_ref
&& !($function_param->is_variadic xor $unpack)
&& $cased_method_id !== 'echo'
) {
self::coerceValueAfterGatekeeperArgument(
$statements_analyzer,
$input_type,
false,
$input_expr,
$param_type,
$signature_param_type,
$context,
$unpack
);
if ($input_type->isMixed()) {
if (!$function_param->by_ref
&& !($function_param->is_variadic xor $unpack)
&& $cased_method_id !== 'echo'
) {
self::coerceValueAfterGatekeeperArgument(
$statements_analyzer,
$input_type,
false,
$input_expr,
$param_type,
$signature_param_type,
$context,
$unpack
);
}
}
if ($cased_method_id) {
@@ -2364,7 +2366,9 @@ public static function checkFunctionArgumentType(
);
}
return null;
if ($input_type->isMixed()) {
return null;
}
}
if ($input_type->isNever()) {
@@ -2482,7 +2486,7 @@ public static function checkFunctionArgumentType(
}
}
if ($union_comparison_results->type_coerced) {
if ($union_comparison_results->type_coerced && !$input_type->hasMixed()) {
if ($union_comparison_results->type_coerced_from_mixed) {
if (IssueBuffer::accepts(
new MixedArgumentTypeCoercion(
@@ -2747,7 +2751,7 @@ public static function checkFunctionArgumentType(
}
}
if ($type_match_found
if (($type_match_found || $input_type->hasMixed())
&& !$function_param->by_ref
&& !($function_param->is_variadic xor $unpack)
&& $cased_method_id !== 'echo'
@@ -380,7 +380,7 @@ function foo() : void {
'issetOnArrayAccess' => [
'<?php
function foo(ArrayAccess $arr) : void {
$a = isset($arr["a"]) ? $arr["a"] : "a";
$a = isset($arr["a"]) ? $arr["a"] : 4;
takesInt($a);
}
function takesInt(int $i) : void {}',
@@ -683,6 +683,26 @@ function foo(A $a) : void {
}',
'error_message' => 'RedundantCondition',
],
'possiblyNullOrMixedArg' => [
'<?php
class A {
/**
* @var mixed
*/
public $foo;
}
function takesString(string $s) : void {}
function takesA(?A $a) : void {
/**
* @psalm-suppress PossiblyNullPropertyFetch
* @psalm-suppress MixedArgument
*/
takesString($a->foo);
}',
'error_message' => 'PossiblyNullArgument',
],
];
}
}

0 comments on commit 738ba81

Please sign in to comment.
You can’t perform that action at this time.