dart-lang / dart-lang/language
Equality argument context type `_`?
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
I just noticed a tiny discrepancy, for a day where nobody is busy doing important things. ;-) Consider the following program:
```dart
class A {
operator ==(covariant A other) => true;
get hashCode => 0;
}
X getContextType(Object? o) {
print(X);
return o as X;
}
void main() {
A() == getContextType(A());
}
```
This program has no compile-time errors, it runs, and it prints 'dynamic'.
It seems likely that this could be caused by using a context type of `_` for the right hand operand of `==`, even in the case where the statically known type of the formal parameter of `==` is different from `Object`. Perhaps it would be better to use the context type `A?`, where `A` is the type of the formal parameter of `==`.
Contributor guide
Assessment
This issue has not been assessed yet.