mockito icon indicating copy to clipboard operation
mockito copied to clipboard

`fallbackGenerators` are actually called from real calls

Open yanok opened this issue 3 years ago • 2 comments

The documentation for fallbackGenerators says:

The fallback values will never be returned from a real member call; these are not stub return values. They are only used internally by mockito as valid return values.

... but the actual generated code has

returnValueForMissingStub: _i10.getShim<T>(flag)

(where getShim is my fallback generator), so it does actually call fallback generator if the stub is missing and returns values to the caller. I've seen people even relying on this ;(

So, should we fix the doc or the behavior?

yanok avatar Nov 18 '22 15:11 yanok

I believe @emmanuel-p added this in https://github.com/dart-lang/mockito/commit/5d23067c044a8b7687cfa24252ff6e498f35e4b7 (I approved). If I remember, the justification at the time was that this helped move null safety migrations along (maybe specifically in sound mode).

I don't have a strong opinion on fixing the docs or changing the behavior.

srawlins avatar Nov 18 '22 16:11 srawlins

Right, G3 relies on this now, I guess we have to fix the docs.

yanok avatar May 25 '23 12:05 yanok