Skip to content

False positive for increment operator (regression added in 3.14.1) #4011

@kubawerlos

Description

@kubawerlos

Hello,

for a code:

$counter = 0;
for ($i = 0; $i < 100; $i++) {
    if ($i % 2 === 0) {
        $counter++;
        continue;
    }
    if ($counter > 0) {
        $counter--;
    }
}

These errors are reported in 3.14.1:

INFO: MixedOperand - 6:9 - Left operand cannot be mixed
INFO: MixedAssignment - 6:9 - Unable to determine the type that $counter is being assigned to
INFO: MixedOperand - 10:9 - Left operand cannot be mixed
INFO: MixedAssignment - 10:9 - Unable to determine the type that $counter is being assigned to

(https://psalm.dev/r/c7397874df)

Removing continue makes the errors go away, but it should not matter.

It was introduced in 3.14.1, was fine in 3.13.1 (see).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions