Skip to content

collector generics loose precision #8127

@staabm

Description

@staabm

Bug report

it seems the generic type of a collector is loosing precision..?

Code snippet that reproduces the problem

collector

/**
 * @implements Collector<CallLike, array{string, TaintType::TYPE_*, string, int}>
 */
final class SinkCollector implements Collector
{
    public function getNodeType(): string
    {
        return CallLike::class;
    }

    public function processNode(Node $node, Scope $scope)
    {}
}

/**
 * @psalm-immutable
 */
final class TaintType
{
    public const TYPE_INPUT = 'input';
    public const TYPE_SQL = 'sql';
    public const TYPE_HTML = 'html';

    public const TYPES = [self::TYPE_INPUT, self::TYPE_SQL, self::TYPE_HTML];
}

rule

/**
 * @implements Rule<CollectedDataNode>
 */
final class TaintRule implements Rule
{
    public function getNodeType(): string
    {
        return CollectedDataNode::class;
    }

    public function processNode(Node $node, Scope $scope): array
    {
        $sinkCollectorData = $node->get(SinkCollector::class);
        dumpType($sinkCollectorData);
       // actual: Dumped type: array<string, array<int, array{string, string, string, int}>> 
      // expected Dumped type: array<string, array<int, array{string, TaintType::TYPE_*,, string, int}>> 
    }
}

https://phpstan.org/r/72a1ea44-59e0-41c2-af31-11eeb6723b37

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions