Skip to content

[CFE] List pattern without "rest elements" should match lists of exact length #50797

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
alexmarkov opened this issue Dec 20, 2022 · 0 comments
Closed
Assignees
Labels
legacy-area-front-end Legacy: Use area-dart-model instead.

Comments

@alexmarkov
Copy link
Contributor

Part of #49749.
This is the reason for the runtime error on co19/LanguageFeatures/Patterns/logical_and_A03_t02 test.

Example:

main() {
  var x = [1, 2];
  if (x case [1]) {
    print('Bug!');
  } else {
    print('OK');
  }
}

Kernel:

  static method main() → dynamic {
    core::List<core::int> x = core::_GrowableList::_literal2<core::int>(1, 2);
    final core::List<core::int> #t1 = x;
    final core::bool #t2 = true;
    final core::List<core::int> #t3 = #t1;
    if(#t3.{core::List::length}{core::int}.{core::num::>=}(1){(core::num) → core::bool}) {
      final dynamic #t4 = #t3{core::List<dynamic>}.{core::List::[]}(0){(core::int) → dynamic};
      if(#t4 =={core::Object::==}{(core::Object) → core::bool} 1) {
        #t2 = false;
        {
          core::print("Bug!");
        }
      }
    }
    if(#t2) {
      core::print("OK");
    }
  }

Note that the list pattern incorrectly checks if x.length >= 1 and not x.length == 1.

/cc @johnniwinther @chloestefantsova

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