Skip to content

array_merge() and numeric-string keys #6945

@staabm

Description

@staabm

Bug report

from phpstan/phpstan-src#1135 (comment)

there is a interessting test-case, I tried to add.

	/**
	 * @param array<numeric-string&non-empty-string, string> $params1
	 * @param array<numeric-string, string> $params2
	 */
	function foo5(array $params1, array $params2): void
	{
		$params2 = array_merge($params1, $params2);

		assertType('array<numeric-string, string>', $params2);
	}

it errors with

There was 1 failure:

1) PHPStan\Analyser\NodeScopeResolverTest::testFileAsserts with data set "C:\dvl\Workspace\phpstan-src-staabm\tests\PHPStan\Analyser/data/bug-6927.php:61" ('type', 'C:\dvl\Workspace\phpstan-src-...27.php', PHPStan\Type\Constant\ConstantStringType Object (...), PHPStan\Type\ArrayType Object (...), 61)
Expected type array<numeric-string, string>, got type array<int, string> in C:\dvl\Workspace\phpstan-src-staabm\tests\PHPStan\Analyser/data/bug-6927.php on line 61.
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'array<numeric-string, string>'
+'array<int, string>'

C:\dvl\Workspace\phpstan-src-staabm\src\Testing\TypeInferenceTestCase.php:97
C:\dvl\Workspace\phpstan-src-staabm\tests\PHPStan\Analyser\NodeScopeResolverTest.php:846

Code snippet that reproduces the problem

https://phpstan.org/r/7188229f-71b8-4990-a977-5494b1e7d2ee

Expected output

no error

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