dart-lang / dart-lang/language

Can switch expressions be used in const contexts?

Open
#2,379 6 comments 1 reaction 0 assignees View on GitHub
patterns
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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.