Skip to content

Incorrect behavior of RestoreDefaultNullToNullableTypePropertyRector #7998

@simPod

Description

@simPod

Bug Report

Subject Details
Rector version last dev-main
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.com/demo/492d4ef9-bfd2-4a66-9f64-376697f98ad2

<?php

final readonly class A
{
    public B|null $display;

    public function __construct(
        string|null $display = null,
    ) {
        if ($display === null) {
            $this->display = null;
        } else {
            $this->display = $display;
        }
    }
}

Responsible rules

  • RestoreDefaultNullToNullableTypePropertyRector

Expected Behavior

  1. it shouldn't add default values to readonly properties https://3v4l.org/TLaUT#v8.2.7
  2. The property is initialized in constructor so it should't try to add a default value

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions