8000 'cannot reconcile upper and lower bound for template' message usability · Issue #3126 · vimeo/psalm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

'cannot reconcile upper and lower bound for template' message usability #3126

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
weirdan opened this issue Apr 12, 2020 · 3 comments
Closed
Labels

Comments

@weirdan
Copy link
Collaborator
weirdan commented Apr 12, 2020

The fix for #3084 introduced new error message which I'm afraid will be extremely confusing for even the average Psalm user.

Consider this (simple) example: https://psalm.dev/r/8a21c26e0a

Even here one could have a head scratching moment figuring out where do A and B come from. Now imagine that parameters come from one library, getting passed to another library, and types for both provided by independent plugins and it all starts looking like a support hell.

I would suggest to:

  1. spell out the inference sources
  2. get rid of 'uppper/lower bound' terminology and use 'subtype/supertype' instead

Example of adjusted message:

InvalidArgument: template type T inferred from argument 1 (class-string<T>) should be a subtype of type T inferred from argument 2 (callable(T):void)
@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/8a21c26e0a
<?php

function outmaker(B $o): void {}
$className = A::class;

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

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

createProxy($className, 'outmaker')->bar();
Psalm output (using commit 5bc9b09):

ERROR: InvalidArgument - 26:1 - Could not reconcile upper and lower bounds A and B for template param T

@vudaltsov
Copy link
Contributor
vudaltsov commented Apr 12, 2020

Also "see https://psalm.dev/194" does not really help as it is about arrays and iterables.

@muglug muglug added the bug label Apr 12, 2020
muglug added a commit that referenced this issue Apr 13, 2020
@weirdan
Copy link
Collaborator Author
weirdan commented Mar 8, 2021

Message has been changed since.

@weirdan weirdan closed this as completed Mar 8, 2021
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

3 participants
0