Skip to content

Error "Cannot create PHPStan\Type\UnionType" (when passing null default value to Union param without null) #7994

Description

@leoloso

Bug Report

Subject Details
Rector version 0.17.1

Running the downgrade set to PHP 7.1 produces an error when applied to symfony/config (I believe due to this code: function addDefaultChildrenIfNoneSet(int|string|array $children = null):

{
    "totals": {
        "changed_files": 0,
        "errors": 1
    },
    "errors": [
        {
            "message": "System error: \"Cannot create PHPStan\\Type\\UnionType with: array|int|string, null\"\nRun Rector with \"--debug\" option and post the report here: https://github.com/rectorphp/rector/issues/new",
            "file": "/var/www/src/../storage/demo/1mxy804ht13018nr24p6/rector_analyzed_file.php",
            "line": 64
        }
    ]
}

This started happening only with v0.17.1. I did the same test with v0.17.0, just changing this Rector library and nothing else (i.e. same PHPStan version), and it works well.

I also checked if PHPStan had a regression, but it works well there:

https://phpstan.org/r/4e928b42-bd06-46c3-943a-6f20fe559468

(Btw, this error happened in PHPStan in the past: https://phpstan.org/r/34941ef9b42e63d5cd9e86c4dff7e82a, but it's now been fixed)

Minimal PHP Code Causing Issue

https://getrector.com/demo/b70ea283-9b7a-4902-9605-b7d8142d6bf4

Expected Behaviour

No error! 😆

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    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