dart-lang / dart-lang/language

if null expression, analyzer need enhanced type verification

Open
#4,639 3 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

```
class Agent {
late int id;
late String name;

Agent.fromJson(Map json) {
id = json['id'] ?? 0;
name = json['name'] ?? '';
}
}
```

When the previous data type is `dynamic`, analyzer can't check that the type of 0 and 'name' match properly;
`json['name ']` or `0` is finally assigned to `name`. Wouldn't it be better if `json['name']` and `0` were verified with `name` respectively? `json['name']` is `dynamic`, so it will not be verified, but `0` is not, then, the verification of `name` and `0` can not be ignored.

Contributor guide

Open the contributing guide

Research direction

Start with the supplied Agent.fromJson example and reproduce the analyzer's current diagnostics for the ?? expression. No files or tests are named, so first identify the relevant language specification rule and analyzer tests. Done means the intended verification behavior for the non-dynamic fallback is defined and covered by tests.

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
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.