-
Notifications
You must be signed in to change notification settings - Fork 166
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
|
||
for (final t in typeParameters) { | ||
final typeVar = _newTypeVar(t); | ||
typeVars[t] = typeVar; | ||
final bound = t.bound; | ||
if (bound != null && bound is analyzer.InterfaceType) { | ||
for (final type in bound.typeArguments) { | ||
final element = type.element; | ||
if (element != null && element is TypeParameterElement) { | ||
typeVars[element] = typeVar; | ||
} | ||
} | ||
} | ||
} | ||
_typeVariableScopes.add(typeVars); | ||
final typeRefsWithBounds = typeParameters.map(_typeParameterReference); | ||
final typeRefs = | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name: mockito | ||
version: 5.4.2 | ||
version: 5.4.3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -wip |
||
description: >- | ||
A mock framework inspired by Mockito with APIs for Fakes, Mocks, | ||
behavior verification, and stubbing. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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! |
||
final mocksContent = await buildWithNonNullable({ | ||
...annotationsAsset, | ||
'foo|lib/foo.dart': dedent(r''' | ||
class Foo<T> {} | ||
abstract class Bar<T> { | ||
Iterable<X> m1<X extends Foo<X>>(X Function(T) f); | ||
} | ||
abstract class FooBar<X> extends Bar<X> {} | ||
'''), | ||
'foo|test/foo_test.dart': ''' | ||
import 'package:foo/foo.dart'; | ||
import 'package:mockito/annotations.dart'; | ||
|
||
@GenerateNiceMocks([ | ||
MockSpec<Foo>(), MockSpec<Bar>(), MockSpec<FooBar>() | ||
]) | ||
void main() {} | ||
''' | ||
}); | ||
expect(mocksContent, contains('class MockBar<T>')); | ||
expect(mocksContent, contains('class MockFooBar<X>')); | ||
expect(mocksContent, | ||
contains('Iterable<X1> m1<X1 extends _i2.Foo<X1>>(X1 Function(X)? f)')); | ||
}); | ||
} | ||
|
||
TypeMatcher<List<int>> _containsAllOf(a, [b]) => decodedMatches( | ||
|
There was a problem hiding this comment.
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