mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Fix #5434 - prevent crash with class-string-map
This commit is contained in:
parent
1bb4a05725
commit
c4aea7c82c
@ -451,7 +451,7 @@ class ArgumentAnalyzer
|
|||||||
if ($arg_type->hasArray()) {
|
if ($arg_type->hasArray()) {
|
||||||
/**
|
/**
|
||||||
* @psalm-suppress PossiblyUndefinedStringArrayOffset
|
* @psalm-suppress PossiblyUndefinedStringArrayOffset
|
||||||
* @var Type\Atomic\TArray|Type\Atomic\TList|Type\Atomic\TKeyedArray
|
* @var Type\Atomic\TArray|Type\Atomic\TList|Type\Atomic\TKeyedArray|Type\Atomic\TClassStringMap
|
||||||
*/
|
*/
|
||||||
$unpacked_atomic_array = $arg_type->getAtomicTypes()['array'];
|
$unpacked_atomic_array = $arg_type->getAtomicTypes()['array'];
|
||||||
$arg_key_allowed = true;
|
$arg_key_allowed = true;
|
||||||
@ -489,6 +489,8 @@ class ArgumentAnalyzer
|
|||||||
}
|
}
|
||||||
} elseif ($unpacked_atomic_array instanceof Type\Atomic\TList) {
|
} elseif ($unpacked_atomic_array instanceof Type\Atomic\TList) {
|
||||||
$arg_type = $unpacked_atomic_array->type_param;
|
$arg_type = $unpacked_atomic_array->type_param;
|
||||||
|
} elseif ($unpacked_atomic_array instanceof Type\Atomic\TClassStringMap) {
|
||||||
|
$arg_type = Type::getMixed();
|
||||||
} else {
|
} else {
|
||||||
if (!$allow_named_args && !$unpacked_atomic_array->type_params[0]->isInt()) {
|
if (!$allow_named_args && !$unpacked_atomic_array->type_params[0]->isInt()) {
|
||||||
$arg_key_allowed = false;
|
$arg_key_allowed = false;
|
||||||
@ -645,7 +647,8 @@ class ArgumentAnalyzer
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Type\Atomic\TKeyedArray|Type\Atomic\TArray|Type\Atomic\TList $unpacked_atomic_array
|
* @param Type\Atomic\TKeyedArray|Type\Atomic\TArray|Type\Atomic\TList|Type\Atomic\TClassStringMap
|
||||||
|
* $unpacked_atomic_array
|
||||||
* @return null|false
|
* @return null|false
|
||||||
*/
|
*/
|
||||||
public static function verifyType(
|
public static function verifyType(
|
||||||
@ -1321,7 +1324,8 @@ class ArgumentAnalyzer
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Type\Atomic\TKeyedArray|Type\Atomic\TArray|Type\Atomic\TList $unpacked_atomic_array
|
* @param Type\Atomic\TKeyedArray|Type\Atomic\TArray|Type\Atomic\TList|Type\Atomic\TClassStringMap
|
||||||
|
* $unpacked_atomic_array
|
||||||
*/
|
*/
|
||||||
private static function coerceValueAfterGatekeeperArgument(
|
private static function coerceValueAfterGatekeeperArgument(
|
||||||
StatementsAnalyzer $statements_analyzer,
|
StatementsAnalyzer $statements_analyzer,
|
||||||
|
@ -71,6 +71,19 @@ class ClassStringMapTest extends TestCase
|
|||||||
}
|
}
|
||||||
}',
|
}',
|
||||||
],
|
],
|
||||||
|
'noCrashWithSplatMap' => [
|
||||||
|
'<?php
|
||||||
|
class A {}
|
||||||
|
|
||||||
|
/** @param array<array-key, mixed> $args */
|
||||||
|
function takesVariadic(...$args): void {
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @param class-string-map<A, A> $arr */
|
||||||
|
function foo(array $arr) : void {
|
||||||
|
takesVariadic(...$arr);
|
||||||
|
}'
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user