Open
Description
global $x;
'@phan-var array{k?:1} $x';
'@phan-debug-var $x'; // array{k?:1}
$x += [ 'k' => 2 ];
'@phan-debug-var $x'; // array{k?:1}
There are two problems here:
- the
k
key should not be optional anymore; - the type of the
k
field should be the union of the values of the two inputs of the+=
operator.
So the correct union type would be array{k:1|2}
.
The first is the more annoying issue as this is a very common pattern:
/**
* @param array $options An associative array of:
* - bar (bool, default false): ...
* @phan-param array{bar?:bool}
*/
function foo( array $options = [] ) {
$options += [
'bar' => false,
];
if ( $options['bar'] ) ...
}
but it will trigger a PhanTypePossiblyInvalidDimOffset
.
The snippets here were tested on https://phan.github.io/demo (Phan 5.4.1), the problem was originally seen in MediaWiki CI (5.4.3).
Metadata
Metadata
Assignees
Labels
No labels