Skip to content

Ternary conditional operator does not resolve type properly #2577

Closed as not planned
@yanqui-uxo

Description

@yanqui-uxo

This yields the error A value of type "Object" can't be returned from the function 'func' because it has a return type of 'B'.. This error does not occur using regular conditional syntax (if/else). I am using Dart 2.18.2, and this can be replicated on DartPad.

class A {}

class B {}

class C extends A implements B {}

class D extends A implements B {}

B func(bool b) => b ? C() : D();

Metadata

Metadata

Assignees

No one assigned

    Labels

    least-upper-boundProposals about improvements of the LUB algorithm

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions