Skip to content
Permalink
Browse files

Fix class constant assertions on self/static

  • Loading branch information...
muglug committed May 27, 2019
1 parent c5e682d commit 518330dcf4d57908a9c82384a7ec988dec81b2d5
Showing with 25 additions and 2 deletions.
  1. +4 −0 src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php
  2. +21 −2 tests/ArrayAccessTest.php
@@ -948,6 +948,10 @@ public static function getArrayVarId(
$resolved_name = $stmt->class->getAttribute('resolvedName');
if ($resolved_name) {
if (($resolved_name === 'self' || $resolved_name === 'static') && $this_class_name) {
$resolved_name = $this_class_name;
}
return $resolved_name . '::' . $stmt->name;
}
}
@@ -441,7 +441,26 @@ public function offsetUnset($offset) : void
'<?php
["s" => "str"]["str"[0]];',
],
'assertConstantOffsets' => [
'assertConstantOffsetsInMethod' => [
'<?php
class C {
public const ARR = [
"a" => ["foo" => true],
"b" => []
];
public function bar(string $key): bool {
if (!array_key_exists($key, self::ARR) || !array_key_exists("foo", self::ARR[$key])) {
return false;
}
return self::ARR[$key]["foo"];
}
}',
[],
['MixedReturnStatement', 'MixedInferredReturnType']
],
'assertConstantOffsetsInFunction' => [
'<?php
class C {
public const ARR = [
@@ -451,7 +470,7 @@ class C {
}
function bar(string $key): bool {
if (!array_key_exists($key, C::ARR) || !array_key_exists(\'foo\', C::ARR[$key])) {
if (!array_key_exists($key, C::ARR) || !array_key_exists("foo", C::ARR[$key])) {
return false;
}

0 comments on commit 518330d

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