Skip to content

Literal string array keys incorrectly cause error that makes no sense and wrong tag? #264

@kkmuffme

Description

@kkmuffme
/**
 * foo
 *
 * @param array<'hello'|int, string> $a xyz
 */

is an InvalidTag of type method (?) with message

An array can have only integers or strings as keys

Works fine in phpstan https://phpstan.org/r/7a29b6c5-52de-4762-aa0a-2e03deb5acaf (and has worked fine in v1 since ages too)

Trace:

    ["trace":"Exception":private]=>
    array(11) {
      [0]=>
      array(6) {
        ["file"]=>
        string(125) "/path/to/vendor/phpdocumentor/type-resolver/src/TypeResolver.php"
        ["line"]=>
        int(393)
        ["function"]=>
        string(11) "createArray"
        ["class"]=>
        string(37) "phpDocumentor\Reflection\TypeResolver"
        ["type"]=>
        string(2) "->"
        ["args"]=>
        array(2) {
          [0]=>
          array(2) {
            [0]=>
            string(51) "object(PHPStan\PhpDocParser\Ast\Type\UnionTypeNode)"
            [1]=>
            string(56) "object(PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode)"
          }
          [1]=>
          string(46) "object(phpDocumentor\Reflection\Types\Context)"
        }
      }
      [1]=>
      array(6) {
        ["file"]=>
        string(125) "/path/to/vendor/phpdocumentor/type-resolver/src/TypeResolver.php"
        ["line"]=>
        int(313)
        ["function"]=>
        string(17) "createFromGeneric"
        ["class"]=>
        string(37) "phpDocumentor\Reflection\TypeResolver"
        ["type"]=>
        string(2) "->"
        ["args"]=>
        array(2) {
          [0]=>
          string(53) "object(PHPStan\PhpDocParser\Ast\Type\GenericTypeNode)"
          [1]=>
          string(46) "object(phpDocumentor\Reflection\Types\Context)"
        }
      }
      [2]=>
      array(6) {
        ["file"]=>
        string(153) "/path/to/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/ParamFactory.php"
        ["line"]=>
        int(79)
        ["function"]=>
        string(10) "createType"
        ["class"]=>
        string(37) "phpDocumentor\Reflection\TypeResolver"
        ["type"]=>
        string(2) "->"
        ["args"]=>
        array(2) {
          [0]=>
          string(53) "object(PHPStan\PhpDocParser\Ast\Type\GenericTypeNode)"
          [1]=>
          string(46) "object(phpDocumentor\Reflection\Types\Context)"
        }
      }
      [3]=>
      array(6) {
        ["file"]=>
        string(163) "/path/to/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php"
        ["line"]=>
        int(92)
        ["function"]=>
        string(6) "create"
        ["class"]=>
        string(59) "phpDocumentor\Reflection\DocBlock\Tags\Factory\ParamFactory"
        ["type"]=>
        string(2) "->"
        ["args"]=>
        array(2) {
          [0]=>
          string(53) "object(PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode)"
          [1]=>
          string(46) "object(phpDocumentor\Reflection\Types\Context)"
        }
      }
      [4]=>
      array(6) {
        ["file"]=>
        string(146) "/path/to/vendor/phpdocumentor/reflection-docblock/src/DocBlock/StandardTagFactory.php"
        ["line"]=>
        int(230)
        ["function"]=>
        string(6) "create"
        ["class"]=>
        string(69) "phpDocumentor\Reflection\DocBlock\Tags\Factory\AbstractPHPStanFactory"
        ["type"]=>
        string(2) "->"
        ["args"]=>
        array(2) {
          [0]=>
          string(57) "@param array<'hello'|int, string> $a xyz"
          [1]=>
          string(46) "object(phpDocumentor\Reflection\Types\Context)"
        }
      }
      [5]=>
      array(6) {
        ["file"]=>
        string(146) "/path/to/vendor/phpdocumentor/reflection-docblock/src/DocBlock/StandardTagFactory.php"
        ["line"]=>
        int(155)
        ["function"]=>
        string(9) "createTag"
        ["class"]=>
        string(52) "phpDocumentor\Reflection\DocBlock\StandardTagFactory"
        ["type"]=>
        string(2) "->"
        ["args"]=>
        array(3) {
          [0]=>
          string(50) "array<'hello'|int, string> $a xyz"
          [1]=>
          string(5) "param"
          [2]=>
          string(46) "object(phpDocumentor\Reflection\Types\Context)"
        }
      }
      [6]=>
      array(6) {
        ["file"]=>
        string(134) "/path/to/vendor/phpdocumentor/reflection-docblock/src/DocBlockFactory.php"
        ["line"]=>
        int(286)
        ["function"]=>
        string(6) "create"
        ["class"]=>
        string(52) "phpDocumentor\Reflection\DocBlock\StandardTagFactory"
        ["type"]=>
        string(2) "->"
        ["args"]=>
        array(2) {
          [0]=>
          string(57) "@param array<'hello'|int, string> $a xyz"
          [1]=>
          string(46) "object(phpDocumentor\Reflection\Types\Context)"
        }
      }
      [7]=>
      array(6) {
        ["file"]=>
        string(134) "/path/to/vendor/phpdocumentor/reflection-docblock/src/DocBlockFactory.php"
        ["line"]=>
        int(145)
        ["function"]=>
        string(13) "parseTagBlock"
        ["class"]=>
        string(40) "phpDocumentor\Reflection\DocBlockFactory"
        ["type"]=>
        string(2) "->"
        ["args"]=>
        array(2) {
          [0]=>
          string(57) "@param array<'hello'|int, string> $a xyz"
          [1]=>
          string(46) "object(phpDocumentor\Reflection\Types\Context)"
        }
      }

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