dart-lang / dart-lang/language
Can switch expressions be used in const contexts?
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
The [introduction to switch expressions](https://github.com/dart-lang/language/blob/master/working/0546-patterns/patterns-feature-specification.md#switch-expression) briefly compares them to conditional expressions, which are allowed in const contexts. Are switch expressions?
E.g. this is legal and I imagine useful.
```dart
const a = 1;
const b = 2;
const c = a == b ? 3 : 4;
```
Contributor guide
Research direction
Read the linked switch-expression section in patterns-feature-specification.md and compare its const-context rules with the conditional-expression behavior described in the issue. Determine whether the example should be supported, then update the relevant language documentation or specification text so the answer and expected usage are explicit.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- compilers
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100