Skip to content

Implement constant evaluation in patterns #50869

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

Closed
chloestefantsova opened this issue Jan 1, 2023 · 2 comments
Closed

Implement constant evaluation in patterns #50869

chloestefantsova opened this issue Jan 1, 2023 · 2 comments
Labels
legacy-area-front-end Legacy: Use area-dart-model instead.

Comments

@chloestefantsova
Copy link
Contributor

The following tests fail due to the absent constant evaluation in patterns:

  • co19/LanguageFeatures/Patterns/constant_A03_t03
  • co19/LanguageFeatures/Patterns/constant_A03_t06
  • co19/LanguageFeatures/Patterns/map_A01_t01
  • co19/LanguageFeatures/Patterns/constant_A03_t07
  • co19/LanguageFeatures/Patterns/constant_A04_t01
  • co19/LanguageFeatures/Patterns/constant_A04_t02

Consider the following program as an example:

String test(List value) {
  if (value case const <int>[1, 2]) {
    return "[1, 2]";
  }
  return "other";
}

main() {
  print(test(const <int>[1, 2]));
}

When complied to Kernel currently, only one of const <int>[1, 2] is represented as a constant.

library /*isNonNullableByDefault*/;
import self as self;
import "dart:core" as core;

static method test(core::List<dynamic> value) → core::String {
  final core::List<dynamic> #t1 = value;
  if(#t1 =={core::List::==}{(core::Object) → core::bool} core::_GrowableList::_literal2<core::int>(1, 2)) {
    {
      return "[1, 2]";
    }
  }
  return "other";
}
static method main() → dynamic {
  core::print(self::test(#C3));
}
constants  {
  #C1 = 1
  #C2 = 2
  #C3 = <core::int*>[#C1, #C2]
}

It prevents the equality to work for constants as expecting, resulting in failing tests. When the program shown above is run, it prints other.

@chloestefantsova chloestefantsova added the legacy-area-front-end Legacy: Use area-dart-model instead. label Jan 1, 2023
@johnniwinther
Copy link
Member

Related to #50629

@johnniwinther
Copy link
Member

This seems to have been fixed together with #50629

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-front-end Legacy: Use area-dart-model instead.
Projects
None yet
Development

No branches or pull requests

2 participants