Skip to content

Warnign "Type not assignable to same type" when in a default part of switch statement #3298

@terrylucas

Description

@terrylucas

This is a weird bug:

  switch (a) {
    case 1:
      return new ReturnValue(2012, f.fetch);
    default:
      return new ReturnValue(2012, f.fetch);
  }

The statement inside of case 1 works however the same statement inside of the default generates the warning

      () -> String is not assignable to String

Here's a small sample, note: If BaseValue doesn't exist and Return value contains both int n and String s everything works find.

  class Foobar {
    String value;

    Foobar() {
      value = "testit";
    }
    String get fetch() => value;
  }

  class BaseValue {
    String s;
    BaseValue(this.s);
  }

  class ReturnValue extends BaseValue {
    int n;
    ReturnValue(this.n, String s) : super(s);
  }

  class test {
    testit(int a) {
      Foobar f = new Foobar();
      switch (a) {
        case 1:
          return new ReturnValue(2012, f.fetch);
        default:
          return new ReturnValue(2012, f.fetch);
      }
    }
  }

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions