-
Notifications
You must be signed in to change notification settings - Fork 493
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix array dim fetches with treatPhpDocTypesAsCertain: false
- Loading branch information
1 parent
43fca8d
commit a9ec174
Showing
3 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Bug4099; | ||
|
||
use function PHPStan\Analyser\assertNativeType; | ||
use function PHPStan\Analyser\assertType; | ||
|
||
class Foo | ||
{ | ||
|
||
/** | ||
* @param array{key: array{inner: mixed}} $arr | ||
*/ | ||
function arrayHint(array $arr): void | ||
{ | ||
assertType('array(\'key\' => array(\'inner\' => mixed))', $arr); | ||
assertNativeType('array', $arr); | ||
|
||
if (!array_key_exists('key', $arr)) { | ||
assertType('*NEVER*', $arr); | ||
assertNativeType('array', $arr); | ||
throw new \Exception('no key "key" found.'); | ||
} | ||
assertType('array(\'key\' => array(\'inner\' => mixed))', $arr); | ||
assertNativeType('array&hasOffset(\'key\')', $arr); | ||
assertType('array(\'inner\' => mixed)', $arr['key']); | ||
assertNativeType('mixed', $arr['key']); | ||
|
||
if (!array_key_exists('inner', $arr['key'])) { | ||
assertType('array(\'key\' => *NEVER*)', $arr); | ||
//assertNativeType('array(\'key\' => mixed)', $arr); | ||
assertType('*NEVER*', $arr['key']); | ||
//assertNativeType('mixed', $arr['key']); | ||
throw new \Exception('need key.inner'); | ||
} | ||
|
||
assertType('array(\'key\' => array(\'inner\' => mixed))', $arr); | ||
assertNativeType('array(\'key\' => array(\'inner\' => mixed))', $arr); | ||
} | ||
|
||
} |