Skip to content

Genercis can solve to Never with final/sealed classes when it could never resolve #56964

Open
@FMorschel

Description

@FMorschel

If you write code like the following:

void foo() {
  String s1 = bar(0);  // <-- invalid_assignment
  String s2 = baz(0);  // <-- argument_type_not_assignable
}

num bar(num n) => n;

T baz<T extends num?>(T t) => t;

At bar(0) you get the following message:

A value of type 'num' can't be assigned to a variable of type 'String'.
Try changing the type of the variable, or casting the right-hand type to 'String'.

At 0 (inside baz) you get the following message:

The argument type 'int' can't be assigned to the parameter type 'Never'. 

In cases with final/sealed types (like String and num) couldn't we calculate up to invalid_assignment instead of calculating the generics to Never (we could still do that but it would be a bit counter intuitive)?


Edit

Found this in a code that simply returned T without any parameter (it would look somewhere else for the value) and then the problem was happening inside when the return was happening.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).type-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions