dart-lang / dart-lang/language
Expand "is" for Types
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
In the following code:
```dart
void main() async {
MyClass c = MyClass();
print(c is MyInterface); // prints true
print(MyClass is MyInterface); // prints false
print(MyClass is MyClass); // prints false
}
class MyClass implements MyInterface {
String s;
}
class MyInterface {
String s;
}
```
`MyClass` implements `MyInterface` but I can't test this with `is` directly using types, only with a variable.
Since Dart generics are very limited on multiple inheritance bounds, I was trying to make my code more secure by adding checks like following before doing some operations:
```dart
assert(V is MyInterface);
```
But since I don't have an actual variable of type `V` to test (I am searching a value using the type V as the key), this code throws an exception.
Contributor guide
Research direction
Start with the issue's Dart examples and compare the behavior of `is` on an instance with the proposed checks on `MyClass` and type parameter `V`. Determine the intended semantics and constraints for testing type relationships without a value; done would require an agreed language-design direction or specification change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100