Skip to content

Template psalm-throws #3784

@adrianpanicek

Description

@adrianpanicek

I could not find any similar issue. I have a usecase

<?php
/**
 * @template T
 *
 * @psalm-param string|null $nullable
 * @psalm-param T $exception
 *
 * @psalm-throws T
 */
function expect(?string $nullable, Exception $exception) 
{
    if ($nullable === null) {
    	throw $exception;
    }
    
    return $nullable;
}
expect('test', new RuntimeException('Test is null'));

My proposal:

@psalm-throws should take generic parameter same as @psalm-param or @psalm-var.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions