Skip to content

Incorrect type in mocks with analyzer 5.x #612

@stuartmorgan-g

Description

@stuartmorgan-g

We're having a strange issue with mockito generating the wrong types in webview_flutter_android when trying to update analyzer. I have tried to make a minimal repro case, but haven't been able to recreate the problem so far so filing with what I have for now.

STR:

  1. git clone https://github.com/flutter/packages
  2. cd packages/packages/webview_flutter/webview_flutter_android
  3. Edit pubspec.yaml to change the pigeon dependency to pigeon: ^9.0.0. (This allows analyzer to resolve to 5.7.1 instead of 4.x.) then flutter pub get
  4. flutter pub run build_runner build --delete-conflicting-outputs
  5. flutter test test/android_webview_test.dart

The test fails to compile:

 Error: The return type of the method 'MockWebView.getScrollPosition' is
'Future<dynamic>', which does not match the return type, 'Future<Offset>', of the overridden method,
'WebView.getScrollPosition'.
 - 'Future' is from 'dart:async'.
 - 'Offset' is from 'dart:ui'.
Change to a subtype of 'Future<Offset>'.
  _i4.Future<dynamic> getScrollPosition() => (super.noSuchMethod(
                      ^
lib/src/android_webview.dart:331:18: Context: This is the overridden method ('getScrollPosition').
  Future<Offset> getScrollPosition() {
                 ^

There are similar problems with a Future<Size>.

If you skip step 3, everything is fine, and the generated code has the correct type. Comparing the lock files, it's just analyzer that changes between them (and pigeon of course, but I'm not re-running Pigeon generation, so its version is irrelevant).

I tried adding Offset to the @GenerateMocks list in android_webview_test.dart to see if that would help, and that causes (with 5.x only): Invalid @GenerateMocks annotation: The GenerateMocks "classes" argument is missing, includes an unknown type, or includes an extension.

I made a simple project that just has a class with a Future<Offset> method in it, and couldn't reproduce this, but I haven't yet been able to figure out what the important difference is.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions