Skip to content

Commit 442fa7f

Browse files
johnniwinthercommit-bot@chromium.org
authored andcommitted
[cfe] Update message for missing default value
Update in response to issue #44329 and to match the change in https://dart-review.googlesource.com/c/sdk/+/174300 Change-Id: Ia28887f0fad54927b82b7aa29acb88231053cd6a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174800 Reviewed-by: Vyacheslav Egorov <[email protected]> Commit-Queue: Johnni Winther <[email protected]>
1 parent 96dc411 commit 442fa7f

File tree

46 files changed

+441
-224
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+441
-224
lines changed

pkg/front_end/lib/src/fasta/fasta_codes_cfe_generated.dart

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3936,7 +3936,9 @@ const Template<
39363936
Message Function(
39373937
String name, DartType _type, bool isNonNullableByDefault)>(
39383938
messageTemplate:
3939-
r"""Optional parameter '#name' should have a default value because its type '#type' doesn't allow null.""",
3939+
r"""The parameter '#name' can't have a value of 'null' because of its type '#type', but the implicit default value is 'null'.""",
3940+
tipTemplate:
3941+
r"""Try adding either an explicit non-'null' default value or the 'required' modifier.""",
39403942
withArguments:
39413943
_withArgumentsOptionalNonNullableWithoutInitializerError);
39423944

@@ -3945,11 +3947,11 @@ const Code<
39453947
Message Function(
39463948
String name, DartType _type, bool isNonNullableByDefault)>
39473949
codeOptionalNonNullableWithoutInitializerError = const Code<
3948-
Message Function(
3949-
String name, DartType _type, bool isNonNullableByDefault)>(
3950-
"OptionalNonNullableWithoutInitializerError",
3951-
templateOptionalNonNullableWithoutInitializerError,
3952-
);
3950+
Message Function(
3951+
String name, DartType _type, bool isNonNullableByDefault)>(
3952+
"OptionalNonNullableWithoutInitializerError",
3953+
templateOptionalNonNullableWithoutInitializerError,
3954+
analyzerCodes: <String>["MISSING_DEFAULT_VALUE_FOR_PARAMETER"]);
39533955

39543956
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
39553957
Message _withArgumentsOptionalNonNullableWithoutInitializerError(
@@ -3961,8 +3963,9 @@ Message _withArgumentsOptionalNonNullableWithoutInitializerError(
39613963
String type = typeParts.join();
39623964
return new Message(codeOptionalNonNullableWithoutInitializerError,
39633965
message:
3964-
"""Optional parameter '${name}' should have a default value because its type '${type}' doesn't allow null.""" +
3966+
"""The parameter '${name}' can't have a value of 'null' because of its type '${type}', but the implicit default value is 'null'.""" +
39653967
labeler.originMessages,
3968+
tip: """Try adding either an explicit non-'null' default value or the 'required' modifier.""",
39663969
arguments: {'name': name, 'type': _type});
39673970
}
39683971

pkg/front_end/messages.status

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,6 @@ OperatorParameterMismatch1/example: Fail
629629
OperatorParameterMismatch2/example: Fail
630630
OperatorWithOptionalFormals/analyzerCode: Fail
631631
OperatorWithOptionalFormals/example: Fail
632-
OptionalNonNullableWithoutInitializerError/analyzerCode: Fail
633-
OptionalNonNullableWithoutInitializerWarning/analyzerCode: Fail
634632
OverrideFewerNamedArguments/example: Fail
635633
OverrideFewerPositionalArguments/example: Fail
636634
OverrideMismatchNamedParameter/example: Fail

pkg/front_end/messages.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4585,7 +4585,9 @@ ValueForRequiredParameterNotProvidedError:
45854585
template: "Required named parameter '#name' must be provided."
45864586

45874587
OptionalNonNullableWithoutInitializerError:
4588-
template: "Optional parameter '#name' should have a default value because its type '#type' doesn't allow null."
4588+
template: "The parameter '#name' can't have a value of 'null' because of its type '#type', but the implicit default value is 'null'."
4589+
tip: "Try adding either an explicit non-'null' default value or the 'required' modifier."
4590+
analyzerCode: MISSING_DEFAULT_VALUE_FOR_PARAMETER
45894591
configuration: nnbd-strong
45904592
script:
45914593
- method1({int a}) {}

pkg/front_end/testcases/general/constants/with_unevaluated_agnostic/various.dart.outline.expect

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ library /*isNonNullableByDefault*/;
2222
// const Class.method(T t) : this(-t);
2323
// ^
2424
//
25-
// pkg/front_end/testcases/general/constants/with_unevaluated_agnostic/various.dart:123:27: Error: Optional parameter 'named' should have a default value because its type 'int' doesn't allow null.
25+
// pkg/front_end/testcases/general/constants/with_unevaluated_agnostic/various.dart:123:27: Error: The parameter 'named' can't have a value of 'null' because of its type 'int', but the implicit default value is 'null'.
26+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
2627
// int procedure(int i, {int named}) => i;
2728
// ^^^^^
2829
//

pkg/front_end/testcases/general/constants/with_unevaluated_agnostic/various.dart.strong.expect

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ library /*isNonNullableByDefault*/;
2222
// const Class.method(T t) : this(-t);
2323
// ^
2424
//
25-
// pkg/front_end/testcases/general/constants/with_unevaluated_agnostic/various.dart:123:27: Error: Optional parameter 'named' should have a default value because its type 'int' doesn't allow null.
25+
// pkg/front_end/testcases/general/constants/with_unevaluated_agnostic/various.dart:123:27: Error: The parameter 'named' can't have a value of 'null' because of its type 'int', but the implicit default value is 'null'.
26+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
2627
// int procedure(int i, {int named}) => i;
2728
// ^^^^^
2829
//

pkg/front_end/testcases/general/constants/with_unevaluated_agnostic/various.dart.strong.transformed.expect

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ library /*isNonNullableByDefault*/;
2222
// const Class.method(T t) : this(-t);
2323
// ^
2424
//
25-
// pkg/front_end/testcases/general/constants/with_unevaluated_agnostic/various.dart:123:27: Error: Optional parameter 'named' should have a default value because its type 'int' doesn't allow null.
25+
// pkg/front_end/testcases/general/constants/with_unevaluated_agnostic/various.dart:123:27: Error: The parameter 'named' can't have a value of 'null' because of its type 'int', but the implicit default value is 'null'.
26+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
2627
// int procedure(int i, {int named}) => i;
2728
// ^^^^^
2829
//

pkg/front_end/testcases/nnbd/issue40954.dart.outline.expect

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,39 @@ library /*isNonNullableByDefault*/;
22
//
33
// Problems in library:
44
//
5-
// pkg/front_end/testcases/nnbd/issue40954.dart:8:31: Error: Optional parameter 'a' should have a default value because its type 'A' doesn't allow null.
5+
// pkg/front_end/testcases/nnbd/issue40954.dart:8:31: Error: The parameter 'a' can't have a value of 'null' because of its type 'A', but the implicit default value is 'null'.
66
// - 'A' is from 'pkg/front_end/testcases/nnbd/issue40954.dart'.
7+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
78
// static void test1(var v, [A a]) {}
89
// ^
910
//
10-
// pkg/front_end/testcases/nnbd/issue40954.dart:10:31: Error: Optional parameter 'a' should have a default value because its type 'A' doesn't allow null.
11+
// pkg/front_end/testcases/nnbd/issue40954.dart:10:31: Error: The parameter 'a' can't have a value of 'null' because of its type 'A', but the implicit default value is 'null'.
1112
// - 'A' is from 'pkg/front_end/testcases/nnbd/issue40954.dart'.
13+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
1214
// static void test2(var v, {A a}) {}
1315
// ^
1416
//
15-
// pkg/front_end/testcases/nnbd/issue40954.dart:12:25: Error: Optional parameter 'a' should have a default value because its type 'A' doesn't allow null.
17+
// pkg/front_end/testcases/nnbd/issue40954.dart:12:25: Error: The parameter 'a' can't have a value of 'null' because of its type 'A', but the implicit default value is 'null'.
1618
// - 'A' is from 'pkg/front_end/testcases/nnbd/issue40954.dart'.
19+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
1720
// void test11(var v, [A a]) {}
1821
// ^
1922
//
20-
// pkg/front_end/testcases/nnbd/issue40954.dart:14:25: Error: Optional parameter 'a' should have a default value because its type 'A' doesn't allow null.
23+
// pkg/front_end/testcases/nnbd/issue40954.dart:14:25: Error: The parameter 'a' can't have a value of 'null' because of its type 'A', but the implicit default value is 'null'.
2124
// - 'A' is from 'pkg/front_end/testcases/nnbd/issue40954.dart'.
25+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
2226
// void test22(var v, {A a}) {}
2327
// ^
2428
//
25-
// pkg/front_end/testcases/nnbd/issue40954.dart:17:22: Error: Optional parameter 'a' should have a default value because its type 'A' doesn't allow null.
29+
// pkg/front_end/testcases/nnbd/issue40954.dart:17:22: Error: The parameter 'a' can't have a value of 'null' because of its type 'A', but the implicit default value is 'null'.
2630
// - 'A' is from 'pkg/front_end/testcases/nnbd/issue40954.dart'.
31+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
2732
// void test1(var v, [A a]) {}
2833
// ^
2934
//
30-
// pkg/front_end/testcases/nnbd/issue40954.dart:19:22: Error: Optional parameter 'a' should have a default value because its type 'A' doesn't allow null.
35+
// pkg/front_end/testcases/nnbd/issue40954.dart:19:22: Error: The parameter 'a' can't have a value of 'null' because of its type 'A', but the implicit default value is 'null'.
3136
// - 'A' is from 'pkg/front_end/testcases/nnbd/issue40954.dart'.
37+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
3238
// void test2(var v, {A a}) {}
3339
// ^
3440
//

pkg/front_end/testcases/nnbd/issue40954.dart.strong.expect

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,39 @@ library /*isNonNullableByDefault*/;
22
//
33
// Problems in library:
44
//
5-
// pkg/front_end/testcases/nnbd/issue40954.dart:8:31: Error: Optional parameter 'a' should have a default value because its type 'A' doesn't allow null.
5+
// pkg/front_end/testcases/nnbd/issue40954.dart:8:31: Error: The parameter 'a' can't have a value of 'null' because of its type 'A', but the implicit default value is 'null'.
66
// - 'A' is from 'pkg/front_end/testcases/nnbd/issue40954.dart'.
7+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
78
// static void test1(var v, [A a]) {}
89
// ^
910
//
10-
// pkg/front_end/testcases/nnbd/issue40954.dart:10:31: Error: Optional parameter 'a' should have a default value because its type 'A' doesn't allow null.
11+
// pkg/front_end/testcases/nnbd/issue40954.dart:10:31: Error: The parameter 'a' can't have a value of 'null' because of its type 'A', but the implicit default value is 'null'.
1112
// - 'A' is from 'pkg/front_end/testcases/nnbd/issue40954.dart'.
13+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
1214
// static void test2(var v, {A a}) {}
1315
// ^
1416
//
15-
// pkg/front_end/testcases/nnbd/issue40954.dart:12:25: Error: Optional parameter 'a' should have a default value because its type 'A' doesn't allow null.
17+
// pkg/front_end/testcases/nnbd/issue40954.dart:12:25: Error: The parameter 'a' can't have a value of 'null' because of its type 'A', but the implicit default value is 'null'.
1618
// - 'A' is from 'pkg/front_end/testcases/nnbd/issue40954.dart'.
19+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
1720
// void test11(var v, [A a]) {}
1821
// ^
1922
//
20-
// pkg/front_end/testcases/nnbd/issue40954.dart:14:25: Error: Optional parameter 'a' should have a default value because its type 'A' doesn't allow null.
23+
// pkg/front_end/testcases/nnbd/issue40954.dart:14:25: Error: The parameter 'a' can't have a value of 'null' because of its type 'A', but the implicit default value is 'null'.
2124
// - 'A' is from 'pkg/front_end/testcases/nnbd/issue40954.dart'.
25+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
2226
// void test22(var v, {A a}) {}
2327
// ^
2428
//
25-
// pkg/front_end/testcases/nnbd/issue40954.dart:17:22: Error: Optional parameter 'a' should have a default value because its type 'A' doesn't allow null.
29+
// pkg/front_end/testcases/nnbd/issue40954.dart:17:22: Error: The parameter 'a' can't have a value of 'null' because of its type 'A', but the implicit default value is 'null'.
2630
// - 'A' is from 'pkg/front_end/testcases/nnbd/issue40954.dart'.
31+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
2732
// void test1(var v, [A a]) {}
2833
// ^
2934
//
30-
// pkg/front_end/testcases/nnbd/issue40954.dart:19:22: Error: Optional parameter 'a' should have a default value because its type 'A' doesn't allow null.
35+
// pkg/front_end/testcases/nnbd/issue40954.dart:19:22: Error: The parameter 'a' can't have a value of 'null' because of its type 'A', but the implicit default value is 'null'.
3136
// - 'A' is from 'pkg/front_end/testcases/nnbd/issue40954.dart'.
37+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
3238
// void test2(var v, {A a}) {}
3339
// ^
3440
//

pkg/front_end/testcases/nnbd/issue40954.dart.strong.transformed.expect

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,39 @@ library /*isNonNullableByDefault*/;
22
//
33
// Problems in library:
44
//
5-
// pkg/front_end/testcases/nnbd/issue40954.dart:8:31: Error: Optional parameter 'a' should have a default value because its type 'A' doesn't allow null.
5+
// pkg/front_end/testcases/nnbd/issue40954.dart:8:31: Error: The parameter 'a' can't have a value of 'null' because of its type 'A', but the implicit default value is 'null'.
66
// - 'A' is from 'pkg/front_end/testcases/nnbd/issue40954.dart'.
7+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
78
// static void test1(var v, [A a]) {}
89
// ^
910
//
10-
// pkg/front_end/testcases/nnbd/issue40954.dart:10:31: Error: Optional parameter 'a' should have a default value because its type 'A' doesn't allow null.
11+
// pkg/front_end/testcases/nnbd/issue40954.dart:10:31: Error: The parameter 'a' can't have a value of 'null' because of its type 'A', but the implicit default value is 'null'.
1112
// - 'A' is from 'pkg/front_end/testcases/nnbd/issue40954.dart'.
13+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
1214
// static void test2(var v, {A a}) {}
1315
// ^
1416
//
15-
// pkg/front_end/testcases/nnbd/issue40954.dart:12:25: Error: Optional parameter 'a' should have a default value because its type 'A' doesn't allow null.
17+
// pkg/front_end/testcases/nnbd/issue40954.dart:12:25: Error: The parameter 'a' can't have a value of 'null' because of its type 'A', but the implicit default value is 'null'.
1618
// - 'A' is from 'pkg/front_end/testcases/nnbd/issue40954.dart'.
19+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
1720
// void test11(var v, [A a]) {}
1821
// ^
1922
//
20-
// pkg/front_end/testcases/nnbd/issue40954.dart:14:25: Error: Optional parameter 'a' should have a default value because its type 'A' doesn't allow null.
23+
// pkg/front_end/testcases/nnbd/issue40954.dart:14:25: Error: The parameter 'a' can't have a value of 'null' because of its type 'A', but the implicit default value is 'null'.
2124
// - 'A' is from 'pkg/front_end/testcases/nnbd/issue40954.dart'.
25+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
2226
// void test22(var v, {A a}) {}
2327
// ^
2428
//
25-
// pkg/front_end/testcases/nnbd/issue40954.dart:17:22: Error: Optional parameter 'a' should have a default value because its type 'A' doesn't allow null.
29+
// pkg/front_end/testcases/nnbd/issue40954.dart:17:22: Error: The parameter 'a' can't have a value of 'null' because of its type 'A', but the implicit default value is 'null'.
2630
// - 'A' is from 'pkg/front_end/testcases/nnbd/issue40954.dart'.
31+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
2732
// void test1(var v, [A a]) {}
2833
// ^
2934
//
30-
// pkg/front_end/testcases/nnbd/issue40954.dart:19:22: Error: Optional parameter 'a' should have a default value because its type 'A' doesn't allow null.
35+
// pkg/front_end/testcases/nnbd/issue40954.dart:19:22: Error: The parameter 'a' can't have a value of 'null' because of its type 'A', but the implicit default value is 'null'.
3136
// - 'A' is from 'pkg/front_end/testcases/nnbd/issue40954.dart'.
37+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
3238
// void test2(var v, {A a}) {}
3339
// ^
3440
//

pkg/front_end/testcases/nnbd/issue40954.dart.weak.expect

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,39 @@ library /*isNonNullableByDefault*/;
22
//
33
// Problems in library:
44
//
5-
// pkg/front_end/testcases/nnbd/issue40954.dart:8:31: Error: Optional parameter 'a' should have a default value because its type 'A' doesn't allow null.
5+
// pkg/front_end/testcases/nnbd/issue40954.dart:8:31: Error: The parameter 'a' can't have a value of 'null' because of its type 'A', but the implicit default value is 'null'.
66
// - 'A' is from 'pkg/front_end/testcases/nnbd/issue40954.dart'.
7+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
78
// static void test1(var v, [A a]) {}
89
// ^
910
//
10-
// pkg/front_end/testcases/nnbd/issue40954.dart:10:31: Error: Optional parameter 'a' should have a default value because its type 'A' doesn't allow null.
11+
// pkg/front_end/testcases/nnbd/issue40954.dart:10:31: Error: The parameter 'a' can't have a value of 'null' because of its type 'A', but the implicit default value is 'null'.
1112
// - 'A' is from 'pkg/front_end/testcases/nnbd/issue40954.dart'.
13+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
1214
// static void test2(var v, {A a}) {}
1315
// ^
1416
//
15-
// pkg/front_end/testcases/nnbd/issue40954.dart:12:25: Error: Optional parameter 'a' should have a default value because its type 'A' doesn't allow null.
17+
// pkg/front_end/testcases/nnbd/issue40954.dart:12:25: Error: The parameter 'a' can't have a value of 'null' because of its type 'A', but the implicit default value is 'null'.
1618
// - 'A' is from 'pkg/front_end/testcases/nnbd/issue40954.dart'.
19+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
1720
// void test11(var v, [A a]) {}
1821
// ^
1922
//
20-
// pkg/front_end/testcases/nnbd/issue40954.dart:14:25: Error: Optional parameter 'a' should have a default value because its type 'A' doesn't allow null.
23+
// pkg/front_end/testcases/nnbd/issue40954.dart:14:25: Error: The parameter 'a' can't have a value of 'null' because of its type 'A', but the implicit default value is 'null'.
2124
// - 'A' is from 'pkg/front_end/testcases/nnbd/issue40954.dart'.
25+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
2226
// void test22(var v, {A a}) {}
2327
// ^
2428
//
25-
// pkg/front_end/testcases/nnbd/issue40954.dart:17:22: Error: Optional parameter 'a' should have a default value because its type 'A' doesn't allow null.
29+
// pkg/front_end/testcases/nnbd/issue40954.dart:17:22: Error: The parameter 'a' can't have a value of 'null' because of its type 'A', but the implicit default value is 'null'.
2630
// - 'A' is from 'pkg/front_end/testcases/nnbd/issue40954.dart'.
31+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
2732
// void test1(var v, [A a]) {}
2833
// ^
2934
//
30-
// pkg/front_end/testcases/nnbd/issue40954.dart:19:22: Error: Optional parameter 'a' should have a default value because its type 'A' doesn't allow null.
35+
// pkg/front_end/testcases/nnbd/issue40954.dart:19:22: Error: The parameter 'a' can't have a value of 'null' because of its type 'A', but the implicit default value is 'null'.
3136
// - 'A' is from 'pkg/front_end/testcases/nnbd/issue40954.dart'.
37+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
3238
// void test2(var v, {A a}) {}
3339
// ^
3440
//

0 commit comments

Comments
 (0)