Skip to content

Commit c8d036f

Browse files
dickermoshesrawlins
authored andcommitted
allow duplicate typedefs
1 parent 1dafb54 commit c8d036f

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

lib/src/builder.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ $rawOutput
173173
void addTypesFrom(analyzer.DartType type) {
174174
// Prevent infinite recursion.
175175
if (seenTypes.contains(type)) {
176+
if (type.alias != null) {
177+
// To check for duplicate typdefs that have different names
178+
type.alias!.element.accept(typeVisitor);
179+
}
176180
return;
177181
}
178182
seenTypes.add(type);

test/builder/auto_mocks_test.dart

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3583,8 +3583,7 @@ void main() {
35833583
expect(mocksContent, contains('implements _i2.Baz'));
35843584
});
35853585

3586-
test(
3587-
'when a type parameter is a typedef a function which returns another type',
3586+
test('when its a type parameter of function which returns another type',
35883587
() async {
35893588
final mocksContent = await buildWithNonNullable({
35903589
...annotationsAsset,
@@ -3610,6 +3609,34 @@ void main() {
36103609
'''
36113610
});
36123611

3612+
expect(mocksContent, contains('class MockFoo extends _i1.Mock'));
3613+
expect(mocksContent, contains('implements _i2.Foo'));
3614+
});
3615+
test('when its a duplicate type parameter', () async {
3616+
final mocksContent = await buildWithNonNullable({
3617+
...annotationsAsset,
3618+
'foo|lib/foo.dart': dedent(r'''
3619+
class Bar {}
3620+
typedef BarDef = int Function();
3621+
typedef BarDef2 = int Function();
3622+
class BaseFoo<T,P> {
3623+
BaseFoo(this.t1, this.t2);
3624+
final T t1;
3625+
final P t2;
3626+
}
3627+
class Foo extends BaseFoo<BarDef, BarDef2> {
3628+
Foo() : super(() => 1, () => 2);
3629+
}
3630+
'''),
3631+
'foo|test/foo_test.dart': '''
3632+
import 'package:foo/foo.dart';
3633+
import 'package:mockito/annotations.dart';
3634+
3635+
@GenerateMocks([Foo])
3636+
void main() {}
3637+
'''
3638+
});
3639+
36133640
expect(mocksContent, contains('class MockFoo extends _i1.Mock'));
36143641
expect(mocksContent, contains('implements _i2.Foo'));
36153642
});

0 commit comments

Comments
 (0)