Skip to content
Permalink
Browse files

Fixed #1848 - allow static class strings to be compared

  • Loading branch information...
muglug committed Jun 26, 2019
1 parent 372a512 commit 5ed49c0c0374a605e0d50f03ae40e13c9e29f3e0
@@ -172,7 +172,13 @@ public static function analyzeClassConst(
}
}
$stmt->inferredType = Type::getLiteralClassString($fq_class_name);
if ($first_part_lc === 'static') {
$stmt->inferredType = new Type\Union([
new Type\Atomic\TClassString($fq_class_name, new Type\Atomic\TNamedObject($fq_class_name))
]);
} else {
$stmt->inferredType = Type::getLiteralClassString($fq_class_name);
}
if ($codebase->store_node_types) {
$codebase->analyzer->addNodeReference(
@@ -249,6 +249,7 @@ public static function reconcileKeyedTypes(
&& !$result_type->hasTemplate()
&& !$result_type->hasType('iterable')
&& (!$has_isset || substr($key, -1, 1) !== ']')
&& !($statements_analyzer->getSource()->getSource() instanceof TraitAnalyzer)
) {
$reconcile_key = implode(
'&',
@@ -1307,6 +1308,9 @@ function (Type\Union $t) {
&& $new_type->getId() === $existing_var_type->getId()
&& !$is_equality
&& !$is_maybe_callable_array
&& (!($statements_analyzer->getSource()->getSource() instanceof TraitAnalyzer)
|| ($key !== '$this'
&& !($existing_var_type->hasLiteralClassString() && $new_type->hasLiteralClassString())))
) {
self::triggerIssueForImpossible(
$existing_var_type,
@@ -1358,8 +1362,9 @@ function (Type\Union $t) {
// fall through
}
}
} elseif ($key !== '$this'
|| !($statements_analyzer->getSource()->getSource() instanceof TraitAnalyzer)
} elseif (!($statements_analyzer->getSource()->getSource() instanceof TraitAnalyzer)
|| ($key !== '$this'
&& !($existing_var_type->hasLiteralClassString() && $new_type->hasLiteralClassString()))
) {
if ($existing_var_type->from_docblock) {
if (IssueBuffer::accepts(
@@ -657,6 +657,14 @@ public function hasString()
|| $this->typed_class_strings;
}
/**
* @return bool
*/
public function hasLiteralClassString()
{
return count($this->typed_class_strings) > 0;
}
/**
* @return bool
*/
@@ -1591,7 +1591,7 @@ function foo() {}',
*/
function f($reference) {}',
'error_message' => 'MissingDocblockType'
]
],
];
}
}
@@ -591,6 +591,18 @@ public function __construct() {
}
}'
],
'allowComparisonToStaticClassString' => [
'<?php
class A {
const CLASSES = ["foobar" => B::class];
function foo(): bool {
return self::CLASSES["foobar"] === static::class;
}
}
class B extends A {}'
],
];
}

0 comments on commit 5ed49c0

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