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

Missing prefix for Type object in generated .mocks.dart #382

Closed
gysipos opened this issue Apr 12, 2021 · 1 comment
Closed

Missing prefix for Type object in generated .mocks.dart #382

gysipos opened this issue Apr 12, 2021 · 1 comment
Assignees
Labels
P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@gysipos
Copy link

gysipos commented Apr 12, 2021

The generated code imports everything as _inumber, but it forgets to add the prefix for the Type decratation of the implemented file.

So for an annotation like this:
@GenerateMocks([], customMocks: [MockSpec<Foo<Bar>>()])

the generated Class declaration looks like this:
class MockFoo extends _i1.Mock implements _i2.Foo<Bar>
and i get The name 'Bar' isn't a type so it can't be used as a type argument.

it should generate :
@GenerateMocks([], customMocks: [MockSpec<Foo<_i3.Bar>>()])

since it imports Bar as _i3

i'm on mockito: ^5.0.3

@srawlins
Copy link
Member

Good catch. Working on a fix now.

@srawlins srawlins added P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Apr 12, 2021
@srawlins srawlins self-assigned this Apr 12, 2021
srawlins added a commit that referenced this issue Apr 12, 2021
Fixes #382

All imports in mockito's generated code use import prefixes, and so a prefix always needs to be attached to a reference to a library element (like a class).

Forgetting a URL has been the source of multiple bugs, so this change includes a broader refactor as well to hide code_builder's `refer` function, and instead provide our own.

PiperOrigin-RevId: 368050695
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

2 participants