[Capability] Stop a union type losing a branch (#434)
* [Capability] Stop a union type losing a branch
mapPhpTypeToJsonSchemaType() tested for array syntax before splitting the
union, so string[]|int mapped to array alone; applyArrayConstraints() then
overwrote the type with array whenever the union contained one, dropping the
scalar branch a second time. A tool declaring such a parameter rejected a
valid integer argument.
The split now happens first and only at the top level, so array<int|string>
and array{a: int|string} stay one type rather than two that do not exist, and
the array branch keeps its items alongside the others - which is what 2020-12
means by items: a constraint that applies only when the instance is an array.
* Apply suggestion from @chr-hertel
* Isolate the array branch before inferring its element type
* Don't apply items to arrays whose union branches disagree on element type
This commit is contained in:
parent
0751a83658
commit
ced762614b
1 changed files with 247 additions and 20 deletions
27
tests/Unit/Capability/Discovery/UnionFixture.php
Normal file
27
tests/Unit/Capability/Discovery/UnionFixture.php
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the official PHP MCP SDK.
|
||||
*
|
||||
* A collaboration between Symfony and the PHP Foundation.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Mcp\Tests\Unit\Capability\Discovery;
|
||||
|
||||
class UnionFixture
|
||||
{
|
||||
/**
|
||||
* @param string[]|int $mixedish an array branch beside a scalar one
|
||||
* @param int|string $scalars two scalar branches
|
||||
* @param string[] $arrayOnly one branch, and it is an array
|
||||
* @param string[]|null $nullableArray an array branch that may be null
|
||||
* @param string[]|int[] $disagreeingArrays two array branches with different element types
|
||||
*/
|
||||
public function handle(array|int $mixedish, int|string $scalars, array $arrayOnly, ?array $nullableArray, array $disagreeingArrays): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue