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

Incompatible types found for T #6212

Closed
VincentLanglet opened this issue Jul 31, 2021 · 6 comments
Closed

Incompatible types found for T #6212

VincentLanglet opened this issue Jul 31, 2021 · 6 comments

Comments

@VincentLanglet
Copy link
Contributor

Since the last version (4.9.1), I'm getting a new error: Incompatible types found for T.
https://psalm.dev/r/a1e0f8f6f1

I saw that @muglug try to fix the issue #6066
But I don't think my case should be reported.

According to the trace, I'm passing

AdminInterface<T:AdminEventExtension as object>
FormMapper<T:AdminEventExtension as object>, which is MapperInterface<T:AdminEventExtension as object>

So it should be compatible with the ConfigureEvent::__construct

    /**
     * @param AdminInterface<T> $admin
     * @param MapperInterface<T> $mapper
     */
@psalm-github-bot
Copy link

I found these snippets:

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

/**
 * @template T of object
 */
interface AdminInterface {}

/**
 * @template T of object
 */
interface MapperInterface
{
    /**
     * @return AdminInterface<T>
     */
    public function getAdmin();
}

/**
 * @template T of object
 * @phpstan-implements MapperInterface<T>
 */
class FormMapper implements MapperInterface
{
    public function getAdmin()
    {
        throw new \Exception('TODO');
    }
}

/**
 * @template T of object
 */
class ConfigureEvent
{
    /**
     * @param AdminInterface<T> $admin
     * @param MapperInterface<T> $mapper
     */
    public function __construct(AdminInterface $admin, MapperInterface $mapper)
    {
    }
}

/**
 * @template T of object
 */
class AdminEventExtension
{
    /**
     * @param FormMapper<T> $form
     */
    public function configureFormFields(FormMapper $form): void
    {
        /** @psalm-trace $admin */
        $admin = $form->getAdmin();
        /** @psalm-trace $form */
        
        new ConfigureEvent($admin, $form);
    }
}
Psalm output (using commit 7e137f5):

INFO: Trace - 56:9 - $admin: AdminInterface<T:AdminEventExtension as object>

ERROR: InvalidArgument - 59:9 - Incompatible types found for T

INFO: Trace - 59:9 - $form: FormMapper<T:AdminEventExtension as object>

@muglug
Copy link
Collaborator

muglug commented Jul 31, 2021

Simplified: https://psalm.dev/r/1a83e98791

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/1a83e98791
<?php

/**
 * @template T of object
 */
interface A {}

/**
 * @template T of object
 */
interface B {}

/**
 * @template T of object
 * @param A<T> $admin
 * @param B<T> $mapper
 */
function foo(A $admin, B $mapper): void
{}

/**
 * @param A<stdClass> $admin
 * @param B<stdClass> $mapper
 */
function configureFormFields(A $admin, B $mapper): void {
    foo($admin, $mapper);
}
Psalm output (using commit 7e137f5):

ERROR: InvalidArgument - 26:5 - Incompatible types found for T

@muglug muglug closed this as completed in a205a23 Jul 31, 2021
@VincentLanglet
Copy link
Contributor Author

Thanks for the fix @muglug.

Does a 4.9.2 will be planned @weirdan ? :)

@orklah
Copy link
Collaborator

orklah commented Aug 1, 2021

It seems to affect some other repos as well: https://github.com/laminas/automatic-releases/pull/157/checks?check_run_id=3212245604

@muglug
Copy link
Collaborator

muglug commented Aug 1, 2021

I've created a release for 4.9.2

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

No branches or pull requests

3 participants