Skip to content
Permalink
Browse files

Allow explicitly-annotated mixed assignments (#2030)

This change makes it possible to assign mixed expressions to variables
if an annotation is explicitly added to the variable. This allows the
use of `call_user_func` without needing to suppress issues.

Fixes: #1374
  • Loading branch information...
lhchavez authored and muglug committed Aug 17, 2019
1 parent ac73546 commit c98c16090749aac83f8398409d86a0c22948c2b5
@@ -1162,7 +1162,8 @@ function foo(array $a, array $b) : void {

### MixedAssignment

Emitted when assigning a variable to a value for which Psalm cannot infer a type
Emitted when assigning an unannotated variable to a value for which Psalm
cannot infer a type more specific than `mixed`.

```php
$a = $_GET['foo'];
@@ -1173,7 +1174,7 @@ $a = $_GET['foo'];
Emitted when calling a function on a value whose type Psalm cannot infer.

```php
/** @psalm-suppress MixedAssignment */
/** @var mixed */
$a = $_GET['foo'];
$a();
```
@@ -254,6 +254,7 @@ public static function analyze(
if (!$assign_var instanceof PhpParser\Node\Expr\PropertyFetch
&& !strpos($root_var_id ?? '', '->')
&& !$comment_type
) {
if (IssueBuffer::accepts(
new MixedAssignment(
@@ -51,6 +51,13 @@ function foo2(?string &$u, ?string &$v): void {}
echo $foo;
}',
],
'explicitlyTypedMixedAssignment' => [
'<?php
/** @var mixed */
$a = 5;
/** @var mixed */
$b = $a;',
],
];
}

0 comments on commit c98c160

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