Skip to content

Commit

Permalink
Revert "Implement identical/equal comparisons on EnumCaseObjectType"
Browse files Browse the repository at this point in the history
This reverts commit 5fc2bfd.
  • Loading branch information
ondrejmirtes committed Dec 13, 2022
1 parent 874f410 commit 11a1039
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 112 deletions.
8 changes: 1 addition & 7 deletions src/Reflection/InitializerExprTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -1303,10 +1303,6 @@ public function resolveIdenticalType(Type $leftType, Type $rightType): BooleanTy
return new ConstantBooleanType($leftType->getValue() === $rightType->getValue());
}

if ($leftType instanceof EnumCaseObjectType && $rightType instanceof EnumCaseObjectType) {
return new ConstantBooleanType($leftType->equals($rightType));
}

$isSuperset = $leftType->isSuperTypeOf($rightType);
if ($isSuperset->no()) {
return new ConstantBooleanType(false);
Expand All @@ -1323,10 +1319,8 @@ public function resolveEqualType(Type $leftType, Type $rightType): BooleanType
{
$integerType = new IntegerType();
$floatType = new FloatType();

if (
($leftType instanceof EnumCaseObjectType && $rightType instanceof EnumCaseObjectType)
|| ($leftType->isString()->yes() && $rightType->isString()->yes())
($leftType->isString()->yes() && $rightType->isString()->yes())
|| ($integerType->isSuperTypeOf($leftType)->yes() && $integerType->isSuperTypeOf($rightType)->yes())
|| ($floatType->isSuperTypeOf($leftType)->yes() && $floatType->isSuperTypeOf($rightType)->yes())
) {
Expand Down
24 changes: 0 additions & 24 deletions tests/PHPStan/Rules/Comparison/IfConstantConditionRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;
use const PHP_VERSION_ID;

/**
* @extends RuleTestCase<IfConstantConditionRule>
Expand Down Expand Up @@ -130,27 +129,4 @@ public function testBug6902(): void
$this->analyse([__DIR__ . '/data/bug-6902.php'], []);
}

public function testBug8485(): void
{
if (PHP_VERSION_ID < 80100) {
$this->markTestSkipped('Test requires PHP 8.1.');
}

$this->treatPhpDocTypesAsCertain = true;
$this->analyse([__DIR__ . '/data/bug-8485.php'], [
[
'If condition is always true.',
19,
],
[
'If condition is always false.',
24,
],
[
'If condition is always false.',
29,
],
]);
}

}
6 changes: 1 addition & 5 deletions tests/PHPStan/Rules/Comparison/MatchExpressionRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,7 @@ public function testEnums(): void
56,
],
[
'Match arm comparison between MatchEnums\Foo::THREE and MatchEnums\Foo::THREE is always true.',
76,
],
[
'Match arm is unreachable because previous comparison is always true.',
'Match arm comparison between *NEVER* and MatchEnums\Foo is always false.',
77,
],
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,37 +607,6 @@ public function testBug8158(): void
$this->analyse([__DIR__ . '/data/bug-8158.php'], []);
}

public function testBug8485(): void
{
if (PHP_VERSION_ID < 80100) {
$this->markTestSkipped('Test requires PHP 8.1.');
}

$this->checkAlwaysTrueStrictComparison = true;
$this->analyse([__DIR__ . '/data/bug-8485.php'], [
[
'Strict comparison using === between Bug8485\E::c and Bug8485\E::c will always evaluate to true.',
17,
],
[
'Strict comparison using === between Bug8485\F::c and Bug8485\E::c will always evaluate to false.',
22,
],
[
'Strict comparison using === between Bug8485\F::c and Bug8485\E::c will always evaluate to false.',
27,
],
[
'Strict comparison using === between Bug8485\F and Bug8485\E will always evaluate to false.',
35,
],
[
'Strict comparison using === between Bug8485\F and Bug8485\E::c will always evaluate to false.',
40,
],
]);
}

public function testPhpUnitIntegration(): void
{
$this->checkAlwaysTrueStrictComparison = true;
Expand Down
45 changes: 0 additions & 45 deletions tests/PHPStan/Rules/Comparison/data/bug-8485.php

This file was deleted.

0 comments on commit 11a1039

Please sign in to comment.