Skip to content
Permalink
Browse files

Fix #2083 - don’t bludgeon method_exists first type

  • Loading branch information...
muglug committed Aug 29, 2019
1 parent 22ba3ad commit 9bd7f21a9d946e038dd00c1edb52e9044081b50f
Showing with 33 additions and 1 deletion.
  1. +1 −1 src/Psalm/Internal/CallMap.php
  2. +4 −0 src/Psalm/Internal/Type/AssertionReconciler.php
  3. +28 −0 tests/MethodCallTest.php
@@ -7372,7 +7372,7 @@
'MessageFormatter::parseMessage' => ['array|false', 'locale'=>'string', 'pattern'=>'string', 'source'=>'string'],
'MessageFormatter::setPattern' => ['bool', 'pattern'=>'string'],
'metaphone' => ['string|false', 'text'=>'string', 'phones='=>'int'],
'method_exists' => ['bool', 'object'=>'object|string', 'method'=>'string'],
'method_exists' => ['bool', 'object'=>'object|class-string', 'method'=>'string'],
'mhash' => ['string', 'hash'=>'int', 'data'=>'string', 'key='=>'string'],
'mhash_count' => ['int'],
'mhash_get_block_size' => ['int|false', 'hash'=>'int'],
@@ -862,6 +862,10 @@ private static function reconcileHasMethod(
[$method_name => 'object::' . $method_name]
);
$did_remove_type = true;
} elseif ($type instanceof TString) {
// we don’t know
$object_types[] = $type;
$did_remove_type = true;
} elseif ($type instanceof TTemplateParam) {
$object_types[] = $type;
$did_remove_type = true;
@@ -398,6 +398,34 @@ function foo(A $object) : void {
}
}'
],
'preserveMethodExistsType' => [
'<?php
/**
* @param class-string $foo
*/
function foo(string $foo): string {
if (!method_exists($foo, "something")) {
return "";
}
return $foo;
}'
],
'methodDoesNotExistOnClass' => [
'<?php
class A {}
/**
* @param class-string<A> $foo
*/
function foo(string $foo): string {
if (!method_exists($foo, "something")) {
return "";
}
return $foo;
}'
],
];
}

0 comments on commit 9bd7f21

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