Skip to content

Commit fc8212e

Browse files
committed
Fix static call specialisation via annotation
1 parent bee10a2 commit fc8212e

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticCallAnalyzer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,7 @@ private static function taintReturnType(
13681368
? ($method_storage->signature_return_type_location ?: $method_storage->location)
13691369
: null;
13701370

1371-
if ($method_storage && $method_storage->pure) {
1371+
if ($method_storage && $method_storage->specialize_call) {
13721372
$method_source = TaintNode::getForMethodReturn(
13731373
(string) $method_id,
13741374
$cased_method_id,

tests/TaintTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,4 +1717,36 @@ public function testImplodeExplode() : void
17171717

17181718
$this->analyzeFile('somefile.php', new Context());
17191719
}
1720+
1721+
public function testSpecializeStaticMethod() : void
1722+
{
1723+
$this->project_analyzer->trackTaintedInputs();
1724+
1725+
$this->addFile(
1726+
'somefile.php',
1727+
'<?php
1728+
StringUtility::foo($_GET["c"]);
1729+
1730+
class StringUtility {
1731+
/**
1732+
* @psalm-taint-specialize
1733+
*/
1734+
public static function foo(string $str) : string
1735+
{
1736+
return $str;
1737+
}
1738+
1739+
/**
1740+
* @psalm-taint-specialize
1741+
*/
1742+
public static function slugify(string $url) : string {
1743+
return self::foo($url);
1744+
}
1745+
}
1746+
1747+
echo StringUtility::slugify("hello");'
1748+
);
1749+
1750+
$this->analyzeFile('somefile.php', new Context());
1751+
}
17201752
}

0 commit comments

Comments
 (0)