dart-lang / dart-lang/language
What if postfix "!" operator was the "implicit operator"?
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
I was looking at some examples produced by the Dart team around how non-nullability and NNBD will work out, including (but not limited to) the interaction between non-nullability and implicit casting (https://github.com/dart-lang/sdk/issues/31410).
See also https://github.com/dart-lang/language/issues/193, which I think this proposal could replace.
As far as I understand, the (postfix) `a!` means roughly:
* Promote `a`'s type `T`, or `T?` to `T` if the runtime type of `a` is non-null
* If the runtime type of `a` is `null`, throw `NullError` (or whatever the error is)
More or less, `a!` could be emulated using `(a as T`), when NNBD is enabled. If that's the case, it feels like `a!` is "implicitly cast to the non-null type, if able". What if instead of #193, postfix `!` was just the implicit cast operator:
```dart
void example(Map json) {
String name = json['name']; // ERROR: Downcast.
String name = json['name']!; // OK
}
```
Contributor guide
Research direction
Start by reading the Dart NNBD context in the linked SDK issue 31410 and language issue 193, then compare the proposed postfix `!` behavior with the examples in this issue. Done would require a resolved language-design decision and corresponding specification changes; no implementation files or tests are named.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100