You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The problem here is that the parser has a hard time distinguishing function bodies in the initializer list from a constructor body.
It's not impossible, but it's hard enough that Dart has so far not allowed unparenthesized function-expressions in initializer lists.
The example here is easier because there is no argument, but
Foo(x) : bar = (x) { print(x); };
requires arbitrary look-ahead to see whether the {print(x)} is a function body or a constructor body. (It's probably a function body because of the trailing ;).
I'm not sure the grammar reflects this restriction. @eernstg?
This restriction has been part of Dart since 2013 (cf. dart-lang/sdk#11509), but the language specification does not mention it, and never did. This PR finally adds it.
Seems like Dart analysis gets confused when using assignment initializer with anonymous functions. For instance:
When wrapping the function in parenthesis, the error goes away:
I'm not sure whether this behavior is expected, but I cannot see any reason why it should be.
The text was updated successfully, but these errors were encountered: