Skip to content

Fix code generation error on nested generic bounded type arguments #659

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

Closed

Conversation

KholmatovS
Copy link

@KholmatovS KholmatovS commented Jun 19, 2023

Fixes #658 code generation error on nested generic bounded type arguments.


  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.

@KholmatovS KholmatovS changed the title fix: nested bounded type arguments Fix code generation error on nested generic bounded type arguments Jun 19, 2023
Copy link
Contributor

@yanok yanok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some feedback on your code, but generally I'd like to hear from the analyzer team first.

@@ -1,3 +1,7 @@
## 5.4.3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be 5.4.3-wip

@@ -1,5 +1,5 @@
name: mockito
version: 5.4.2
version: 5.4.3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-wip

@@ -2051,7 +2051,20 @@ class _MockClassInfo {

T _withTypeParameters<T>(Iterable<TypeParameterElement> typeParameters,
T Function(Iterable<TypeReference>, Iterable<TypeReference>) body) {
final typeVars = {for (final t in typeParameters) t: _newTypeVar(t)};
final Map<TypeParameterElement, String> typeVars = {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I wrote on the bug, I think it would be more logical to fix the equality on the analyzer side, if possible. Then, this won't be needed.

But even as a workaround, it has a few problems:

  1. It won't catch cases with more than one level of wrapping, like T extends Foo<Bar<T>>.
  2. It will create a wrong mapping for other type variables appearing in the bound, like
    class C<T> {
      X m<X extends Iterable<T>>() => [];
    }

@@ -1843,6 +1843,32 @@ void main() {
expect(mocksContent, contains('Iterable<X1> m1<X1>(X1 Function(X)? f)'));
expect(mocksContent, contains('Iterable<X1?> m2<X1>(X1 Function(X)? f)'));
});

test('We preserve nested generic bounded type arguments', () async {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the test! Could you please try adding test cases to cover the items in my comment above? Thanks!

@yanok
Copy link
Contributor

yanok commented Jul 5, 2023

Closing this in favor of #671

@yanok yanok closed this Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Code generation error on nested generic bounded type arguments
2 participants