Skip to content

Internal error in FunctionCallParametersCheck on "new self(...$properties)" when child constructor has extra promoted parameter (bleedingEdge) #14715

@momala454

Description

@momala454

Bug report

PHPStan 2.2.0 crashes with an internal error in Rules/FunctionCallParametersCheck.php:155 when analysing a new self(...$properties) call in a child class whose constructor adds a promoted parameter on top of the parent's, and where $properties is built by iterating over the parent constructor's ReflectionMethod parameters.

The crash only occurs when bleedingEdge.neon is included. Without bleedingEdge, PHPStan reports a normal argument.type error and completes the analysis.

<?php
declare(strict_types=1);

class Event {
    public function __construct(public int $a) {}
}

class EventOutput extends Event {
    public function __construct(public int $a, public bool $b) {
        parent::__construct(a: $a);
    }

    public static function fromEvent(Event $event, bool $b): self
    {
        $properties = ['b' => $b];
        $construct = new \ReflectionMethod(Event::class, '__construct');
        foreach ($construct->getParameters() as $parameter) {
            $properties[$parameter->getName()] = $event->{$parameter->getName()};
        }

        return new self(...$properties);
    }
}

Stack trace (top frames)

## phar://.../vendor/phpstan/phpstan/phpstan.phar/src/Rules/FunctionCallParametersCheck.php(155)
#0 .../Rules/Classes/InstantiationRule.php(176): PHPStan\Rules\FunctionCallParametersCheck->check()
#1 .../Rules/Classes/InstantiationRule.php(78):  PHPStan\Rules\Classes\InstantiationRule->checkClassName()
#2 .../Analyser/FileAnalyserCallback.php(134):   PHPStan\Rules\Classes\InstantiationRule->processNode()
#3 .../Node/ClassStatementsGatherer.php(120):    PHPStan\Analyser\FileAnalyserCallback->__invoke()
#4 .../Analyser/NodeScopeResolver.php(771):      PHPStan\Node\ClassStatementsGatherer->__invoke()
...

Environment
PHPStan: 2.2.0
PHP: 8.x
Config: level: 10, bleedingEdge.neon included
The crash disappears when bleedingEdge.neon is removed.

includes:
    - phar://phpstan.phar/conf/bleedingEdge.neon
parameters:
    level: 10
    paths:
        - repro.php

Code snippet that reproduces the problem

https://phpstan.org/r/1b1462cc-ebcc-4d03-a897-2f3e33a7743b

Expected output

No crash

Did PHPStan help you today? Did it make you happy in any way?

Thanks for the update!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions