-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Inconsistent behaviour when getter that returns a function is called with/without .call()
#48635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
.call
.call
.call()
@daadu, thanks for the concise stand-alone example, that's always a great way to point to the exact topic of interest! The getter So I'll transfer this to the SDK repository. We may need to reconsider this particular rule, however, if it turns out to be a significantly breaking change. At least, we'd have to run it via a breaking change process. |
It looks like a change that could give rise to a rather small amount of breakage (because getters returning functions could be a somewhat esoteric design choice), but based on the fact that it just changes the order of evaluation it might cause some really subtle bugs that aren't noticed for a while. And, of course, it might also break a lot of code, who knows. I can see that the actual arguments are evaluated before the getter with @johnniwinther, we have had discussions about the evaluation order of similar constructs previously. What do you think? And is it true that this decision is made by the CFE (for all or some configurations)? @sigmundch, @mkustermann, WDYT? |
Just for note, I discovered it when writing test("dynamic stubbing", () async {
// arrange
final connectivityPlugin = setUpMockPlugin("dev.fluttercommunity.plus/connectivity");
final checkStub = connectivityPlugin.stubFor.call(await Connectivity().checkConnectivity());
checkStub.toResult((call) async => "mobile");
// act
final result = await Connectivity().checkConnectivity();
// assert
expect(result, ConnectivityResult.mobile);
checkStub.verify.calledOnce();
}); Here, the I think similar mechanism is done by |
Just discussed the matter with @johnniwinther, confirming that this topic has been an issue for several years, and there is no easy path to "just fix it", but we are in a better position to do it than we used to be (because various stages of the compilation process have more type information available today). We'll discuss how to deal with it, but it is likely to take some time. |
See previous discussion here as well. |
Also here. |
Discussion of the state of the implementations as of 2019 here. |
Dart-pad demo: https://dartpad.dev/?id=a0f88b47e1d05bd8f2347442f867de84
When a "getter" returns a function - depending on how it is called -
obj.adder(fetchNum())
vsobj.adder.call(fetchNum())
- the execution-path is different, check the demo link above.This is an inconsistent behaviour, when the getter has a side-effect.
PS: Not sure if this is a bug or feature (as intended). According to me, it is a bug - since the behaviour is inconsitent.
The text was updated successfully, but these errors were encountered: