Skip to content
Closed
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 .github/workflows/windows-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
with:
php-version: '8.5'
#ini-values: zend.assertions=1, assert.exception=1, opcache.enable_cli=1, opcache.jit=function, opcache.jit_buffer_size=512M
ini-values: zend.assertions=1, assert.exception=1, opcache.enable_cli=1, opcache.jit=off
ini-values: zend.assertions=1, assert.exception=1
tools: composer:v2
coverage: none
#extensions: none, curl, dom, filter, intl, json, libxml, mbstring, openssl, opcache, pcre, phar, reflection, simplexml, spl, tokenizer, xml, xmlwriter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,8 @@ private static function getNewType(
* Whether the constructor binds the given template through a `class-string<T>`
* (`T::class`) parameter position, which names the template's type exactly
* rather than providing a value of it.
*
* @psalm-mutation-free
*/
private static function templateBoundThroughClassString(
MethodStorage $method_storage,
Expand Down Expand Up @@ -1139,6 +1141,7 @@ private static function templateBoundThroughClassString(
* only have been fixed at the construction site.
*
* @return array<string, true>
* @psalm-mutation-free
*/
private static function getUnconstrainableTemplates(ClassLikeStorage $storage): array
{
Expand Down
27 changes: 21 additions & 6 deletions src/Psalm/Internal/Analyzer/StatementsAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,16 @@ final class StatementsAnalyzer extends SourceAnalyzer
*/
public readonly bool $owns_type_variable_tracker;

public function __construct(protected SourceAnalyzer $source, public NodeDataProvider $node_data)
{
private int $depth = 0;

/**
* @psalm-mutation-free
*/
public function __construct(
protected SourceAnalyzer $source,
public NodeDataProvider $node_data,
private readonly bool $root_scope,
) {
$this->file_analyzer = $source->getFileAnalyzer();
$this->codebase = $source->getCodebase();

Expand All @@ -185,10 +193,17 @@ public function __construct(protected SourceAnalyzer $source, public NodeDataPro
$this->owns_type_variable_tracker = true;
}

if ($this->codebase->taint_flow_graph) {
$this->data_flow_graph = new TaintFlowGraph();
} elseif ($this->codebase->find_unused_variables) {
$this->data_flow_graph = new VariableUseGraph();
if ($this->codebase->taint_flow_graph
&& $root_scope
&& $this->codebase->config->trackTaintsInPath($this->getFilePath())
) {
$this->data_flow_graph = $this->taint_flow_graph = $this->codebase->taint_flow_graph;
}
if ($this->codebase->find_unused_variables) {
$this->data_flow_graph = $this->variable_use_graph = new VariableUseGraph();
}
if ($this->taint_flow_graph && $this->variable_use_graph) {
$this->data_flow_graph = new CombinedFlowGraph($this->variable_use_graph, $this->taint_flow_graph);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Psalm\Type\Atomic\TArray;
use Psalm\Type\Atomic\TArrayKey;
use Psalm\Type\Atomic\TBool;
use Psalm\Type\Atomic\TClosure;
use Psalm\Type\Atomic\TFalse;
use Psalm\Type\Atomic\TFloat;
use Psalm\Type\Atomic\TInt;
Expand Down
5 changes: 5 additions & 0 deletions src/Psalm/Internal/Type/TypeVariableBounds.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
* when the surrounding function-like has been analyzed.
*
* @internal
* @psalm-suppress MissingImmutableAnnotation TypeVariableTracker::addBounds()
* appends to lower_bounds/upper_bounds in place, on purpose: every
* TTypeVariable holding a reference to this object needs to see later
* constraints as they're recorded during analysis.
*/
final class TypeVariableBounds
{
Expand All @@ -24,6 +28,7 @@ final class TypeVariableBounds
/**
* @param list<TemplateBound> $lower_bounds
* @param list<TemplateBound> $upper_bounds
* @psalm-mutation-free
*/
public function __construct(
public array $lower_bounds = [],
Expand Down
5 changes: 5 additions & 0 deletions src/Psalm/Internal/Type/TypeVariableTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ final class TypeVariableTracker

/**
* Mints a fresh type variable name, registering its bound storage.
*
* @psalm-external-mutation-free
*/
public function addVariable(TypeVariableBounds $bounds): string
{
Expand Down Expand Up @@ -80,6 +82,8 @@ public function addBounds(array $lower, array $upper, ?CodeLocation $pos): void
* below. Used where a concrete shape is required (property reads, method
* call returns); the variable itself stays in the object's type params,
* so later uses still constrain it.
*
* @psalm-external-mutation-free
*/
public static function resolveTypeVariables(Union $type, ?Codebase $codebase): Union
{
Expand Down Expand Up @@ -327,6 +331,7 @@ private static function reconcileLowerBoundsWithUpperBounds(
*
* @param list<TemplateBound> $lower_bounds
* @return list<TemplateBound>
* @psalm-mutation-free
*/
private static function getRelevantBounds(array $lower_bounds): array
{
Expand Down
3 changes: 3 additions & 0 deletions src/Psalm/Internal/TypeVisitor/TypeVariableResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ final class TypeVariableResolver extends MutableTypeVisitor
{
public bool $resolved_a_variable = false;

/**
* @psalm-mutation-free
*/
public function __construct(
private readonly ?Codebase $codebase,
) {
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Issue/IncompatibleTypeParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
final class IncompatibleTypeParameters extends CodeIssue
{
public const ERROR_LEVEL = 1;
public const SHORTCODE = 362;
public const SHORTCODE = 368;
}
6 changes: 5 additions & 1 deletion src/Psalm/Type/Atomic/TTypeVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public function getId(bool $exact = true, bool $nested = false): string
}

/**
* @param array<lowercase-string, string> $aliased_classes
* @param array<lowercase-string, string> $aliased_classes
* @psalm-pure
*/
#[Override]
public function toPhpString(
Expand All @@ -78,6 +79,9 @@ public function toPhpString(
return null;
}

/**
* @psalm-pure
*/
#[Override]
public function canBeFullyExpressedInPhp(int $analysis_php_version_id): bool
{
Expand Down
6 changes: 6 additions & 0 deletions tests/Template/TypeVariableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ final class TypeVariableTest extends TestCase
use InvalidCodeAnalysisTestTrait;
use ValidCodeAnalysisTestTrait;

/**
* @psalm-pure
*/
#[Override]
public function providerValidCodeParse(): iterable
{
Expand Down Expand Up @@ -84,6 +87,9 @@ function probe(): void {
];
}

/**
* @psalm-pure
*/
#[Override]
public function providerInvalidCodeParse(): iterable
{
Expand Down
Loading