Skip to content

Type error in "RemoveParentDelegatingConstructorRector::matchParentConstructorCallArgs" in a combination with a large PhpSet #9577

@raneomik

Description

@raneomik

Bug Report

Hello, I just bumped on this Rector run Fail :

{ "totals": { "changed_files": 0, "errors": 1 }, "errors": [ { "message": "System error: \"Rector\\DeadCode\\Rector\\ClassMethod\\RemoveParentDelegatingConstructorRector::matchParentConstructorCallArgs(): Argument #1 ($stmt) must be of type PhpParser\\Node\\Stmt, null given, called in /var/www/vendor/rector/rector/rules/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector.php on line 100\"\nRun Rector with \"--debug\" option and post the report here: https://github.com/rectorphp/rector/issues/new", "file": "/var/www/storage/demo/gq7sfvrntg1nlbi31c2q/rector_analyzed_file.php", "line": 135 } ] }
Subject Details
Rector version last dev-main
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.com/demo/bbd24251-be91-4fc8-ab5d-08dbd5d6619b

<?php

class A 
{
    public function __construct()
    {
        $this->init();
    }
    
    private function init(): void
    {
		echo 'A init';
    }
}

final class B extends A
{
    private string $prop;
    
    public function __construct(string $prop) 
    {
        $this->prop = $prop;
        parent::__construct();
    }
    
    public function prop(): string
    {
        return $this->prop;
    }    
}

Responsible minimal config

<?php

use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\ClassMethod\RemoveParentDelegatingConstructorRector;
use Rector\ValueObject\PhpVersion;

return RectorConfig::configure()
    ->withPhpSets(php83: true)
    ->withRules([
        RemoveParentDelegatingConstructorRector::class,
    ])
;

Expected Behaviour

No error and maybe a fix proposal similiar to this ? :

final class B extends A
{
    public function __construct(private string $prop) 
    {
        parent::__construct();
    }
    
    public function prop(): string
    {
        return $this->prop;
    }    
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions