mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 13:51:54 +01:00
Daniil Gentili
1986c8b4a8
* Immutable CodeLocation * Remove excess clones * Remove external clones * Remove leftover clones * Fix final clone issue * Immutable storages * Refactoring * Fixes * Fixes * Fix * Fix * Fixes * Simplify * Fixes * Fix * Fixes * Update * Fix * Cache global types * Fix * Update * Update * Fixes * Fixes * Refactor * Fixes * Fix * Fix * More caching * Fix * Fix * Update * Update * Fix * Fixes * Update * Refactor * Update * Fixes * Break one more test * Fix * FIx * Fix * Fix * Fix * Fix * Improve performance and readability * Equivalent logic * Fixes * Revert * Revert "Revert" This reverts commit f9175100c8452c80559234200663fd4c4f4dd889. * Fix * Fix reference bug * Make default TypeVisitor immutable * Bugfix * Remove clones * Partial refactoring * Refactoring * Fixes * Fix * Fixes * Fixes * cs-fix * Fix final bugs * Add test * Misc fixes * Update * Fixes * Experiment with removing different property * revert "Experiment with removing different property" This reverts commit ac1156e077fc4ea633530d51096d27b6e88bfdf9. * Uniform naming * Uniform naming * Hack hotfix * Clean up $_FILES ref #8621 * Undo hack, try fixing properly * Helper method * Remove redundant call * Partially fix bugs * Cleanup * Change defaults * Fix bug * Fix (?, hope this doesn't break anything else) * cs-fix * Review fixes * Bugfix * Bugfix * Improve logic * Add support for list{} and callable-list{} types, properly implement array_is_list assertions (fixes #8389) * Default to sealed arrays * Fix array_merge bug * Fixes * Fix * Sealed type checks * Properly infer properties-of and get_object_vars on final classes * Fix array_map zipping * Fix tests * Fixes * Fixes * Fix more stuff * Recursively resolve type aliases * Fix typo * Fixes * Fix array_is_list assertion on keyed array * Add BC docs * Fixes * fix * Update * Update * Update * Update * Seal arrays with count assertions * Fix #8528 * Fix * Update * Improve sealed array foreach logic * get_object_vars on template properties * Fix sealed array assertion reconciler logic * Improved reconciler * Add tests * Single source of truth for test types * Fix tests * Fixup tests * Fixup tests * Fixup tests * Update * Fix tests * Fix tests * Final fixes * Fixes * Use list syntax only when needed * Fix tests * Cs-fix * Update docs * Update docs * Update docs * Update docs * Update docs * Document missing types * Update docs * Improve class-string-map docs * Update * Update * I love working on psalm :) * Keep arrays unsealed by default * Fixup tests * Fix syntax mistake * cs-fix * Fix typo * Re-import missing types * Keep strict types only in return types * argc/argv fixes * argc/argv fixes * Fix test * Comment-out valinor code, pinging @romm pls merge https://github.com/CuyZ/Valinor/pull/246 so we can add valinor to the psalm docs :)
838 lines
25 KiB
PHP
838 lines
25 KiB
PHP
<?php
|
|
|
|
namespace Psalm\Tests;
|
|
|
|
use Psalm\Internal\Type\TypeCombiner;
|
|
use Psalm\Tests\Traits\ValidCodeAnalysisTestTrait;
|
|
use Psalm\Type;
|
|
use Psalm\Type\Atomic;
|
|
|
|
class TypeCombinationTest extends TestCase
|
|
{
|
|
use ValidCodeAnalysisTestTrait;
|
|
|
|
/**
|
|
* @dataProvider providerTestValidTypeCombination
|
|
*
|
|
* @param string $expected
|
|
* @param non-empty-list<string> $types
|
|
*
|
|
*/
|
|
public function testValidTypeCombination($expected, $types): void
|
|
{
|
|
$converted_types = [];
|
|
|
|
foreach ($types as $type) {
|
|
$converted_type = self::getAtomic($type);
|
|
/** @psalm-suppress InaccessibleProperty */
|
|
$converted_type->from_docblock = true;
|
|
$converted_types[] = $converted_type;
|
|
}
|
|
|
|
$this->assertSame(
|
|
$expected,
|
|
TypeCombiner::combine($converted_types)->getId()
|
|
);
|
|
}
|
|
|
|
/**
|
|
*
|
|
*/
|
|
public function providerValidCodeParse(): iterable
|
|
{
|
|
return [
|
|
'multipleValuedArray' => [
|
|
'code' => '<?php
|
|
class A {}
|
|
class B {}
|
|
$var = [];
|
|
$var[] = new A();
|
|
$var[] = new B();',
|
|
],
|
|
'preventLiteralAndClassString' => [
|
|
'code' => '<?php
|
|
/**
|
|
* @param "array"|class-string $type_name
|
|
*/
|
|
function foo(string $type_name) : bool {
|
|
return $type_name === "array";
|
|
}',
|
|
],
|
|
'NeverTwice' => [
|
|
'code' => '<?php
|
|
/** @return no-return */
|
|
function other() {
|
|
throw new Exception();
|
|
}
|
|
|
|
rand(0,1) ? die() : other();',
|
|
],
|
|
'ArrayAndTraversableNotIterable' => [
|
|
'code' => '<?php declare(strict_types=1);
|
|
|
|
/** @param mixed $identifier */
|
|
function isNullIdentifier($identifier): bool
|
|
{
|
|
if ($identifier instanceof \Traversable || is_array($identifier)) {
|
|
expectsTraversableOrArray($identifier);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/** @param Traversable|array<array-key, mixed> $_a */
|
|
function expectsTraversableOrArray($_a): void
|
|
{
|
|
|
|
}
|
|
',
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array<string,strict-array{string,non-empty-list<string>}>
|
|
*/
|
|
public function providerTestValidTypeCombination(): array
|
|
{
|
|
return [
|
|
'intOrString' => [
|
|
'int|string',
|
|
[
|
|
'int',
|
|
'string',
|
|
],
|
|
],
|
|
'mixedOrNull' => [
|
|
'mixed|null',
|
|
[
|
|
'mixed',
|
|
'null',
|
|
],
|
|
],
|
|
'mixedOrNever' => [
|
|
'mixed',
|
|
[
|
|
'never',
|
|
'mixed',
|
|
],
|
|
],
|
|
'mixedOrObject' => [
|
|
'mixed|object',
|
|
[
|
|
'mixed',
|
|
'object',
|
|
],
|
|
],
|
|
'mixedOrEmptyArray' => [
|
|
'array<never, never>|mixed',
|
|
[
|
|
'mixed',
|
|
'array<never, never>',
|
|
],
|
|
],
|
|
'falseTrueToBool' => [
|
|
'bool',
|
|
[
|
|
'false',
|
|
'true',
|
|
],
|
|
],
|
|
'trueFalseToBool' => [
|
|
'bool',
|
|
[
|
|
'true',
|
|
'false',
|
|
],
|
|
],
|
|
'trueBoolToBool' => [
|
|
'bool',
|
|
[
|
|
'true',
|
|
'bool',
|
|
],
|
|
],
|
|
'boolTrueToBool' => [
|
|
'bool',
|
|
[
|
|
'bool',
|
|
'true',
|
|
],
|
|
],
|
|
'intOrTrueOrFalseToBool' => [
|
|
'bool|int',
|
|
[
|
|
'int',
|
|
'false',
|
|
'true',
|
|
],
|
|
],
|
|
'intOrBoolOrTrueToBool' => [
|
|
'bool|int',
|
|
[
|
|
'int',
|
|
'bool',
|
|
'true',
|
|
],
|
|
],
|
|
'intOrTrueOrBoolToBool' => [
|
|
'bool|int',
|
|
[
|
|
'int',
|
|
'true',
|
|
'bool',
|
|
],
|
|
],
|
|
'arrayOfIntOrString' => [
|
|
'array<array-key, int|string>',
|
|
[
|
|
'array<int>',
|
|
'array<string>',
|
|
],
|
|
],
|
|
'arrayOfIntOrAlsoString' => [
|
|
'array<array-key, int>|string',
|
|
[
|
|
'array<int>',
|
|
'string',
|
|
],
|
|
],
|
|
'emptyArrays' => [
|
|
'array<never, never>',
|
|
[
|
|
'array<never, never>',
|
|
'array<never, never>',
|
|
],
|
|
],
|
|
'arrayStringOrEmptyArray' => [
|
|
'array<array-key, string>',
|
|
[
|
|
'array<never>',
|
|
'array<string>',
|
|
],
|
|
],
|
|
'arrayMixedOrString' => [
|
|
'array<array-key, mixed|string>',
|
|
[
|
|
'array<mixed>',
|
|
'array<string>',
|
|
],
|
|
],
|
|
'arrayMixedOrStringKeys' => [
|
|
'array<array-key, string>',
|
|
[
|
|
'array<int|string,string>',
|
|
'array<mixed,string>',
|
|
],
|
|
],
|
|
'arrayMixedOrEmpty' => [
|
|
'array<array-key, mixed>',
|
|
[
|
|
'array<never>',
|
|
'array<mixed>',
|
|
],
|
|
],
|
|
'arrayBigCombination' => [
|
|
'array<array-key, float|int|string>',
|
|
[
|
|
'array<int|float>',
|
|
'array<string>',
|
|
],
|
|
],
|
|
'arrayTraversableToIterable' => [
|
|
'iterable<array-key|mixed, mixed>',
|
|
[
|
|
'array',
|
|
'Traversable',
|
|
],
|
|
],
|
|
'arrayIterableToIterable' => [
|
|
'iterable<mixed, mixed>',
|
|
[
|
|
'array',
|
|
'iterable',
|
|
],
|
|
],
|
|
'iterableArrayToIterable' => [
|
|
'iterable<mixed, mixed>',
|
|
[
|
|
'iterable',
|
|
'array',
|
|
],
|
|
],
|
|
'traversableIterableToIterable' => [
|
|
'iterable<mixed, mixed>',
|
|
[
|
|
'Traversable',
|
|
'iterable',
|
|
],
|
|
],
|
|
'iterableTraversableToIterable' => [
|
|
'iterable<mixed, mixed>',
|
|
[
|
|
'iterable',
|
|
'Traversable',
|
|
],
|
|
],
|
|
'arrayTraversableToIterableWithParams' => [
|
|
'iterable<int, bool|string>',
|
|
[
|
|
'array<int, string>',
|
|
'Traversable<int, bool>',
|
|
],
|
|
],
|
|
'arrayIterableToIterableWithParams' => [
|
|
'iterable<int, bool|string>',
|
|
[
|
|
'array<int, string>',
|
|
'iterable<int, bool>',
|
|
],
|
|
],
|
|
'iterableArrayToIterableWithParams' => [
|
|
'iterable<int, bool|string>',
|
|
[
|
|
'iterable<int, string>',
|
|
'array<int, bool>',
|
|
],
|
|
],
|
|
'traversableIterableToIterableWithParams' => [
|
|
'iterable<int, bool|string>',
|
|
[
|
|
'Traversable<int, string>',
|
|
'iterable<int, bool>',
|
|
],
|
|
],
|
|
'iterableTraversableToIterableWithParams' => [
|
|
'iterable<int, bool|string>',
|
|
[
|
|
'iterable<int, string>',
|
|
'Traversable<int, bool>',
|
|
],
|
|
],
|
|
'arrayObjectAndParamsWithEmptyArray' => [
|
|
'ArrayObject<int, string>|array<never, never>',
|
|
[
|
|
'ArrayObject<int, string>',
|
|
'array<never, never>',
|
|
],
|
|
],
|
|
'emptyArrayWithArrayObjectAndParams' => [
|
|
'ArrayObject<int, string>|array<never, never>',
|
|
[
|
|
'array<never, never>',
|
|
'ArrayObject<int, string>',
|
|
],
|
|
],
|
|
'falseDestruction' => [
|
|
'bool',
|
|
[
|
|
'false',
|
|
'bool',
|
|
],
|
|
],
|
|
'onlyFalse' => [
|
|
'false',
|
|
[
|
|
'false',
|
|
],
|
|
],
|
|
'onlyTrue' => [
|
|
'true',
|
|
[
|
|
'true',
|
|
],
|
|
],
|
|
'falseFalseDestruction' => [
|
|
'false',
|
|
[
|
|
'false',
|
|
'false',
|
|
],
|
|
],
|
|
'aAndAOfB' => [
|
|
'A|A<B>',
|
|
[
|
|
'A',
|
|
'A<B>',
|
|
],
|
|
],
|
|
'combineObjectType1' => [
|
|
'strict-array{a?: int, b?: string}',
|
|
[
|
|
'strict-array{a: int}',
|
|
'strict-array{b: string}',
|
|
],
|
|
],
|
|
'combineObjectType2' => [
|
|
'strict-array{a: int|string, b?: string}',
|
|
[
|
|
'strict-array{a: int}',
|
|
'strict-array{a: string,b: string}',
|
|
],
|
|
],
|
|
'combineObjectTypeWithIntKeyedArray' => [
|
|
"array<'a'|int, int|string>",
|
|
[
|
|
'strict-array{a: int}',
|
|
'array<int, string>',
|
|
],
|
|
],
|
|
'combineNestedObjectTypeWithTKeyedArrayIntKeyedArray' => [
|
|
"strict-array{a: array<'a'|int, int|string>}",
|
|
[
|
|
'strict-array{a: strict-array{a: int}}',
|
|
'strict-array{a: array<int, string>}',
|
|
],
|
|
],
|
|
'combineIntKeyedObjectTypeWithNestedIntKeyedArray' => [
|
|
"array<int, array<'a'|int, int|string>>",
|
|
[
|
|
'array<int, strict-array{a:int}>',
|
|
'array<int, array<int, string>>',
|
|
],
|
|
],
|
|
'combineNestedObjectTypeWithNestedIntKeyedArray' => [
|
|
"array<'a'|int, array<'a'|int, int|string>>",
|
|
[
|
|
'strict-array{a: strict-array{a: int}}',
|
|
'array<int, array<int, string>>',
|
|
],
|
|
],
|
|
'combinePossiblyUndefinedKeys' => [
|
|
'strict-array{a: bool, b?: mixed, d?: mixed}',
|
|
[
|
|
'strict-array{a: false, b: mixed}',
|
|
'strict-array{a: true, d: mixed}',
|
|
'strict-array{a: true, d: mixed}',
|
|
],
|
|
],
|
|
'combinePossiblyUndefinedKeysAndString' => [
|
|
'strict-array{a: string, b?: int}|string',
|
|
[
|
|
'strict-array{a: string, b?: int}',
|
|
'string',
|
|
],
|
|
],
|
|
'combineMixedArrayWithTKeyedArray' => [
|
|
'array<array-key, mixed>',
|
|
[
|
|
'strict-array{a: int}',
|
|
'array',
|
|
],
|
|
],
|
|
'traversableAorB' => [
|
|
'Traversable<mixed, A|B>',
|
|
[
|
|
'Traversable<A>',
|
|
'Traversable<B>',
|
|
],
|
|
],
|
|
'iterableAorB' => [
|
|
'iterable<mixed, A|B>',
|
|
[
|
|
'iterable<A>',
|
|
'iterable<B>',
|
|
],
|
|
],
|
|
'FooAorB' => [
|
|
'Foo<A>|Foo<B>',
|
|
[
|
|
'Foo<A>',
|
|
'Foo<B>',
|
|
],
|
|
],
|
|
'traversableOfMixed' => [
|
|
'Traversable<mixed, mixed>',
|
|
[
|
|
'Traversable',
|
|
'Traversable<mixed, mixed>',
|
|
],
|
|
],
|
|
'traversableAndIterator' => [
|
|
'Traversable&Iterator',
|
|
[
|
|
'Traversable&Iterator',
|
|
'Traversable&Iterator',
|
|
],
|
|
],
|
|
'traversableOfMixedAndIterator' => [
|
|
'Traversable<mixed, mixed>&Iterator',
|
|
[
|
|
'Traversable<mixed, mixed>&Iterator',
|
|
'Traversable<mixed, mixed>&Iterator',
|
|
],
|
|
],
|
|
'objectLikePlusArrayEqualsArray' => [
|
|
"array<'a'|'b'|'c', 1|2|3>",
|
|
[
|
|
'array<"a"|"b"|"c", 1|2|3>',
|
|
'strict-array{a: 1|2, b: 2|3, c: 1|3}',
|
|
],
|
|
],
|
|
'combineClosures' => [
|
|
'Closure(A):void|Closure(B):void',
|
|
[
|
|
'Closure(A):void',
|
|
'Closure(B):void',
|
|
],
|
|
],
|
|
'combineClassStringWithString' => [
|
|
'string',
|
|
[
|
|
'class-string',
|
|
'string',
|
|
],
|
|
],
|
|
'combineClassStringWithFalse' => [
|
|
'class-string|false',
|
|
[
|
|
'class-string',
|
|
'false',
|
|
],
|
|
],
|
|
'combineRefinedClassStringWithString' => [
|
|
'string',
|
|
[
|
|
'class-string<Exception>',
|
|
'string',
|
|
],
|
|
],
|
|
'combineRefinedClassStrings' => [
|
|
'class-string<Exception>|class-string<Iterator>',
|
|
[
|
|
'class-string<Exception>',
|
|
'class-string<Iterator>',
|
|
],
|
|
],
|
|
'combineClassStringsWithLiteral' => [
|
|
'class-string',
|
|
[
|
|
'class-string',
|
|
'Exception::class',
|
|
],
|
|
],
|
|
'combineClassStringWithNumericString' => [
|
|
'class-string|numeric-string',
|
|
[
|
|
'class-string',
|
|
'numeric-string',
|
|
],
|
|
],
|
|
'combineRefinedClassStringWithNumericString' => [
|
|
'class-string<Exception>|numeric-string',
|
|
[
|
|
'class-string<Exception>',
|
|
'numeric-string',
|
|
],
|
|
],
|
|
'combineClassStringWithTraitString' => [
|
|
'class-string|trait-string',
|
|
[
|
|
'class-string',
|
|
'trait-string',
|
|
],
|
|
],
|
|
'combineRefinedClassStringWithTraitString' => [
|
|
'class-string<Exception>|trait-string',
|
|
[
|
|
'class-string<Exception>',
|
|
'trait-string',
|
|
],
|
|
],
|
|
'combineCallableAndCallableString' => [
|
|
'callable',
|
|
[
|
|
'callable',
|
|
'callable-string',
|
|
],
|
|
],
|
|
'combineCallableStringAndCallable' => [
|
|
'callable',
|
|
[
|
|
'callable-string',
|
|
'callable'
|
|
],
|
|
],
|
|
'combineCallableAndCallableObject' => [
|
|
'callable',
|
|
[
|
|
'callable',
|
|
'callable-object',
|
|
],
|
|
],
|
|
'combineCallableObjectAndCallable' => [
|
|
'callable',
|
|
[
|
|
'callable-object',
|
|
'callable'
|
|
],
|
|
],
|
|
'combineCallableAndCallableArray' => [
|
|
'callable',
|
|
[
|
|
'callable',
|
|
'callable-array',
|
|
],
|
|
],
|
|
'combineCallableArrayAndCallable' => [
|
|
'callable',
|
|
[
|
|
'callable-array',
|
|
'callable'
|
|
],
|
|
],
|
|
'combineCallableArrayAndArray' => [
|
|
'array<array-key, mixed>',
|
|
[
|
|
'callable-strict-array{class-string, string}',
|
|
'array',
|
|
],
|
|
],
|
|
'combineGenericArrayAndMixedArray' => [
|
|
'array<array-key, int|mixed>',
|
|
[
|
|
'array<string, int>',
|
|
'array<array-key, mixed>',
|
|
],
|
|
],
|
|
'combineTKeyedArrayAndArray' => [
|
|
'array<array-key, mixed>',
|
|
[
|
|
'strict-array{hello: int}',
|
|
'array<array-key, mixed>',
|
|
],
|
|
],
|
|
'combineTKeyedArrayAndNestedArray' => [
|
|
'array<array-key, mixed>',
|
|
[
|
|
'strict-array{hello: strict-array{goodbye: int}}',
|
|
'array<array-key, mixed>',
|
|
],
|
|
],
|
|
'combineNumericStringWithLiteralString' => [
|
|
'numeric-string',
|
|
[
|
|
'numeric-string',
|
|
'"1"',
|
|
],
|
|
],
|
|
'combineLiteralStringWithNumericString' => [
|
|
'numeric-string',
|
|
[
|
|
'"1"',
|
|
'numeric-string',
|
|
],
|
|
],
|
|
'combineNonEmptyListWithTKeyedArrayList' => [
|
|
'list{null|string}<int, string>',
|
|
[
|
|
'non-empty-list<string>',
|
|
'strict-array{null}'
|
|
],
|
|
],
|
|
'combineZeroAndPositiveInt' => [
|
|
'int<0, max>',
|
|
[
|
|
'0',
|
|
'positive-int',
|
|
],
|
|
],
|
|
'combinePositiveIntAndZero' => [
|
|
'int<0, max>',
|
|
[
|
|
'positive-int',
|
|
'0',
|
|
],
|
|
],
|
|
'combinePositiveIntAndMinusOne' => [
|
|
'int<-1, max>',
|
|
[
|
|
'positive-int',
|
|
'-1',
|
|
],
|
|
],
|
|
'combinePositiveIntZeroAndMinusOne' => [
|
|
'int<-1, max>',
|
|
[
|
|
'0',
|
|
'positive-int',
|
|
'-1',
|
|
],
|
|
],
|
|
'combineMinusOneAndPositiveInt' => [
|
|
'int<-1, max>',
|
|
[
|
|
'-1',
|
|
'positive-int',
|
|
],
|
|
],
|
|
'combineZeroMinusOneAndPositiveInt' => [
|
|
'int<-1, max>',
|
|
[
|
|
'0',
|
|
'-1',
|
|
'positive-int',
|
|
],
|
|
],
|
|
'combineZeroOneAndPositiveInt' => [
|
|
'int<0, max>',
|
|
[
|
|
'0',
|
|
'1',
|
|
'positive-int',
|
|
],
|
|
],
|
|
'combinePositiveIntOneAndZero' => [
|
|
'int<0, max>',
|
|
[
|
|
'positive-int',
|
|
'1',
|
|
'0',
|
|
],
|
|
],
|
|
'combinePositiveInts' => [
|
|
'int<1, max>',
|
|
[
|
|
'positive-int',
|
|
'positive-int',
|
|
],
|
|
],
|
|
'combineNonEmptyArrayAndKeyedArray' => [
|
|
'array<int, int>',
|
|
[
|
|
'non-empty-array<int, int>',
|
|
'strict-array{0?:int}',
|
|
]
|
|
],
|
|
'combineNonEmptyStringAndLiteral' => [
|
|
'non-empty-string',
|
|
[
|
|
'non-empty-string',
|
|
'"foo"',
|
|
]
|
|
],
|
|
'combineLiteralAndNonEmptyString' => [
|
|
'non-empty-string',
|
|
[
|
|
'"foo"',
|
|
'non-empty-string'
|
|
]
|
|
],
|
|
'combineTruthyStringAndNonEmptyString' => [
|
|
'non-empty-string',
|
|
[
|
|
'truthy-string',
|
|
'non-empty-string'
|
|
]
|
|
],
|
|
'combineNonFalsyNonEmptyString' => [
|
|
'non-empty-string',
|
|
[
|
|
'non-falsy-string',
|
|
'non-empty-string'
|
|
]
|
|
],
|
|
'combineNonEmptyNonFalsyString' => [
|
|
'non-empty-string',
|
|
[
|
|
'non-empty-string',
|
|
'non-falsy-string'
|
|
]
|
|
],
|
|
'combineNonEmptyStringAndNumericString' => [
|
|
'non-empty-string',
|
|
[
|
|
'non-empty-string',
|
|
'numeric-string'
|
|
]
|
|
],
|
|
'combineNumericStringAndNonEmptyString' => [
|
|
'non-empty-string',
|
|
[
|
|
'numeric-string',
|
|
'non-empty-string'
|
|
]
|
|
],
|
|
'combineNonEmptyLowercaseAndNonFalsyString' => [
|
|
'non-empty-string',
|
|
[
|
|
'non-falsy-string',
|
|
'non-empty-lowercase-string',
|
|
]
|
|
],
|
|
'combineNonEmptyAndEmptyScalar' => [
|
|
'scalar',
|
|
[
|
|
'non-empty-scalar',
|
|
'empty-scalar',
|
|
]
|
|
],
|
|
'combineLiteralStringAndNonspecificLiteral' => [
|
|
'literal-string',
|
|
[
|
|
'literal-string',
|
|
'"foo"',
|
|
]
|
|
],
|
|
'combineNonspecificLiteralAndLiteralString' => [
|
|
'literal-string',
|
|
[
|
|
'"foo"',
|
|
'literal-string',
|
|
]
|
|
],
|
|
'combineLiteralIntAndNonspecificLiteral' => [
|
|
'literal-int',
|
|
[
|
|
'literal-int',
|
|
'5',
|
|
]
|
|
],
|
|
'combineNonspecificLiteralAndLiteralInt' => [
|
|
'literal-int',
|
|
[
|
|
'5',
|
|
'literal-int',
|
|
]
|
|
],
|
|
'combineNonspecificLiteralAndPositiveInt' => [
|
|
'int',
|
|
[
|
|
'positive-int',
|
|
'literal-int',
|
|
]
|
|
],
|
|
'combinePositiveAndLiteralInt' => [
|
|
'int',
|
|
[
|
|
'literal-int',
|
|
'positive-int',
|
|
]
|
|
],
|
|
'combineNonEmptyStringAndNonEmptyNonSpecificLiteralString' => [
|
|
'non-empty-string',
|
|
[
|
|
'non-empty-literal-string',
|
|
'non-empty-string',
|
|
],
|
|
],
|
|
'combineNonEmptyNonSpecificLiteralStringAndNonEmptyString' => [
|
|
'non-empty-string',
|
|
[
|
|
'non-empty-string',
|
|
'non-empty-literal-string',
|
|
],
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @param string $string
|
|
*
|
|
*/
|
|
private static function getAtomic($string): Atomic
|
|
{
|
|
return Type::parseString($string)->getSingleAtomic();
|
|
}
|
|
}
|