Skip to content

False positive fix for "Remove the '?'"Β #57067

@tenhobi

Description

@tenhobi

If we have code like

UnknownType? getValue() {
  return null;
}

if (getValue() case final valueX?) {
  return Text(valueX);
}

When my UnknownType type is InvalidType because like in cases when maybe imports are wrong, or generated code is not generated, fix (we have auto fix on save) removes the ? while it is NOT CORRECT and will lead to errors when non null expected below.

The fix is there because of this code https://github.com/dart-lang/sdk/blob/main/pkg/analysis_server/lib/src/services/correction/dart/remove_question_mark.dart#L45 which is probably missing some check for InvalidType in which case it should not suggest the fix.


Edit: The same thing for null assert.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onlegacy-area-analyzerUse area-devexp instead.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