-
Notifications
You must be signed in to change notification settings - Fork 461
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ObjectType - fix enum property with subtracted type
- Loading branch information
1 parent
53c643d
commit eb00fd2
Showing
5 changed files
with
141 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php // lint >= 8.1 | ||
|
||
namespace Bug8486; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
enum Operator: string | ||
{ | ||
case Foo = 'foo'; | ||
case Bar = 'bar'; | ||
case None = ''; | ||
|
||
public function explode(): void | ||
{ | ||
$character = match ($this) { | ||
self::None => 'baz', | ||
default => $this->value, | ||
}; | ||
|
||
assertType("'bar'|'baz'|'foo'", $character); | ||
} | ||
|
||
public function typeInference(): void | ||
{ | ||
match ($this) { | ||
self::None => 'baz', | ||
default => assertType('$this(Bug8486\Operator~Bug8486\Operator::None)', $this), | ||
}; | ||
} | ||
|
||
public function typeInference2(): void | ||
{ | ||
if ($this === self::None) { | ||
return; | ||
} | ||
|
||
assertType("'Bar'|'Foo'", $this->name); | ||
assertType("'bar'|'foo'", $this->value); | ||
} | ||
} | ||
|
||
class Foo | ||
{ | ||
|
||
public function doFoo(Operator $operator) | ||
{ | ||
$character = match ($operator) { | ||
Operator::None => 'baz', | ||
default => $operator->value, | ||
}; | ||
|
||
assertType("'bar'|'baz'|'foo'", $character); | ||
} | ||
|
||
public function typeInference(Operator $operator): void | ||
{ | ||
match ($operator) { | ||
Operator::None => 'baz', | ||
default => assertType('Bug8486\Operator~Bug8486\Operator::None', $operator), | ||
}; | ||
} | ||
|
||
public function typeInference2(Operator $operator): void | ||
{ | ||
if ($operator === Operator::None) { | ||
return; | ||
} | ||
|
||
assertType("'Bar'|'Foo'", $operator->name); | ||
assertType("'bar'|'foo'", $operator->value); | ||
} | ||
|
||
public function typeInference3(Operator $operator): void | ||
{ | ||
if ($operator === Operator::None) { | ||
return; | ||
} | ||
|
||
if ($operator === Operator::Foo) { | ||
return; | ||
} | ||
|
||
assertType("Bug8486\Operator::Bar", $operator); | ||
assertType("'Bar'", $operator->name); | ||
assertType("'bar'", $operator->value); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters