Skip to content

non-empty-string swallows other accessory string types if narrowed first #14047

@paulbalandan

Description

@paulbalandan

Bug report

This code:

<?php declare(strict_types = 1);

use function PHPStan\dumpType;
use function PHPStan\Testing\assertType;

function test_strings(string $a, string $b): void
{
	if ($a !== '' && strtolower($a) === $a) {
		assertType('lowercase-string&non-empty-string', $a);
	} elseif ($a !== '' && strtolower($a) === $a) {
		assertType('non-empty-string&uppercase-string', $a);
	}

	if (strtolower($b) === $b && $b !== '') {
		assertType('lowercase-string&non-empty-string', $b);
	} elseif (strtoupper($b) === $b && $b !== '') {
		assertType('non-empty-string&uppercase-string', $b);
	}
}

Code snippet that reproduces the problem

https://phpstan.org/r/71e2eac7-39d2-4544-b3c2-5b36c824647f

Expected output

I expect regardless of order, the asserted type would be the same.

Did PHPStan help you today? Did it make you happy in any way?

Oh, yes!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions