dart-lang / mockito

Mockito-inspired mock library for Dart
https://pub.dev/packages/mockito
Apache License 2.0
636 stars 163 forks source link

[bug] Generic typedef on Functions breaks builder #775

Open dickermoshe opened 3 weeks ago

dickermoshe commented 3 weeks ago

A very very strange bug. A whole bunch of things must happen to trigger this bug

mockito: 5.4.4

// A typedef of any function Function
typedef CreateInt = int Function();

// A base class which uses a generic
class BaseFoo<T> {
  BaseFoo(this.t);
  // The class uses the generic and it's not nullable
  final T t;
}
// Class which extends the base class and uses super()
class Foo extends BaseFoo<CreateInt> {
  Foo() : super(() => 1);
}

Console:

Resolving dependencies in `C:\Users\dicke\DickerSystems\repromockito`... 
Downloading packages...
Got dependencies in `C:\Users\dicke\DickerSystems\repromockito`.
Building package executable... (2.3s)
Built build_runner:build_runner.
[INFO] Generating build script completed, took 183ms
[INFO] Precompiling build script... completed, took 2.3s
[INFO] Building new asset graph completed, took 462ms
[INFO] Checking for unexpected pre-existing outputs. completed, took 1ms
[INFO] Generating SDK summary completed, took 2.8s
[SEVERE] mockito:mockBuilder on test/repromockito_test.dart:

Bad state: Asset URI is missing for typedef CreateInt = dynamic Function()
package:mockito/src/builder.dart 2195:10                     _MockClassInfo._typeImport
package:mockito/src/builder.dart 2154:19                     _MockClassInfo._typeReference.<fn>
package:code_builder/src/specs/type_reference.g.dart 164:33  _$TypeReferenceBuilder.update
package:code_builder/src/specs/type_reference.g.dart 22:36   new _$TypeReference
package:mockito/src/builder.dart 2151:14                     _MockClassInfo._typeReference
package:mockito/src/builder.dart 1910:25                     _MockClassInfo._buildOverridingGetter
package:mockito/src/builder.dart 1224:36                     _MockClassInfo.fieldOverrides.<fn>
package:code_builder/src/specs/method.g.dart 323:33          _$MethodBuilder.update
package:code_builder/src/specs/method.g.dart 38:29           new _$Method
package:mockito/src/builder.dart 1224:15                     _MockClassInfo.fieldOverrides
dart:core                                                    List.addAll
package:built_collection/src/list/list_builder.dart 98:14    ListBuilder.addAll
package:mockito/src/builder.dart 1182:28                     _MockClassInfo._buildMockClass.<fn>.<fn>
package:mockito/src/builder.dart 2070:24                     _MockClassInfo._withTypeParameters
package:mockito/src/builder.dart 1135:7                      _MockClassInfo._buildMockClass.<fn>
package:code_builder/src/specs/class.g.dart 345:33           _$ClassBuilder.update
package:code_builder/src/specs/class.g.dart 40:28            new _$Class
package:mockito/src/builder.dart 1113:12                     _MockClassInfo._buildMockClass
package:mockito/src/builder.dart 1059:9                      new _MockLibraryInfo
package:mockito/src/builder.dart 94:29                       MockBuilder.build

[INFO] Running build completed, took 3.1s
[INFO] Caching finalized dependency graph completed, took 26ms
[SEVERE] Failed after 3.1s

repro: https://github.com/dickermoshe/repromockito

General info

Project info

Process info

Memory CPU Elapsed time Command line
21 MB -- dart.exe
78 MB -- dart.exe
37 MB -- dart.exe
21 MB -- dart.exe
19 MB -- dart.exe
81 MB -- dart.exe
37 MB -- dart.exe
21 MB -- dart.exe
18 MB -- dart.exe
23 MB -- dart.exe
722 MB -- dart.exe
101 MB -- dart.exe
dickermoshe commented 3 weeks ago

I've traced this down to the fact that calling supertype.typeArguments returns an unwrapped version of the typedef (BaseFoo<int Function()>), instead of the typedef itself BaseFoo<CreateInt>.

So during analysis CreateInt is not added to the types.