dart-lang / dart-lang/language
[void] Make `typeTest`s and `typeCast`s support full `type`s
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
[typeTests](https://github.com/dart-lang/sdk/blob/4751ed0bb8675402c66d530b99fff94e327e175c/tools/spec_parser/Dart.g#L1023-L1025) and [typeCasts](https://github.com/dart-lang/sdk/blob/4751ed0bb8675402c66d530b99fff94e327e175c/tools/spec_parser/Dart.g#L1031-L1033) do not support `void` on their rhs.
This is useful because it makes little sense to test for or cast to a void type. However, this syntactical limitation can be circumvented using typedefs (`typedef Void = void;`) so this limitation offers no useful guarantees.
Erik provides some historical context [here](https://github.com/dart-lang/language/issues/2897#issuecomment-1463884349).
I'd like to propose for this limitation to be lifted i.e. to support `type`s on the rhs of `typeTest`s and the rhs of `typeCast`s instead of `type`s that exclude `void`s.
A `castPattern` feels very much like a `typeTest`, but it is intended to support `void` on its rhs while a `typeTest` doesn't. I think it is easier to "master" and use a system (i.e. Dart) if one doesn't have to keep track of low value edge cases like e.g.: 'you can't use void here to the right of this is, but you can use it here to the right of this is'. Lifting this restriction to make both `castPattern`s and `typeTest`s be syntactically identical would remove this edge case and make Dart easier to learn and master.
Contributor guide
Research direction
Start with the linked Dart.g grammar rules for typeTests and typeCasts, then compare them with the castPattern behavior described in the issue. Review Erik's linked historical context and determine the specification changes needed for void on the right-hand side; done means the language-design proposal has a clear resolution.
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
- 30/100