sdk icon indicating copy to clipboard operation
sdk copied to clipboard

[Records] CFE doesn't correctly handle ambiguity with on clauses

Open alexmarkov opened this issue 3 years ago • 1 comments

Part of https://github.com/dart-lang/sdk/issues/49713.

According to the spec https://github.com/dart-lang/language/blob/master/accepted/future-releases/records/records-feature-specification.md#ambiguity-with-on-clauses try .. on .. on (a, b) {} should be parsed as try with 2 on clauses. However, front-end incorrectly parses it as try .. on and a local function.

This causes co19/LanguageFeatures/Records/on_clauses_A01_t01 test failure with RuntimeError.

Kernel AST of this test:

    try {
      throw (42, "Lily was here");
    }
    on core::String catch(no-exception-var) {
      exp::Expect::fail("Unexpected String exception");
    }
    function on(core::int i, core::String n) → Null {
      caught = true;
    }

@johnniwinther

alexmarkov avatar Sep 16 '22 20:09 alexmarkov

I know. But considering record types are probably about to get some different syntax (https://github.com/dart-lang/language/issues/2469) it feels like a waste of time to change this.

jensjoha avatar Sep 19 '22 07:09 jensjoha

https://github.com/dart-lang/language/issues/2599 updated the specification, so this is still an issue.

Specifically, this:

main() {
  try {
    print(0);
  } on String {
  } on ([int? i, String? n]) {
//      ^
// [analyzer] unspecified
// [cfe] unspecified
  }
  on();
//^^
// [analyzer] unspecified
// [cfe] unspecified
}

is parsed as: image

scheglov avatar Nov 16 '22 20:11 scheglov

@jensjoha I think there is still work to do here.

scheglov avatar Jan 03 '23 20:01 scheglov

It's in flight (https://dart-review.googlesource.com/c/sdk/+/275922) delayed by the holiday break.

jensjoha avatar Jan 04 '23 08:01 jensjoha