Skip to content

FP: incorrectly detected derived variable bounds in loop #2675

@dktapps

Description

@dktapps

Bug report

Version is 0.12.0

It appears that bounds for the derived variable $i has the bounds applied from the for loop variables.

Code snippet that reproduces the problem

<?php

declare(strict_types=1);

class MyClass{
	public $t = 0;

	public function test() : array{
		$result = [];
		for($xx = 0; $xx <= 2; ++$xx){
			for($zz = 0; $zz <= 2; ++$zz){
				$i = $zz * 3 + $xx;
				if($i === 4){
					continue; //center chunk
				}
				$result[$i] = true;
			}
		}
		return $result;
	}
}

https://phpstan.org/r/a1836aad-4d1e-42df-ad12-f8772c4b2ffb

Expected output

No errors (on level 4, at least).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions