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

DocblockTypeContradiction error creates incorrect type and wrong error #9038

Closed
kkmuffme opened this issue Jan 1, 2023 · 3 comments · Fixed by #9209
Closed

DocblockTypeContradiction error creates incorrect type and wrong error #9038

kkmuffme opened this issue Jan 1, 2023 · 3 comments · Fixed by #9209

Comments

@kkmuffme
Copy link
Contributor

kkmuffme commented Jan 1, 2023

https://psalm.dev/r/abc33fab15

The first trace should be int - not int|float

@psalm-github-bot
Copy link

I found these snippets:

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

/**
 * @var int|float $init
 */
$foo = $init;

if ( is_int( $foo ) || !is_float( $foo ) ) {
 	/** @psalm-trace $foo */;   
    return;
}

/** @psalm-trace $foo */;
Psalm output (using commit e81823e):

ERROR: DocblockTypeContradiction - 8:24 - Docblock-defined type float for $foo is always float

INFO: Trace - 9:27 - $foo: float|int

INFO: Trace - 13:25 - $foo: float

@kkmuffme
Copy link
Contributor Author

kkmuffme commented Jan 5, 2023

Reverse issue too https://psalm.dev/r/335b5aca9e

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/335b5aca9e
<?php

/**
 * @param int|float $arg
 * @return bool
 *
 * @psalm-assert-if-true int $arg
 * @psalm-assert-if-false float $arg
 */
function is_int_or_float( $arg ) {
	if ( is_int( $arg ) ) {
		return true;
	}

	return false;
}

/**
 * @var int|float $init
 */
$foo = $init;

if ( is_int_or_float( $foo ) ) {
	/** @psalm-trace $foo */;
	return;
}

/** @psalm-trace $foo */;
Psalm output (using commit 7d6a48a):

ERROR: RedundantCondition - 23:6 - Type int for $foo is never float

INFO: Trace - 24:26 - $foo: int

INFO: Trace - 28:25 - $foo: float|int

kkmuffme added a commit to kkmuffme/psalm that referenced this issue Jan 5, 2023
kkmuffme added a commit to kkmuffme/psalm that referenced this issue Jan 5, 2023
kkmuffme added a commit to kkmuffme/psalm that referenced this issue Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants