Skip to content

Commit

Permalink
Use more accurate type for large arraya
Browse files Browse the repository at this point in the history
Fixes #2690
  • Loading branch information
muglug committed Jan 25, 2020
1 parent c3a989f commit 8c89760
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/Psalm/Internal/Analyzer/StatementsAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1849,10 +1849,6 @@ public static function getSimpleType(
$item_key_type = Type::getInt();
}

if ($item_value_type && !$can_create_objectlike) {
continue;
}

$single_item_value_type = self::getSimpleType(
$codebase,
$nodes,
Expand Down
73 changes: 73 additions & 0 deletions tests/ConstantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,79 @@ function test($value): void {
const FOO = 1;
echo \constant("FOO");'
],
'tooLongClassConstArray' => [
'<?php
class MyTest {
const LOOKUP = [
"A00" => null,
"A01" => null,
"A02" => null,
"A03" => null,
"A04" => null,
"A05" => null,
"A06" => null,
"A07" => null,
"A010" => null,
"A011" => null,
"A012" => null,
"A013" => null,
"A014" => null,
"A015" => null,
"A016" => null,
"A017" => null,
"A020" => null,
"A021" => null,
"A022" => null,
"A023" => null,
"A024" => null,
"A025" => null,
"A026" => null,
"A027" => null,
"A030" => null,
"A031" => null,
"A032" => null,
"A033" => null,
"A034" => null,
"A035" => null,
"A036" => null,
"A037" => null,
"A040" => null,
"A041" => null,
"A042" => null,
"A043" => null,
"A044" => null,
"A045" => null,
"A046" => null,
"A047" => null,
"A050" => null,
"A051" => null,
"A052" => null,
"A053" => null,
"A054" => null,
"A055" => null,
"A056" => null,
"A057" => null,
"A060" => null,
"A061" => null,
"A062" => null,
"A063" => null,
"A064" => self::SUCCEED,
"A065" => self::FAIL,
];
const SUCCEED = "SUCCEED";
const FAIL = "FAIL";
/**
* @param string $code
*/
public static function will_succeed($code) : bool {
// False positive TypeDoesNotContainType - string(SUCCEED) cannot be identical to null
// This seems to happen because the array has a lot of entries.
return (self::LOOKUP[strtoupper($code)] ?? null) === self::SUCCEED;
}
}'
],
];
}

Expand Down

0 comments on commit 8c89760

Please sign in to comment.