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

Invalid ImplementedReturnTypeMismatch #2556

Closed
azjezz opened this issue Jan 5, 2020 · 2 comments
Closed

Invalid ImplementedReturnTypeMismatch #2556

azjezz opened this issue Jan 5, 2020 · 2 comments
Labels

Comments

@azjezz
Copy link
Contributor

azjezz commented Jan 5, 2020

I have encountered a bug in the ImplementedReturnTypeMismatch checker while writing some code today 🙂

the typing here is sane, i have even reimplemented the exact same interfaces in hack lang and was able to type check everything without errors, so this is most likely a psalm bug.

snippet : https://psalm.dev/r/19b73ba81b

hack sample :

namespace MyCollections;

interface ICollection<Tk as arraykey, Tv>
  extends \Countable, \IteratorAggregate<Tv> {
  public function zip<Tu>(Container<Tu> $iterable): ICollection<Tk, (Tv, Tu)>;
}

interface IAccessibleCollection<Tk as arraykey, Tv> extends ICollection<Tk, Tv>
{
  public function zip<Tu>(
    Container<Tu> $iterable
  ): IAccessibleCollection<Tk, (Tv, Tu)>;
}

hack type checker output :

hack-psalm hhvm --version
HipHop VM 4.38.0 (rel)
Compiler: 1577995291_580682453
Repo schema: 9ac3425448b38a0b90b019ba45c2e61eabafa30chack-psalm hh_client interfaces.hack
No errors!hack-psalm 
@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/19b73ba81b
<?php
  
/**
 * @template Tk of array-key
 * @template Tv
 *
 * @extends IteratorAggregate<Tk, Tv>
 */
interface Collection extends Countable, IteratorAggregate
{
    /**
     * @psalm-template Tu
     *
     * @psalm-param iterable<Tu> $iterable
     *
     * @psalm-return Collection<Tk, array{0: Tv, 1: Tu}>
     */
    public function zip(iterable $iterable): Collection;
}

/**
 * @template Tk of array-key
 * @template Tv
 *
 * @extends Collection<Tk, Tv>
 */
interface AccessibleCollection extends Collection
{
    /**
     * @psalm-template Tu
     *
     * @psalm-param iterable<Tu> $iterable
     *
     * @psalm-return AccessibleCollection<Tk, array{0: Tv, 1: Tu}>
     */
    public function zip(iterable $iterable): AccessibleCollection;
}
Psalm output (using commit d4ef5c2):

ERROR: ImplementedReturnTypeMismatch - 34:22 - The inherited return type 'Collection<Tk:AccessibleCollection as array-key, array{0: Tv:AccessibleCollection as mixed, 1: Tu:fn-collection::zip as mixed}>' for Collection::zip is different to the implemented return type for AccessibleCollection::zip 'AccessibleCollection<Tk:AccessibleCollection as array-key, array{0: array{0: Tv:AccessibleCollection as mixed, 1: Tu:fn-accessiblecollection::zip as mixed}, 1: Tu:fn-accessiblecollection::zip as mixed}>'

INFO: PossiblyUnusedMethod - 18:21 - Cannot find any calls to method Collection::zip

@weirdan weirdan added the bug label Jan 5, 2020
@muglug
Copy link
Collaborator

muglug commented Jan 6, 2020

Can be simplified to

/**
 * @template T1
 */
interface C
{
    /**
     * @psalm-return C<array<int, T1>>
     */
    public function zip(): C;
}

/**
 * @template T2
 * @extends C<T2>
 */
interface AC extends C
{
    /**
     * @psalm-return AC<array<int, T2>>
     */
    public function zip(): AC;
}

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