dart-lang / dart-lang/language
Throw expressions are annoying to use on the right of if-null expressions
Open
request
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
I know that this is rather fussy, but I stumble across this so often that I'm wondering if there's something that could be done about this in the language.
I'd like to write
```dart
var x = y ?? throw SomeError();
```
I have to write
```dart
var x = y ?? (throw SomeError());
```
This is a very common pattern to deal with nullable values and I'm not sure why `throw` has such a low precedence. Something like `var x = y != null ? y : throw SomeError()` is not a syntax error either.
Contributor guide
Assessment
This issue has not been assessed yet.