Skip to content

NNBD: Map [] operator accepts null even when keys are non-nullable #58427

@rrousselGit

Description

@rrousselGit

Consider the following:

void main() {
  var map = <String, String>{};

  map[null];
}

The current behavior is, map[null] compiles (and return null)

I would expect it to emit a compilation error instead.


This appears to be voluntary, considering ma[null] = correctly does not compile.

Maybe we should have a lint?

Metadata

Metadata

Assignees

No one assigned

    Labels

    devexp-linterIssues with the analyzer's support for the linter packagelegacy-area-analyzerUse area-devexp instead.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions