Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5c85200

Browse files
committed
Understand == between ConstantScalarType
1 parent6bf335c commit5c85200

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

‎src/Analyser/MutatingScope.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2358,6 +2358,10 @@ private function resolveEqualType(Type $leftType, Type $rightType): BooleanType
23582358
return$this->resolveIdenticalType($leftType,$rightType);
23592359
}
23602360

2361+
if ($leftTypeinstanceof ConstantScalarType &&$rightTypeinstanceof ConstantScalarType) {
2362+
returnnewConstantBooleanType($leftType->getValue() ==$rightType->getValue());// phpcs:ignore
2363+
}
2364+
23612365
if ($leftTypeinstanceof ConstantArrayType &&$rightTypeinstanceof ConstantArrayType) {
23622366
return$this->resolveConstantArrayTypeComparison($leftType,$rightType,fn ($leftValueType,$rightValueType):BooleanType =>$this->resolveEqualType($leftValueType,$rightValueType));
23632367
}

‎tests/PHPStan/Analyser/data/constant-array-type-identical.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public function doFoo(string $s): void
1515
assertType('false', [1] != [1]);
1616
assertType('false', [1] == [2]);
1717
assertType('true', [1] != [2]);
18-
assertType('bool', [1] == ["1"]);
19-
assertType('bool', [1] != ["1"]);
18+
assertType('true', [1] == ["1"]);
19+
assertType('false', [1] != ["1"]);
2020

2121
assertType('false', [1] === [2]);
2222
assertType('false', [1] !== [1]);

‎tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeMethodCallRuleEqualsTest.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ public function testRule(): void
9292
'Call to method ImpossibleMethodCall\Foo::isNotSame() with array{1, 3} and array{1, 3} will always evaluate to false.',
9393
122,
9494
],
95+
[
96+
'Call to method ImpossibleMethodCall\Foo::isSame() with array{\'a\',\'b\'} and array{1, 2} will always evaluate to false.',
97+
139,
98+
],
99+
[
100+
'Call to method ImpossibleMethodCall\Foo::isNotSame() with array{\'a\',\'b\'} and array{1, 2} will always evaluate to true.',
101+
142,
102+
],
95103
[
96104
'Call to method ImpossibleMethodCall\Foo::isSame() with\'\' and\'\' will always evaluate to true.',
97105
174,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp