Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Rules/FunctionCallParametersCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ public function check(
if ($this->checkMissingTypehints && $parametersAcceptor instanceof ResolvedFunctionVariant) {
$originalParametersAcceptor = $parametersAcceptor->getOriginalParametersAcceptor();
$resolvedTypes = $parametersAcceptor->getResolvedTemplateTypeMap()->getTypes();
if (count($resolvedTypes) > 0) {
if (!$isBuiltin && count($resolvedTypes) > 0) {
$returnTemplateTypes = [];
TypeTraverser::map(
$parametersAcceptor->getReturnTypeWithUnresolvableTemplateTypes(),
Expand Down
16 changes: 11 additions & 5 deletions tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -764,11 +764,6 @@ public function testArrayUdiffCallback(): void
"Parameter #3 \$data_comp_func of function array_udiff expects callable(1|2|3|4|5|6, 1|2|3|4|5|6): int, Closure(int, int): ('11'|'12'|'13'|'14'|'15'|'16'|'21'|'22'|'23'|'24'|'25'|'26'|'31'|'32'|'33'|'34'|'35'|'36'|'41'|'42'|'43'|'44'|'45'|'46'|'51'|'52'|'53'|'54'|'55'|'56'|'61'|'62'|'63'|'64'|'65'|'66') given.",
14,
],
[
'Unable to resolve the template type TK in call to function array_udiff',
19,
'See: https://phpstan.org/blog/solving-phpstan-error-unable-to-resolve-template-type',
],
[
'Parameter #1 $arr1 of function array_udiff expects array<int|string, string>, null given.',
20,
Expand Down Expand Up @@ -3533,4 +3528,15 @@ public function testBenevolentUnionDescription(): void
]);
}

public function testBug15700(): void
{
$this->analyse([__DIR__ . '/data/bug-15700.php'], [
[
'Unable to resolve the template type T in call to function Bug15700Functions\\userArrayValues',
22,
'See: https://phpstan.org/blog/solving-phpstan-error-unable-to-resolve-template-type',
],
]);
}

}
23 changes: 23 additions & 0 deletions tests/PHPStan/Rules/Functions/data/bug-15700.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Bug15700Functions;

/**
* @template T
* @param array<T> $array
* @return list<T>
*/
function userArrayValues(array $array): array
{
return array_values($array);
}

/**
* @param mixed $value
*/
function doFoo($value, $implicitMixed): void
{
array_values($value);
array_values($implicitMixed);
userArrayValues($value);
}
13 changes: 13 additions & 0 deletions tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1165,4 +1165,17 @@ public function testBug15235(): void
$this->analyse([__DIR__ . '/data/bug-15235.php'], []);
}

#[RequiresPhp('>= 8.0')]
public function testBug15700(): void
{
$this->checkThisOnly = false;
$this->analyse([__DIR__ . '/data/bug-15700.php'], [
[
'Unable to resolve the template type TIn in call to static method Bug15700Methods\\Foo::create()',
26,
'See: https://phpstan.org/blog/solving-phpstan-error-unable-to-resolve-template-type',
],
]);
}

}
27 changes: 27 additions & 0 deletions tests/PHPStan/Rules/Methods/data/bug-15700.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php // lint >= 8.0

namespace Bug15700Methods;

class Foo
{

/**
* @template TIn of object
* @param TIn $object
* @return \WeakReference<TIn>
*/
public static function create(object $object): \WeakReference
{
return \WeakReference::create($object);
}

}

/**
* @param mixed $value
*/
function doFoo($value): void
{
\WeakReference::create($value);
Foo::create($value);
}
Loading