Skip to content

Returning a Future<ExtensionType> generates invalid code #801

Open
@xvrh

Description

@xvrh
import 'package:mockito/annotations.dart';

class Foo {
  Future<Id> bar() async => Id(0);
}

extension type Id(int id) {}

@GenerateNiceMocks([MockSpec<Foo>()])
class Test {}

Will generate

class MockFoo extends _i1.Mock implements _i2.Foo {
  @override
  _i3.Future<_i2.Id> bar() =>
      (super.noSuchMethod(
            Invocation.method(#bar, []),
            returnValue: _i3.Future<_i2.Id>.value(0),
            returnValueForMissingStub: _i3.Future<_i2.Id>.value(0),
          )
          as _i3.Future<_i2.Id>);
}

and error: The argument type 'int' can't be assigned to the parameter type 'FutureOr<Id>?'. (argument_type_not_assignable at [mock] test/mock.mocks.dart:34)

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