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

Defention of internal function mb_convert_encoding() is wrong #4309

Closed
jsiefer opened this issue Oct 12, 2020 · 1 comment
Closed

Defention of internal function mb_convert_encoding() is wrong #4309

jsiefer opened this issue Oct 12, 2020 · 1 comment
Labels

Comments

@jsiefer
Copy link

jsiefer commented Oct 12, 2020

See https://psalm.dev/r/bb126f54c3

The return type of mb_convert_encoding(string|string[] $input, string $to, string|string[] $from): string | string[] depends on its input.

if the input is a string, its return values should be a string and same for string[]

@psalm-github-bot
Copy link

I found these snippets:

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

function test(string $str): string {
    return mb_convert_encoding($str, 'UTF-8', 'UTF-8');
}

/**
 * @param array<int, string> $str
 * @return array<int, string>
 */
function test2(array $str): array {
    return mb_convert_encoding($str, 'UTF-8', 'UTF-8');
}


test('Hello');
test2('Hello');
Psalm output (using commit 321b81e):

ERROR: InvalidReturnStatement - 4:12 - The inferred type 'array<int, string>|string' does not match the declared return type 'string' for test

ERROR: InvalidReturnType - 3:29 - The declared return type 'string' for test is incorrect, got 'array<int, string>|string'

ERROR: InvalidReturnStatement - 12:12 - The inferred type 'array<int, string>|string' does not match the declared return type 'array<int, string>' for test2

ERROR: InvalidReturnType - 9:12 - The declared return type 'array<int, string>' for test2 is incorrect, got 'array<int, string>|string'

ERROR: InvalidArgument - 17:7 - Argument 1 of test2 expects array<int, string>, string(Hello) provided

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

2 participants