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

Literal 'foo' is not in string when using templated parameter types #8732

Closed
ciaranmcnulty opened this issue Nov 22, 2022 · 2 comments · Fixed by #8731
Closed

Literal 'foo' is not in string when using templated parameter types #8732

ciaranmcnulty opened this issue Nov 22, 2022 · 2 comments · Fixed by #8731

Comments

@ciaranmcnulty
Copy link
Contributor

https://psalm.dev/r/40d5f10df0

Here it's saying the string literal 'foo' doesn't match the templated type which is string - can't see anything wrong?

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/40d5f10df0
<?php

/** 
 * @template T
 */
interface Norm
{
    /**
     * @param T $input
     * @return T
     */
    public function normalize(mixed $input): mixed;   
}

/**
 * @implements Norm<string>
 */
class StringNorm implements Norm
{
    public function normalize(mixed $input): mixed
    {
        return strtolower($input);
    }
}

/**
 * @template TNorm
 *
 * @param TNorm $value
 * @param Norm<TNorm> $n
 */
function normalizeField(mixed $value, Norm $n): void
{
 	$n->normalize($value);
}

normalizeField('foo', new StringNorm());
Psalm output (using commit 7869cb5):

ERROR: InvalidArgument - 37:1 - Incompatible types found for TNorm ('foo' is not in string)

@ciaranmcnulty ciaranmcnulty changed the title Literal string is not of string Literal 'foo' is not in string when using templated parameter types Nov 22, 2022
@danog
Copy link
Collaborator

danog commented Nov 22, 2022

Fixed by #8731

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