Skip to content

Commit

Permalink
Negated class_exist check on class-string converts to string instead …
Browse files Browse the repository at this point in the history
…of mixed
  • Loading branch information
robchett committed Oct 8, 2023
1 parent 69d5881 commit c729fcd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Psalm/Internal/Type/NegatedAssertionReconciler.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ public static function reconcile(
$existing_var_type->removeType('array');
}

if ($assertion instanceof IsNotType && $assertion_type instanceof TClassString) {
$existing_var_type->removeType(TClassString::class);
$existing_var_type->addType(new TString);
}

if (!$is_equality
&& isset($existing_var_atomic_types['int'])
&& $existing_var_type->from_calculation
Expand Down
12 changes: 12 additions & 0 deletions tests/ClassLikeStringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,18 @@ class A {}
new \RuntimeException();
}',
],
'convertToStringClassExistsNegated' => [
'code' => '<?php
/** @param class-string $className */
$className = stdClass::class;
if (class_exists($className)) {
throw new \RuntimeException($className);
}',
'assertions' => [
'$className===' => 'string',
],

],
'createNewObjectFromGetClass' => [
'code' => '<?php
/**
Expand Down

0 comments on commit c729fcd

Please sign in to comment.