-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
new NSM forwarding logic breaks Mockito #33031
Comments
…pull all logic into CFE.""" This reverts commit 9a7e1f6 as it breaks mockito tests and commit 0bc6e72 as being done for 9a7e1f6. Bug: #33031 Change-Id: Id20a83c8a7a62ec73446180ecb37e9200f3a92b6 Reviewed-on: https://dart-review.googlesource.com/53540 Reviewed-by: Alexander Aprelev <aam@google.com>
Closed via 2765fcf |
Thanks, @aam |
The behavior of the I'm not sure what causes Mockito's issue here - it should get equivalent It is correct that you can no longer make a mock act differently depending on whether an optional parameter is omitted, or it is provided with the same value as the default value. A real Dart method could never detect that (apart from a short period where we didn't know better), so the mock should still be perfectly capable of emulating any valid behavior. So, we will have to reapply this fix to make nSM forwarders do the correct thing. |
This is complicated to follow. I think this is what happened in order:
We do intend to implement the intended behavior (almost by definition) so I think we will have to change Mockito. |
I'll look into how Mockito can handle this fix. I expect that the code of Mockito users will have to change, which means we'll need a few weeks or months runway. I'll comment here when I know more. |
Also note that such a breaking change would block rolls of the SDK into google3 (and hence Flutter) until those changes in user code could be made (ie, I'm not sure at all that this change can be made for Dart 2). |
For discussion on how/whether Mockito can work with this proposed change, I've opened dart-lang/mockito#122. |
Honest question, was 7d5025e written because like, some package that uses I think we have a workable solution for Mockito, but it definitely makes Mockito less usable. Is there a net benefit? Does some other package become more usable, or possible? |
I did some sleuthing internally.
Of the remaining cases, I mostly see stuff like: noSuchMethod(_) {}
noSuchMethod(_) => null;
noSuchMethod(_) => throw new UnimplementedError(); So I agree with @dgrove and @srawlins this change should be, at best, suspended until after Dart2 (Dart3). Mockito is basically the most used case for nSM, followed by the following three patterns above. |
And, I see Mockito used over 30K times. So... Not volunteering for that migration :) |
My 2c: this change seems an obviously correct one that makes things noticeably better. The only question is how to feasibly roll it out. |
@tvolkert Correct behavior aside if this will block us for weeks/months it isn't the right change today. |
This should be classified as a language change and the decision is then a language team decision. If migration is unlikely - then we should amend Dart 2 specification making the current behavior "the specified" behavior. /cc @leafpetersen @lrhn |
I also figured out what was wrong with my CL (forgot to pass edit: thanks for the test case @leafpetersen showing the problem :) |
Just to make sure I understand the current state of things: it sounds like we're going to be able to re-land 7d5025e unmodified because we found viable workarounds in mockito (that comes with a workable migration path) and DDC? |
I think it will be reverting https://dart-review.googlesource.com/c/sdk/+/53540 ... it looks like there maybe have been some small tweaks to the CL to keep buildbots happy, but otherwise I presume it's almost the same code as 7d5025e, yes. mockito has a workaround and DDC has an implementation (we're still testing, but it seems like it's close) |
Unfortunately we can't land 7d5025e just yet due to a few failures on precompiled bots. Please let me know when I can re-land it with fixes. |
@sjindel-google - is your fix ready to go if we decide to go forward with the new semantics? The overnight internal run looks promising - ~10 test failures. @srawlins - what do you think? |
Yes, the fix is ready and the revision is approved. I'm just wait for the go-ahead. |
The internally tested CL (195908155) includes @srawlins's Mockito fix and @jmesserly's DDC implementation. So, rolling forwarding means:
Are we missing anything? Is there a chance something will break in Flutter or internal Flutter apps? Are the VM AOT/JIT and Dart2JS all covered by Samir's fix? |
I don't know if Dart2JS will be covered, but I expect so since we inject concrete methods. In your list above, the Mockito fix and updating internal tests needs to be done first, right? |
Yes, I think we'll need the Mockito fix landed and rolled into Flutter and internal. |
Thanks! I added check boxes to the initial comment at top so we can track. |
@srawlins - are we still waiting on the flutter roll? |
Landed in flutter. nSM Forwarding is cool to land in the SDK. |
Thanks, Sam! @sjindel-google and @jmesserly - can you please land your impl CLs? |
yeah I tried, it failed for a status issue (it needs test fixes from @sjindel-google 's CL). Trying CQ again w/ that test temporarily marked failing in DDC (we can mark passing once CFE CL lands). |
FYI the DDC tracking bug is #33019 for status updates. |
@jmesserly , see quite a few test failures in DDC internally after your commit, testing at commit
@srawlins, do we need an update to mockito package to fix these? |
@keertip Yes we need to update mockito to fix those. |
Should I still land the VM side? |
@sjindel-google - yes, please. :-) |
… (Take 2) The behavioral difference is that named and optional arguments are filled in with their default values in the `Invocation` object passed to `noSuchMethod`. On the implementation side we make NSM forwarders concrete and fill in their bodies in the CFE. The custom (and somewhat hacky) VM support is no longer needed, and Dart2JS can benefit from this implementation as well. According to discussion on #33031 we will be able to re-land this soon without breaking Mockito. Prior failures on precompiler bots are fixed in Patchset 2. Change-Id: If1b7fe4cf6da5ef38f330e1ad226121bcfc958a1 Reviewed-on: https://dart-review.googlesource.com/54401 Commit-Queue: Samir Jindel <sjindel@google.com> Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
@sjindel-google and @jmesserly - are we done on the implementation side? |
Yes. |
@srawlins - are you unblocked from fixing those ~10 tests? @leafpetersen @lrhn - how should this change be communicated? |
Yes, I can fix them when we roll >=dev.56 internally. |
@srawlins - thanks! @leafpetersen is working on how to communicate this as part of overall NSM changes. I'll go ahead and close this bug. |
Open items to move forward:
@sjindel-google 's 7d5025e breaks how Mockito works. Given
The user should now be able to stub out
eatFood
like so:However, Mock's noSuchMethod receives something different after 7d5025e: it used to receive an Invocation with 1 positional argument, and 0 named arguments. Now it receives the 1 positional argument, and the 1 named argument (with the default value specified by the parameter). The presence of arguments or lack thereof, in the Invocation passed to noSuchMethod is core to Mockito's implementation.
This is blocking the current Flutter roll (flutter/flutter#17230), as Flutter has some affected tests. This will also block the SDK roll into internal Google, as we use Mockito.
I also imagine this is just... a big breaking change to how NSM works. I wouldn't be surprised if this broke other tools that depend on NSM functionality.
I think this change must be rolled back ASAP, to unblock Flutter. We can then discuss whether the change is possible for Dart 2.
Related to #33019
CC @sjindel-google @keertip @tvolkert @yjbanov
The text was updated successfully, but these errors were encountered: