Skip to content

dynamic type association raise warning when using null-safety #58411

@Jictyvoo

Description

@Jictyvoo

When doing an operation like

var a = 'foo';
final b = <String, dynamic>{'bar' : 'foo-bar'};
a = b['bar'];

This operation should raise a null warning or error. Sometimes, when this map can be outside the function, the programmer can know received types, but as a dynamic type the linter should show a warning or error about null when using null-safety.

Examples

class A {
    final String field;
    A.fromJson(Map<String, dynamic> json):  field = json['foo-bar'];
}

In above example, you can't know if field decoded in json is null or not.
Maybe can be a new rule that can be added in analysis_options.yaml

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.linter-lint-proposaltype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions