8000 Lower & upper bounds of templates should be retained · Issue #3084 · vimeo/psalm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Lower & upper bounds of templates should be retained #3084

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

Closed
muglug opened this issue Apr 6, 2020 · 1 comment
Closed

Lower & upper bounds of templates should be retained #3084

muglug opened this issue Apr 6, 2020 · 1 comment
Labels

Comments

@muglug
Copy link
Collaborator
muglug commented Apr 6, 2020

Here the correct behaviour is to treat closure param types as a lower bound on the templated type, and to treat anything outside as an upper bound.

/**
 * @template T
 * @param class-string<T> $className
 * @param Closure(T):void $outmaker
 * @return T
 */
function createProxy(
    string $className,
    Closure $outmaker
) : object {
    $t = new $className();
    $outmaker($t);
    return $t;
}

class A {
    public function bar() : void {}
}

createProxy(A::class, function(object $o):void {})->bar();

Expected: no issue
Actual: inference of createProxy call fails: https://psalm.dev/r/dfc10a8bde

cc @Ocramius

@muglug muglug added the bug label Apr 6, 2020
@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/dfc10a8bde
<?php

/**
 * @template T
 * @param class-string<T> $className
 * @param Closure(T):void $outmaker
 * @return T
 */
function createProxy(
    string $className,
    Closure $outmaker
) : object {
   	$t = new $className();
    $outmaker($t);
    return $t;
}

class A {
    public function bar() : void {}
}

createProxy(A::class, function(object $o):void {})->bar();
Psalm output (using commit 11edb22):

INFO: MixedMethodCall - 22:53 - Cannot determine the type of the object on the left hand side of this expression

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

No branches or pull requests

1 participant
0