dart-lang / dart-lang/language

Throw expressions are annoying to use on the right of if-null expressions

Open
#644 5 comments 0 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.