Skip to content
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

[bug] Generic typedef on Functions breaks builder #775

Open
dickermoshe opened this issue Oct 28, 2024 · 1 comment · May be fixed by #776
Open

[bug] Generic typedef on Functions breaks builder #775

dickermoshe opened this issue Oct 28, 2024 · 1 comment · May be fixed by #776

Comments

@dickermoshe
Copy link

dickermoshe commented Oct 28, 2024

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

  • Dart 3.5.3 (stable) (Wed Sep 11 16:22:47 2024 +0000) on "windows_x64"
  • on windows / "Windows 10 Pro for Workstations" 10.0 (Build 22631)
  • locale is en-US

Project info

  • sdk constraint: '^3.5.3'
  • dependencies:
  • dev_dependencies: build_runner, lints, mockito

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant