Skip to content

type promotion failing with assignment expression with some branching / ternary expressions #61506

@mmcdon20

Description

@mmcdon20

Consider the following code.

Iterable<num> a(Iterable<num>? i) => i = (true ? <int>[] : <double>[]); // promotion works
Iterable<num> b(Iterable<num>? i) => i = (true ? <int>[] : <int>{});    // promotion works
Iterable<num> c(Iterable<num>? i) => i = (true ? <int>[] : <double>{}); // promotion fails!

Here functions a and b compile and run as expected, however function c results in an error.

A value of type 'Iterable<num>?' can't be returned from the function 'c' because it has a return type of 'Iterable<num>'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.model-inferenceImplementation of type inference

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions