Skip to content

[NNBD ] Static Analyzer incorrectly thinks casts will always succeed. #1523

Closed
@esDotDev

Description

@esDotDev

Consider this code:

RenderBox? rb = c.findRenderObject() as RenderBox;
return rb?.size ?? Size.zero;

findRenderObject returns RenderObject?, so clearly rb could be null here, but the compiler is giving a warning:

warning: The receiver can't be null, so the null-aware operator '?.' is unnecessary. (invalid_null_aware_operator at [flutter_folio] lib_utils\context_utils.dart:9)

Compiler seems to think the cast will always succeed, even if the source is a nullable.

Nullable or not, it should not be making this assumption?

Metadata

Metadata

Assignees

No one assigned

    Labels

    requestRequests to resolve a particular developer problem

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions