[ TypeChecker ] False positive on uncomparable types in switch statements
- Dominant language
- C++
- Stars
- 18.7k
- Forks
- 3.1k
- Avg merge
- 1h 47m
- Merged PRs (30d)
- 2
Description
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
I am forced to check for null before switching over an object type.
When I switch over a nullable object, I get told that comparing `MyObjectType` == `?MyObjectType` will not have the expected result.
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
Can't the typechecker assume that non scalar types are fine to compare with a nullable thing?
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
Putting
```HACK
if ($value_to_be_switched_over is null) {
// the null case
} else {
switch($the_value_to_be_switched_over) {
case ...
```
**Additional context**
Add any other context or screenshots about the feature request here.
```
Typing[4280] Switch statements use == equality, so comparing values of type MyObjectType with ?MyObjectType may not give the desired result.
--> file.php
10 | case $non_nullable:
| ^^^^^^^^^^^^^^^^^^^^^
1 error found.
```
The objects I am switching over can be compared by identity in the same way they are comapre using equality (there are never two objects that share all properties, but have different hashcodes).
We might want to **NOT** tackle this, since the `==` switch is going away.
Contributor guide
Assessment
This issue has not been assessed yet.