Skip to content

PHPDoc inline in new anonymous class creation causes Internal Error #3661

@dbrekelmans

Description

@dbrekelmans

Bug report

PHPDoc inline in new anonymous class creation causes Internal Error.

The use-case is adding a @psalm-immutable annotation to an anonymous class extending an immutable class as is described in the psalm documentation: https://psalm.dev/docs/annotating_code/supported_annotations/#psalm-immutable.

/** @psalm-immutable */
abstract class Foo {
}

new /** @psalm-immutable */ class extends Foo {
};

Using the --debug option prints:

PHP Fatal error:  Uncaught PHPStan\ShouldNotHappenException: Internal error. in phar:///application/vendor/phpstan/phpstan/phpstan/src/Rules/Generics/ClassTemplateTypeRule.php:36

Code snippet that reproduces the problem

https://phpstan.org/r/6a77347f-d037-4793-a23a-a477f4b110c7

Expected output

No errors!

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