Skip to content

Constant enumeration does not throw an error if no constant is defined #11552

@Wulfheart

Description

@Wulfheart

Bug report

Given the following code:

<?php declare(strict_types = 1);

/**
 * @template TSuccess
 * @template TError
 * @phpstan-consistent-constructor
 */
class Result
{
	public function __construct(){}
	
    /**
     * @param TError $error
     * @return static
     */
    public static function err(mixed $error): static
    {
        return new static();
    }
}

/**
 * @extends Result<void, SomeResult::*>
 */
class SomeResult extends Result{

}

SomeResult::err('This should be an error');

class Constants {
	// No constants here defined (yet)
}

/**
 * @param Constants::* $f
 */
function f(mixed $f): void {}

I get the error message PHPDoc tag @param for parameter $f contains unresolvable type..

Code snippet that reproduces the problem

https://phpstan.org/r/943a8f8a-29e1-47f6-93be-b3b8030bb49b

Expected output

I would expect there to have some consistency. In line 29 I would also expect to get a message that the param is not resolvable. Especially because it displays an error for line 29 if a constant on SomeResult is defined.

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

This tool makes PHP development so much easier imo, great work!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions