Skip to content

Commit

Permalink
add test case reproducing issue vimeo#7428
Browse files Browse the repository at this point in the history
  • Loading branch information
hirokinoue committed Sep 17, 2022
1 parent 9ed9c4b commit a2118c6
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/TypeReconciliation/ArrayKeyExistsTest.php
Expand Up @@ -2,6 +2,8 @@

namespace Psalm\Tests\TypeReconciliation;

use Psalm\Config;
use Psalm\Context;
use Psalm\Tests\TestCase;
use Psalm\Tests\Traits\InvalidCodeAnalysisTestTrait;
use Psalm\Tests\Traits\ValidCodeAnalysisTestTrait;
Expand Down Expand Up @@ -430,4 +432,31 @@ function go(array $options): void {
],
];
}

public function testAllowPropertyFetchAsNeedle(): void
{
Config::getInstance()->ensure_array_int_offsets_exist = true;

$this->addFile(
'somefile.php',
'<?php
class Foo {
/** @var self::STATE_* $status */
public int $status = self::STATE_A;
public const STATE_A = 0;
public const STATE_B = 1;
}
$foo = new Foo;
/** @var array<string> $bar */
$bar = [];
if (array_key_exists($foo->status, $bar)) {
echo $bar[$foo->status];
}'
);

$this->analyzeFile('somefile.php', new Context());
}
}

0 comments on commit a2118c6

Please sign in to comment.