dart-lang / dart-lang/language
[void, patterns] castPatterns take a `type` not a `typeNotVoid`
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
I've noticed that castPatterns accept void on their rhs. However, the rhs of typeCasts does not i.e.:

https://github.com/dart-lang/sdk/blob/4751ed0bb8675402c66d530b99fff94e327e175c/tools/spec_parser/Dart.g#L1073-L1075
https://github.com/dart-lang/sdk/blob/4751ed0bb8675402c66d530b99fff94e327e175c/tools/spec_parser/Dart.g#L1031-L1033
Here's the relevant section in the feature specification: [cast pattern](https://github.com/dart-lang/language/blob/master/accepted/future-releases/0546-patterns/feature-specification.md#cast-pattern)
I'm wondering, wouldn't it make sense to make castPatterns also not take `void` on their rhs or are there use cases where it would make sense to make castPatterns support casting to void? (_of course, a typedef can be used to cast to void, this is more about consistency to prevent questions like 'why can I do X but not Y?'_)
Contributor guide
Research direction
Start with the linked Dart.g definitions for castPatterns and typeCasts, then read the cast pattern section of the linked feature specification. Determine whether the grammar should consistently reject void on the right-hand side and check for documented use cases. Done means the specification and parser grammar agree on the accepted type.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100