Skip to content

Strong mode analyzer incorrectly infers return type of ??= #26023

Closed
@charliereams

Description

@charliereams

The following code should be strong-mode compliant:

class X {}

UnmodifiableListView<X> a = new UnmodifiableListView<X>([]);
Iterable<X> b = null;
Iterable<X> c = (b ??= a);

but the analyzer actually produces the error:

#Unsound implicit cast from Object to Iterable<X> [STRONG_MODE_DOWN_CAST_COMPOSITE]

Note that this very similar (and functionally equivalent) code works fine:

class X {}

List<X> a = new UnmodifiableListView<X>([]);
Iterable<X> b = null;
Iterable<X> c = (b ??= a);

so it seems it's specifically having trouble working out the common subtype of Iterable and UnmodifiableListView. Maybe mix-in related?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions