Skip to content

Commit 63fbfcc

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Translate InvalidInlineFunctionType to ParserErrorCode.INVALID_INLINE_FUNCTION_TYPE.
[email protected], [email protected] Change-Id: I2b1c7938c081b771e554149846c8157f8332e061 Bug: #33398 Reviewed-on: https://dart-review.googlesource.com/74043 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Dan Rubel <[email protected]>
1 parent ef72098 commit 63fbfcc

File tree

7 files changed

+55
-33
lines changed

7 files changed

+55
-33
lines changed

pkg/analyzer/lib/error/error.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ const List<ErrorCode> errorCodeValues = const [
176176
CompileTimeErrorCode.INVALID_INITIALIZER,
177177
CompileTimeErrorCode.INVALID_MODIFIER_ON_CONSTRUCTOR,
178178
CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER,
179+
CompileTimeErrorCode.INVALID_INLINE_FUNCTION_TYPE,
179180
CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS,
180181
CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST,
181182
CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP,

pkg/analyzer/lib/src/error/codes.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,6 +1488,12 @@ class CompileTimeErrorCode extends ErrorCode {
14881488
"The name of a factory constructor must be the same as the name of "
14891489
"the immediately enclosing class.");
14901490

1491+
static const CompileTimeErrorCode INVALID_INLINE_FUNCTION_TYPE =
1492+
const CompileTimeErrorCode('INVALID_INLINE_FUNCTION_TYPE',
1493+
"Inline function types cannot be used for parameters in a generic function type.",
1494+
correction:
1495+
"Try using a generic function type (returnType 'Function(' parameters ')').");
1496+
14911497
/**
14921498
* 12.10 This: It is a compile-time error if this appears in a top-level
14931499
* function or variable initializer, in a factory constructor, or in a static

pkg/analyzer/lib/src/fasta/error_converter.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,10 @@ class FastaErrorReporter {
324324
length,
325325
[type1, type2]);
326326
return;
327+
case "INVALID_INLINE_FUNCTION_TYPE":
328+
errorReporter?.reportErrorForOffset(
329+
CompileTimeErrorCode.INVALID_INLINE_FUNCTION_TYPE, offset, length);
330+
return;
327331
case "INVALID_LITERAL_IN_CONFIGURATION":
328332
errorReporter?.reportErrorForOffset(
329333
ParserErrorCode.INVALID_LITERAL_IN_CONFIGURATION, offset, length);

pkg/analyzer/test/generated/parser_test.dart

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -908,27 +908,27 @@ Function(int, String) v;
908908
expect(method.body, isNotNull);
909909
}
910910

911-
void test_parseClassMember_method_get_type() {
912-
createParser('int get() {}');
911+
void test_parseClassMember_method_get_static_namedAsClass() {
912+
createParser('static int get C => 0;');
913913
ClassMember member = parser.parseClassMember('C');
914914
expect(member, isNotNull);
915915
assertNoErrors();
916916
expect(member, new TypeMatcher<MethodDeclaration>());
917917
MethodDeclaration method = member;
918918
expect(method.documentationComment, isNull);
919919
expect(method.externalKeyword, isNull);
920-
expect(method.modifierKeyword, isNull);
921-
expect(method.propertyKeyword, isNull);
920+
expect(method.modifierKeyword, isNotNull);
921+
expect(method.propertyKeyword, isNotNull);
922922
expect(method.returnType, isNotNull);
923923
expect(method.name, isNotNull);
924924
expect(method.operatorKeyword, isNull);
925925
expect(method.typeParameters, isNull);
926-
expect(method.parameters, isNotNull);
926+
expect(method.parameters, isNull);
927927
expect(method.body, isNotNull);
928928
}
929929

930-
void test_parseClassMember_method_get_void() {
931-
createParser('void get() {}');
930+
void test_parseClassMember_method_get_type() {
931+
createParser('int get() {}');
932932
ClassMember member = parser.parseClassMember('C');
933933
expect(member, isNotNull);
934934
assertNoErrors();
@@ -946,36 +946,17 @@ Function(int, String) v;
946946
expect(method.body, isNotNull);
947947
}
948948

949-
void test_parseClassMember_method_get_static_namedAsClass() {
950-
createParser('static int get C => 0;');
951-
ClassMember member = parser.parseClassMember('C');
952-
expect(member, isNotNull);
953-
assertNoErrors();
954-
expect(member, new TypeMatcher<MethodDeclaration>());
955-
MethodDeclaration method = member;
956-
expect(method.documentationComment, isNull);
957-
expect(method.externalKeyword, isNull);
958-
expect(method.modifierKeyword, isNotNull);
959-
expect(method.propertyKeyword, isNotNull);
960-
expect(method.returnType, isNotNull);
961-
expect(method.name, isNotNull);
962-
expect(method.operatorKeyword, isNull);
963-
expect(method.typeParameters, isNull);
964-
expect(method.parameters, isNull);
965-
expect(method.body, isNotNull);
966-
}
967-
968-
void test_parseClassMember_method_set_static_namedAsClass() {
969-
createParser('static void set C(_) {}');
949+
void test_parseClassMember_method_get_void() {
950+
createParser('void get() {}');
970951
ClassMember member = parser.parseClassMember('C');
971952
expect(member, isNotNull);
972953
assertNoErrors();
973954
expect(member, new TypeMatcher<MethodDeclaration>());
974955
MethodDeclaration method = member;
975956
expect(method.documentationComment, isNull);
976957
expect(method.externalKeyword, isNull);
977-
expect(method.modifierKeyword, isNotNull);
978-
expect(method.propertyKeyword, isNotNull);
958+
expect(method.modifierKeyword, isNull);
959+
expect(method.propertyKeyword, isNull);
979960
expect(method.returnType, isNotNull);
980961
expect(method.name, isNotNull);
981962
expect(method.operatorKeyword, isNull);
@@ -1195,6 +1176,25 @@ void Function<A>(core.List<core.int> x) m() => null;
11951176
expect(method.body, isNotNull);
11961177
}
11971178

1179+
void test_parseClassMember_method_set_static_namedAsClass() {
1180+
createParser('static void set C(_) {}');
1181+
ClassMember member = parser.parseClassMember('C');
1182+
expect(member, isNotNull);
1183+
assertNoErrors();
1184+
expect(member, new TypeMatcher<MethodDeclaration>());
1185+
MethodDeclaration method = member;
1186+
expect(method.documentationComment, isNull);
1187+
expect(method.externalKeyword, isNull);
1188+
expect(method.modifierKeyword, isNotNull);
1189+
expect(method.propertyKeyword, isNotNull);
1190+
expect(method.returnType, isNotNull);
1191+
expect(method.name, isNotNull);
1192+
expect(method.operatorKeyword, isNull);
1193+
expect(method.typeParameters, isNull);
1194+
expect(method.parameters, isNotNull);
1195+
expect(method.body, isNotNull);
1196+
}
1197+
11981198
void test_parseClassMember_method_set_type() {
11991199
createParser('int set() {}');
12001200
ClassMember member = parser.parseClassMember('C');
@@ -3948,6 +3948,15 @@ class Wrong<T> {
39483948
expectNotNullIfNoErrors(literal);
39493949
}
39503950

3951+
void test_invalidInlineFunctionType() {
3952+
parseCompilationUnit(
3953+
'typedef F = int Function(int a());',
3954+
errors: [
3955+
expectedError(CompileTimeErrorCode.INVALID_INLINE_FUNCTION_TYPE, 30, 1)
3956+
],
3957+
);
3958+
}
3959+
39513960
void test_invalidInterpolationIdentifier_startWithDigit() {
39523961
StringLiteral literal = parseExpression("'\$1'", errors: [
39533962
usingFastaParser

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4647,7 +4647,9 @@ const Code<Null> codeInvalidInlineFunctionType =
46474647
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
46484648
const MessageCode messageInvalidInlineFunctionType = const MessageCode(
46494649
"InvalidInlineFunctionType",
4650-
message: r"""Invalid inline function type.""",
4650+
analyzerCode: "INVALID_INLINE_FUNCTION_TYPE",
4651+
message:
4652+
r"""Inline function types cannot be used for parameters in a generic function type.""",
46514653
tip:
46524654
r"""Try changing the inline function type (as in 'int f()') to a prefixed function type using the `Function` keyword (as in 'int Function() f').""");
46534655

pkg/front_end/messages.status

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ InvalidCatchArguments/example: Fail
211211
InvalidContinueTarget/analyzerCode: Fail
212212
InvalidContinueTarget/example: Fail
213213
InvalidInitializer/example: Fail
214-
InvalidInlineFunctionType/analyzerCode: Fail
215214
InvalidPackageUri/analyzerCode: Fail
216215
InvalidPackageUri/example: Fail
217216
InvalidUseOfNullAwareAccess/example: Fail

pkg/front_end/messages.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,8 +1035,9 @@ GeneratorReturnsValue:
10351035
analyzerCode: RETURN_IN_GENERATOR
10361036

10371037
InvalidInlineFunctionType:
1038-
template: "Invalid inline function type."
1038+
template: "Inline function types cannot be used for parameters in a generic function type."
10391039
tip: "Try changing the inline function type (as in 'int f()') to a prefixed function type using the `Function` keyword (as in 'int Function() f')."
1040+
analyzerCode: INVALID_INLINE_FUNCTION_TYPE
10401041
declaration: "typedef F = Function(int f(String x));"
10411042

10421043
SetterNotSync:

0 commit comments

Comments
 (0)