Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variadic callables type checking failed #10065

Closed
klimick opened this issue Jul 29, 2023 · 2 comments · Fixed by #10066
Closed

Variadic callables type checking failed #10065

klimick opened this issue Jul 29, 2023 · 2 comments · Fixed by #10066

Comments

@klimick
Copy link
Contributor

klimick commented Jul 29, 2023

https://psalm.dev/r/579db4822c

Actually I already have a fix for this problem.
But I don't know which branch to open PR.
master? v5?

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/579db4822c
<?php

function withVariadicParam(int $a, int $b, int ...$rest): int
{
    throw new RuntimeException();
}

/** @param Closure(int, int): int $f */
function int_int(Closure $f): void {}

/** @param Closure(int, int, int): int $f */
function int_int_int(Closure $f): void {}

/** @param Closure(int, int, int, int): int $f */
function int_int_int_int(Closure $f): void {}

/** @param Closure(int, int, int, string): int $f */
function int_int_int_string(Closure $f): void {}

// false positive: expected no issues here
int_int(withVariadicParam(...));

// ok: but that's because the number of parameters are the same.
int_int_int(withVariadicParam(...));

// ok: but last param actually does not type checked.
int_int_int_int(withVariadicParam(...));

// false negative: expected issue here
int_int_int_string(withVariadicParam(...));
Psalm output (using commit 73ebe22):

ERROR: InvalidScalarArgument - 21:9 - Argument 1 of int_int expects Closure(int, int):int, but impure-Closure(int, int, int...):int provided

@orklah
Copy link
Collaborator

orklah commented Jul 29, 2023

You can target V5 as long as there's no BC break :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants