Skip to content

Commit

Permalink
Actualize after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
klimick committed Apr 27, 2024
1 parent f8fdd55 commit d6cf068
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ public static function analyzeAssignmentRef(
Context $context,
?PhpParser\Node\Stmt $from_stmt,
): bool {
ExpressionAnalyzer::analyze($statements_analyzer, $stmt->expr, $context, false, null, false, true);
ExpressionAnalyzer::analyze($statements_analyzer, $stmt->expr, $context, false, null, null, true);

$lhs_var_id = ExpressionIdentifier::getExtendedVarId(
$stmt->var,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static function extract(

private static function getReturnTypeFromDeclaringConstructor(
Codebase $codebase,
FunctionLikeStorage $ctor_storage
FunctionLikeStorage $ctor_storage,
): ?Union {
if ($ctor_storage instanceof MethodStorage
&& $ctor_storage->cased_name === '__construct'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,19 @@ public static function fetch(
$method_name = $method_id->method_name;

$class_storage = $codebase->methods->getClassLikeStorageForMethod($method_id);
$method_storage = ($class_storage->methods[$method_id->method_name] ?? null);

if ($stmt->isFirstClassCallable()) {
$closure = $codebase->methods->getStorage($declaring_method_id ?? $method_id)->toAnonymous(
$codebase,
true,
TClosure::class,
$lhs_type_part,
$context->getPossibleTemplateDefiners(),
);
if ($method_storage) {
return new Union([new TClosure(
'Closure',
$method_storage->params,
$method_storage->return_type,
$method_storage->pure,
)]);
}

return new Union([$closure]);
return Type::getClosure();
}

if ($codebase->methods->return_type_provider->has($premixin_method_id->fq_class_name)) {
Expand Down
22 changes: 22 additions & 0 deletions src/Psalm/Storage/ClassLikeStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Psalm\Internal\Type\TypeAlias\ClassTypeAlias;
use Psalm\Issue\CodeIssue;
use Psalm\Issue\DeprecatedClass;
use Psalm\Type\Atomic\TGenericObject;
use Psalm\Type\Atomic\TNamedObject;
use Psalm\Type\Atomic\TTemplateParam;
use Psalm\Type\Union;
Expand Down Expand Up @@ -477,4 +478,25 @@ public function getSuppressedIssuesForTemplateExtendParams(): array
}
return $suppressed_issues_for_template_extend_params;
}

public function getNamedObjectAtomic(): ?TNamedObject
{
if ($this->is_enum || $this->is_trait) {
return null;
}

$type_params = [];

foreach ($this->template_types ?? [] as $param_name => $type_map) {
foreach ($type_map as $defining_class => $extends) {
$type_params[] = new Union([
new TTemplateParam($param_name, $extends, $defining_class),
]);
}
}

return $type_params !== []
? new TGenericObject($this->name, $type_params)
: new TNamedObject($this->name);
}
}

0 comments on commit d6cf068

Please sign in to comment.