Skip to content

[analyzer] Exhaustiveness is not supported for extension types #54370

Closed
@sgrekhov

Description

@sgrekhov

The following test works in CFE but fails in analyzer

// SharedOptions=--enable-experiment=inline-class

import "../../Utils/expect.dart";

enum E {
  a, b, c
}

extension type ET1(E _) {}
extension type ET2(E _) implements E {}

String testStatement1(ET1 e) { // COMPILE_TIME_ERROR.BODY_MIGHT_COMPLETE_NORMALLY  The body might complete normally, causing 'null' to be returned, but the return type, 'String', is a potentially non-nullable type.
  switch (e) {
    case E.a:
    case E.b:
    case E.c:
      return "ok";
  }
}

String testStatement2(ET2 e) { // COMPILE_TIME_ERROR.BODY_MIGHT_COMPLETE_NORMALLY  The body might complete normally, causing 'null' to be returned, but the return type, 'String', is a potentially non-nullable type.

  switch (e) {
    case E.a:
    case E.b:
      return "ok1";
    case E.c:
      return "ok2";
  }
}

String testExpression1(ET1 e) => // Ok, works
  switch (e) {
    E.a => "a",
    E.b => "b",
    E.c => "c"
  };

String testExpression2(ET2 e) => // Ok, works
  switch (e) {
    E.a => "a",
    E.b => "b",
    E.c => "c"
  };

main() {
  Expect.equals("ok", testStatement1(ET1(E.a)));
  Expect.equals("ok", testStatement1(ET1(E.b)));
  Expect.equals("ok", testStatement1(ET1(E.c)));
  Expect.equals("a", testExpression1(ET1(E.a)));
  Expect.equals("a", testExpression1(ET1(E.b)));
  Expect.equals("c", testExpression1(ET1(E.c)));

  Expect.equals("ok1", testStatement2(ET2(E.a)));
  Expect.equals("ok1", testStatement2(ET2(E.b)));
  Expect.equals("ok2", testStatement2(ET2(E.c)));
  Expect.equals("a", testExpression2(ET2(E.a)));
  Expect.equals("b", testExpression2(ET2(E.b)));
  Expect.equals("c", testExpression2(ET2(E.c)));
}

co19 tests that fails

co19/LanguageFeatures/Extension-types/exhaustiveness_enum_A01_t01
co19/LanguageFeatures/Extension-types/exhaustiveness_enum_A01_t02
co19/LanguageFeatures/Extension-types/exhaustiveness_enum_A01_t03
co19/LanguageFeatures/Extension-types/exhaustiveness_enum_A01_t04
co19/LanguageFeatures/Extension-types/exhaustiveness_enum_A01_t05

Metadata

Metadata

Assignees

Labels

P1A high priority bug; for example, a single project is unusable or has many test failuresfeature-extension-typesImplementation of the extension type featurelegacy-area-analyzerUse area-devexp instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions