Description
Cf. #35673, it is currently not specified that the following is an error:
class A {
final x;
A(p): x = (p) => 42 {}
}
because the initializing expression in a <fieldInitializer>
cannot be a function literal (the problem is that this in some cases introduces the need for an unlimited lookahead, and it's simply confusing for developers because of the syntactic ambiguity of a potentially large amount of code).
We should specify this. It may be possible to relax these rules somewhat, e.g., by noting that (int p)
cannot be an initializer, so x = (int p) { return 42; }
would not have the ambiguity: We definitely need to parse a function literal, and we can see, after a few tokens, that the {...}
is part of that function literal, and then it's required to have a constructor body or a semicolon afterwards. We might also insist that it is an error, because it's still a source of confusion for human readers that we have this big {...}
that might be a constructor body.