Skip to content

Nullable parent return type #5529

@samsonasik

Description

@samsonasik

Bug report

On PHPStan 0.12.96, given the following code:

class ParentClass
{}

class HelloWorld extends ParentClass
{
	public function run(): ?parent
	{
		if (rand(0,1)) {
			return $this;
		}
		
		return null;
	}
}

produce error:

Internal error: parent type is not supported here Run PHPStan with --debug option and post the stack trace to: https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md

ref https://phpstan.org/r/cde459ea-4602-4078-aef6-ac5fafe6eac1

Expected output

It should not error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions