sdk icon indicating copy to clipboard operation
sdk copied to clipboard

Cascading and callable

Open Solido opened this issue 1 year ago • 1 comments
trafficstars

  • Dart analyzer and linter

Callable is not compatible with cascading.

In my case it is used as an init() lifecycle but I want to keep the reference of the A instance.

If force 2 lines declaration and it's surprising to have to make a direct reference to call.

Thanks!

void main() {
  A()..call('OK');
  A()..('Fail');
}

class A {
  
  call(String s) {
    ...
  }
}

Solido avatar Aug 28 '24 00:08 Solido

Summary: The Dart analyzer and linter flag an error when using the call method with cascading syntax. This is because the call method is not compatible with cascading, which leads to unexpected behavior and forces users to write code in a less concise way.

dart-github-bot avatar Aug 28 '24 00:08 dart-github-bot

Correct, you have to use .call. Same for o?.call(...).

The latter has advantages over o?(...) in the it doesn't conflict with the conditional operator so easily.

There are no current plans to allow (...) after a .. or ?.. Definitely not after ?., and probably not after just one of them either.

lrhn avatar Aug 28 '24 14:08 lrhn

It saddens me but they're reasons and these are the specs. Thanks!

Solido avatar Aug 28 '24 14:08 Solido