Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sgrekhov opened this issue Dec 15, 2023 · 1 comment
Closed

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

sgrekhov opened this issue Dec 15, 2023 · 1 comment
Assignees
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. feature-extension-types Implementation of the extension type feature P1 A high priority bug; for example, a single project is unusable or has many test failures type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@sgrekhov
Copy link
Contributor

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
@sgrekhov sgrekhov added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. feature-extension-types Implementation of the extension type feature labels Dec 15, 2023
@lrhn lrhn added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Dec 15, 2023
@keertip keertip added the P3 A lower priority bug or feature request label Dec 15, 2023
@scheglov scheglov self-assigned this Dec 20, 2023
@scheglov scheglov added P1 A high priority bug; for example, a single project is unusable or has many test failures and removed P3 A lower priority bug or feature request labels Dec 20, 2023
@scheglov
Copy link
Contributor

copybara-service bot pushed a commit that referenced this issue Dec 20, 2023
… always exhaustive.

Bug: #54370
Bug: #54421
Change-Id: Iebd64c413f489ac12b1a8d56a987ad44df00534e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/342729
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. feature-extension-types Implementation of the extension type feature P1 A high priority bug; for example, a single project is unusable or has many test failures type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants