sdk
sdk copied to clipboard
[Records] CFE doesn't correctly handle ambiguity with on clauses
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
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.
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:

@jensjoha I think there is still work to do here.
It's in flight (https://dart-review.googlesource.com/c/sdk/+/275922) delayed by the holiday break.