Skip to content

Commit

Permalink
Fix #3600 - conditional return should be removed before comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Jun 17, 2020
1 parent 02b15b8 commit 0a8b9b5
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Psalm/Internal/Analyzer/MethodComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,18 @@ private static function compareMethodDocblockParams(
}
}

foreach ($guide_method_storage_param_type->getAtomicTypes() as $k => $t) {
if ($t instanceof Type\Atomic\TTemplateParam
&& \strpos($t->defining_class, 'fn-') === 0
) {
$guide_method_storage_param_type->removeType($k);

foreach ($t->as->getAtomicTypes() as $as_t) {
$guide_method_storage_param_type->addType($as_t);
}
}
}

$union_comparison_results = new TypeComparisonResult();

if (!TypeAnalyzer::isContainedBy(
Expand Down
39 changes: 39 additions & 0 deletions tests/Template/ConditionalReturnTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,45 @@ function bar(SerializerInterface $i, string $data): array {
return $i->deserialize($data, \'array\');
}'
],
'inheritConditional' => [
'<?php
/**
* @template E
*/
interface AInterface {
/**
* @template T
* @template T2 as "int"|class-string<T>
* @param T2 $type
* @return (T2 is "int" ? static<int> : static<T>)
*/
public static function ofType(string $type);
}
/**
* @template E
* @implements AInterface<E>
*/
class BClass implements AInterface {
protected string $type;
protected function __construct(string $type)
{
$this->type = $type;
}
/**
* @template T
* @template T2 as "int"|class-string<T>
* @param T2 $type
* @return (T2 is "int" ? static<int> : static<T>)
*/
public static function ofType(string $type) {
return new static($type);
}
}'
],
];
}
}

0 comments on commit 0a8b9b5

Please sign in to comment.