File tree Expand file tree Collapse file tree 4 files changed +28
-4
lines changed Expand file tree Collapse file tree 4 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -1866,7 +1866,7 @@ class _MockClassInfo {
18661866 _dummyFakedValue (dartType, invocation),
18671867 ExtensionTypeElement2 (: final typeErasure)
18681868 when ! typeErasure.containsPrivateName =>
1869- _dummyValue (typeErasure, invocation),
1869+ _dummyValue (typeErasure, invocation). asA ( _typeReference (dartType)) ,
18701870 ExtensionTypeElement2 () => _dummyValueFallbackToRuntime (
18711871 dartType,
18721872 invocation,
Original file line number Diff line number Diff line change @@ -4180,14 +4180,26 @@ void main() {
41804180
41814181 test ('are supported as return types' , () async {
41824182 await expectSingleNonNullableOutput (
4183- dedent ('''
4183+ dedent ('''
41844184 extension type E(int v) {}
41854185 class Foo {
41864186 E get v;
41874187 }
41884188 ''' ),
4189- decodedMatches (allOf (contains ('E get v' ), contains ('returnValue: 0' ))),
4190- );
4189+ decodedMatches (allOf (
4190+ contains ('E get v' ), contains ('returnValue: (0 as _i2.E)' ))));
4191+ });
4192+
4193+ test ('are supported as Future return types' , () async {
4194+ await expectSingleNonNullableOutput (
4195+ dedent ('''
4196+ extension type E(int v) {}
4197+ class Foo {
4198+ Future<E> get v;
4199+ }
4200+ ''' ),
4201+ decodedMatches (allOf (contains ('_i3.Future<_i2.E> get v' ),
4202+ contains ('returnValue: _i3.Future<_i2.E>.value((0 as _i2.E))' ))));
41914203 });
41924204 });
41934205 group ('build_extensions support' , () {
Original file line number Diff line number Diff line change @@ -74,4 +74,7 @@ class UsesExtTypes {
7474 Ext extTypeReturn (int _) => Ext (42 );
7575 bool privateExtTypeArg (ExtOfPrivate _) => true ;
7676 ExtOfPrivate privateExtTypeReturn (int _) => ExtOfPrivate (private);
77+ Future <Ext > futureExtTypeReturn (int _) => Future .value (Ext (43 ));
78+ Future <ExtOfPrivate > futureExtOfPrivateTypeReturn (int _) =>
79+ Future .value (ExtOfPrivate (private));
7780}
Original file line number Diff line number Diff line change @@ -365,6 +365,15 @@ void main() {
365365 expect (usesExtTypes.extTypeReturn (2 ), equals (Ext (42 )));
366366 expect (usesExtTypes.extTypeReturn (42 ), equals (Ext (0 )));
367367 });
368+
369+ test ('a method using extension type as a return type can be stubbed' ,
370+ () async {
371+ when (usesExtTypes.futureExtTypeReturn (2 ))
372+ .thenAnswer ((_) => Future .value (Ext (42 )));
373+ expect (await usesExtTypes.futureExtTypeReturn (2 ), equals (Ext (42 )));
374+ expect (await usesExtTypes.futureExtTypeReturn (42 ), equals (Ext (0 )));
375+ expect (await usesExtTypes.futureExtTypeReturn (42 ), equals (0 ));
376+ });
368377 });
369378 });
370379
You can’t perform that action at this time.
0 commit comments