Skip to content

Commit 09782c8

Browse files
srawlinscopybara-github
authored andcommitted
Resolve for typedefs/aliases and records in typeArguments & resolve duplicate typedefs
#776 Closes: #775 Closes: #777 Closes: #778 The fix for these issues is closely related so I've done both of them in a single PR. - Mockito wasn't checking for typedefs/aliases in `typeArguments` - it also wasn't looking into records on type args. - Typedefs which had the same underlying type were ignored even if the typedef had a different name These issues cause the dreaded `is missing from the asset URI mapping` error. See the related issue for a repro of each of these. I've also added regression tests for all of these. PiperOrigin-RevId: 702712435
1 parent dbc9302 commit 09782c8

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

lib/src/builder.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,22 +181,22 @@ $rawOutput
181181
}
182182
seenTypes.add(type);
183183

184-
if (type.element?.library case var library?) {
184+
if (type.element?.library case final library?) {
185185
librariesWithTypes.add(library);
186186
}
187-
if (type.alias?.element.library case var library?) {
187+
if (type.alias?.element.library case final library?) {
188188
librariesWithTypes.add(library);
189189
}
190190

191191
type.element?.accept(typeVisitor);
192192
type.alias?.element.accept(typeVisitor);
193193
switch (type) {
194-
case analyzer.InterfaceType interface:
194+
case final analyzer.InterfaceType interface:
195195
interface.typeArguments.forEach(addTypesFrom);
196196
interface.allSupertypes.forEach(addTypesFrom);
197-
case analyzer.RecordType record:
197+
case final analyzer.RecordType record:
198198
record.positionalTypes.forEach(addTypesFrom);
199-
record.namedTypes.map((e) => e.type).forEach(addTypesFrom);
199+
record.namedFields.map((e) => e.type).forEach(addTypesFrom);
200200
}
201201
}
202202

test/builder/auto_mocks_test.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3589,20 +3589,17 @@ void main() {
35893589
'foo|lib/foo.dart': dedent(r'''
35903590
class Bar {}
35913591
typedef CreateBar = Bar Function();
3592-
35933592
class BaseFoo<T> {
35943593
BaseFoo(this.t);
35953594
final T t;
35963595
}
3597-
35983596
class Foo extends BaseFoo<CreateBar> {
35993597
Foo() : super(() => 1);
36003598
}
36013599
'''),
36023600
'foo|test/foo_test.dart': '''
36033601
import 'package:foo/foo.dart';
36043602
import 'package:mockito/annotations.dart';
3605-
36063603
@GenerateMocks([Foo])
36073604
void main() {}
36083605
'''
@@ -3631,7 +3628,6 @@ void main() {
36313628
'foo|test/foo_test.dart': '''
36323629
import 'package:foo/foo.dart';
36333630
import 'package:mockito/annotations.dart';
3634-
36353631
@GenerateMocks([Foo])
36363632
void main() {}
36373633
'''

0 commit comments

Comments
 (0)