Skip to content
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

Can't stub generic function with nested function param of unknown type #476

Closed
AlexandrKedrov opened this issue Sep 18, 2021 · 1 comment
Assignees
Labels
type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@AlexandrKedrov
Copy link

Code:

abstract class Foo {
    T? foo<T>(Map<String, T Function()> options);
}

T? fooShim<T>(Map<String, T Function()>? options> {
    return null;
}

@GenerateMocks([], customMocks[
    MockSpec<Foo>(fallbackGenerators: {#foo: fooShim})
])
...

Error:

Invalid @GenerateMocks annotation: Mockito cannot generate a valid mock class which implements 'Foo' for the following reasons:
    The method 'Foo.foo' features a non-nullable unknown return type, and cannot be stubbed without a dummy generator specified on the MockSpec.

Call stack:
image

Problem is that neither hasFallbackGenerator nor isParameter passed to the second _checkFunction call.

As stubbing generic function with Map<> or T Function() should work(at least I hope so according to the current implementation), it is ambiguous their composition causes any trouble

@srawlins srawlins added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Sep 19, 2021
@srawlins
Copy link
Member

Thanks for the bug report and the initial investigation!

@srawlins srawlins self-assigned this Sep 19, 2021
srawlins added a commit that referenced this issue Feb 8, 2022
…function types

Fixes #476

PiperOrigin-RevId: 424888004
mosuem pushed a commit to dart-lang/test that referenced this issue Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

2 participants