Skip to content

Poor diagnostic message when using ?.[] #42762

Open
@bwilkerson

Description

@bwilkerson

Create a file containing the following (invalid) code:

void f(String? s) {
  s?.[0];
}

The use of ?. before an index operator appears to no longer be supported, but the diagnostic message is very confusing. There is only one message generated (on the reference to s inside the body):

error: An expression whose value can be 'null' must be null-checked before it can be dereferenced. (unchecked_use_of_nullable_value at [nnbd_test_package] lib/test.dart:2)

The message should explain to users that they can't use ?. before [] to null-check s.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestanalyzer-recoveryarea-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.area-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.contributions-welcomeContributions welcome to help resolve this (the resolution is expected to be clear from the issue)model-error-recoveryError recovery in analyzer/CFE.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions