dart-lang / dart-lang/language

Null safety flow analysis on nullable object fields

Open
#1,722 3 comments 1 reaction 0 assignees View on GitHub
field-promotion
Dominant language
TeX
Stars
2.9k
Forks
239
Avg merge
2d 18h
Merged PRs (30d)
14

Description

I'm interested in the flow analysis of nullable object fields. The problem is that it is not actually working so I'm wondering if this is an issue or a design decision.

Flutter + Dart version:

[✓] Flutter (Channel stable, 2.2.0, on macOS 11.4 20F71 darwin-x64, locale en-GB)
• Flutter version 2.2.0 at /Users/kiko.balaj/Documents/flutter
• Framework revision b22742018b (7 weeks ago), 2021-05-14 19:12:57 -0700
• Engine revision a9d88a4d18
• Dart version 2.13.0

## Example

```
class Foo {
final String? a;

Foo(this.a);
}

void bar(Foo myObj) {
if (myObj.a != null) {
print(myObj.a?.length);
}
}
```

The issue is in the `bar` method. In my opinion, in the `print` argument there doesn't have to be the questionmark operator after the `myObj.a` because I've already checked `myObj.a != null`.

Thanks for the response!

Contributor guide

Open the contributing guide

Research direction

Start with the nullable-field example in the issue and reproduce the `bar` method behavior using the reported Dart 2.13.0 and Flutter 2.2.0 versions. Read the language project's null-safety flow-analysis design and discussion to determine whether repeated field reads may be promoted; done means the behavior is resolved as either a documented design decision or a specified language change.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.