Skip to content

Commit

Permalink
Automated g4 rollback of changelist 471719348.
Browse files Browse the repository at this point in the history
*** Reason for rollback ***

Rolling forward after fixes

*** Original change description ***

Automated g4 rollback of changelist 471650729.

*** Reason for rollback ***

Breaks GPay tap (pay.flutter.tap)

https://fusion2.corp.google.com/ci;ids=1912127488/tap/pay.flutter.tap/activity/471652072/targets

*** Original change description ***

Include `required` keyword in functions used as default return values.

***

***

PiperOrigin-RevId: 472723817
  • Loading branch information
srawlins committed Sep 14, 2022
1 parent b33ce96 commit 04b74f1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Allow generating a mock class which includes overriding members with private
types in their signature. Such members cannot be stubbed with mockito, and
will only be generated when specified in MockSpec `unsupportedMembers`.
* Include `required` keyword in functions used as default return values.

## 5.3.0

Expand Down
7 changes: 6 additions & 1 deletion lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1492,7 +1492,11 @@ class _MockClassInfo {
superParameterType: parameter.type, defaultName: '__p$position');
b.optionalParameters.add(matchingParameter);
position++;
} else if (parameter.isNamed) {
} else if (parameter.isOptionalNamed) {
final matchingParameter =
_matchingParameter(parameter, superParameterType: parameter.type);
b.optionalParameters.add(matchingParameter);
} else if (parameter.isRequiredNamed) {
final matchingParameter =
_matchingParameter(parameter, superParameterType: parameter.type);
b.optionalParameters.add(matchingParameter);
Expand Down Expand Up @@ -1595,6 +1599,7 @@ class _MockClassInfo {
_typeReference(superParameterType, forceNullable: forceNullable);
}
if (parameter.isNamed) pBuilder.named = true;
if (parameter.isRequiredNamed) pBuilder.required = true;
if (parameter.defaultValueCode != null) {
try {
pBuilder.defaultTo = _expressionFromDartObject(
Expand Down
19 changes: 18 additions & 1 deletion test/builder/auto_mocks_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1524,7 +1524,7 @@ void main() {
void m({required covariant int a});
}
'''),
_containsAllOf('void m({num? a}) => super.noSuchMethod('),
_containsAllOf('void m({required num? a}) => super.noSuchMethod('),
);
});

Expand Down Expand Up @@ -2455,6 +2455,23 @@ void main() {
);
});

test(
'creates a dummy non-null function-typed return value, with required '
'named parameters', () async {
await expectSingleNonNullableOutput(
dedent(r'''
abstract class Foo {
void Function(Foo, {required bool b}) m();
}
'''),
_containsAllOf('''
returnValue: (
_i2.Foo __p0, {
required bool b,
}) {},'''),
);
});

test(
'creates a dummy non-null function-typed return value, with non-core '
'return type', () async {
Expand Down

0 comments on commit 04b74f1

Please sign in to comment.