Skip to content

Commit 60af3ba

Browse files
Implement type arguments to implicit creation
Fixes #30922 Change-Id: If9806d0ec5e1cfcc3ae3bd008f3ad3aa1f518a34 Reviewed-on: https://dart-review.googlesource.com/41261 Commit-Queue: Peter von der Ahé <[email protected]> Reviewed-by: Dmitry Stefantsov <[email protected]> Reviewed-by: Dan Rubel <[email protected]>
1 parent 8ada18e commit 60af3ba

File tree

5 files changed

+67
-22
lines changed

5 files changed

+67
-22
lines changed

pkg/front_end/lib/src/fasta/kernel/body_builder.dart

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,8 @@ class BodyBuilder<Arguments> extends ScopeListener<JumpTarget>
398398
pushQualifiedReference(beginToken.next, periodBeforeName);
399399
if (arguments != null) {
400400
push(arguments);
401-
endNewExpression(beginToken);
401+
buildConstructorReferenceInvocation(
402+
beginToken, beginToken.offset, Constness.explicitConst);
402403
push(popForValue());
403404
} else {
404405
String name = pop();
@@ -2660,6 +2661,12 @@ class BodyBuilder<Arguments> extends ScopeListener<JumpTarget>
26602661
constantContext = ConstantContext.inferred;
26612662
}
26622663

2664+
@override
2665+
void beginImplicitCreationExpression(Token token) {
2666+
debugEvent("beginImplicitCreationExpression");
2667+
super.push(constantContext);
2668+
}
2669+
26632670
@override
26642671
void endConstLiteral(Token token) {
26652672
debugEvent("endConstLiteral");
@@ -2671,7 +2678,12 @@ class BodyBuilder<Arguments> extends ScopeListener<JumpTarget>
26712678
@override
26722679
void endNewExpression(Token token) {
26732680
debugEvent("NewExpression");
2674-
Token nameToken = token.next;
2681+
buildConstructorReferenceInvocation(
2682+
token.next, token.offset, Constness.explicitNew);
2683+
}
2684+
2685+
void buildConstructorReferenceInvocation(
2686+
Token nameToken, int offset, Constness constness) {
26752687
Arguments arguments = pop();
26762688
String name = pop();
26772689
List<DartType> typeArguments = pop();
@@ -2697,27 +2709,26 @@ class BodyBuilder<Arguments> extends ScopeListener<JumpTarget>
26972709
ConstantContext savedConstantContext = pop();
26982710
if (type is TypeDeclarationBuilder) {
26992711
Expression expression = buildConstructorInvocation(
2700-
type,
2701-
nameToken,
2702-
arguments,
2703-
name,
2704-
typeArguments,
2705-
token.charOffset,
2706-
optional("const", token) || optional("@", token)
2707-
? Constness.explicitConst
2708-
: Constness.explicitNew);
2712+
type, nameToken, arguments, name, typeArguments, offset, constness);
27092713
push(deferredPrefix != null
27102714
? wrapInDeferredCheck(expression, deferredPrefix, checkOffset)
27112715
: expression);
27122716
} else if (type is ErrorAccessor) {
27132717
push(type.buildError(arguments));
27142718
} else {
2715-
push(throwNoSuchMethodError(forest.literalNull(token),
2719+
push(throwNoSuchMethodError(storeOffset(forest.literalNull(null), offset),
27162720
debugName(getNodeName(type), name), arguments, nameToken.charOffset));
27172721
}
27182722
constantContext = savedConstantContext;
27192723
}
27202724

2725+
@override
2726+
void endImplicitCreationExpression(Token token) {
2727+
debugEvent("ImplicitCreationExpression");
2728+
buildConstructorReferenceInvocation(
2729+
token, token.offset, Constness.implicit);
2730+
}
2731+
27212732
@override
27222733
Expression buildConstructorInvocation(
27232734
TypeDeclarationBuilder type,
@@ -2816,7 +2827,8 @@ class BodyBuilder<Arguments> extends ScopeListener<JumpTarget>
28162827
@override
28172828
void endConstExpression(Token token) {
28182829
debugEvent("endConstExpression");
2819-
endNewExpression(token);
2830+
buildConstructorReferenceInvocation(
2831+
token.next, token.offset, Constness.explicitConst);
28202832
}
28212833

28222834
@override

pkg/front_end/lib/src/fasta/parser/forwarding_listener.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,16 @@ class ForwardingListener implements Listener {
951951
listener?.handleDottedName(count, firstIdentifier);
952952
}
953953

954+
@override
955+
void beginImplicitCreationExpression(Token token) {
956+
listener?.beginImplicitCreationExpression(token);
957+
}
958+
959+
@override
960+
void endImplicitCreationExpression(Token token) {
961+
listener?.endImplicitCreationExpression(token);
962+
}
963+
954964
@override
955965
void handleEmptyStatement(Token token) {
956966
listener?.handleEmptyStatement(token);

pkg/front_end/lib/src/fasta/parser/listener.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,12 @@ class Listener {
516516
logEvent("DottedName");
517517
}
518518

519+
void beginImplicitCreationExpression(Token token) {}
520+
521+
void endImplicitCreationExpression(Token token) {
522+
logEvent("ImplicitCreationExpression");
523+
}
524+
519525
void beginInitializedIdentifier(Token token) {}
520526

521527
void endInitializedIdentifier(Token nameToken) {

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4566,9 +4566,24 @@ class Parser {
45664566
token.next, POSTFIX_PRECEDENCE, allowCascades);
45674567
listener.handleUnaryPrefixAssignmentExpression(operator);
45684568
return token;
4569-
} else {
4570-
return parsePrimary(token, IdentifierContext.expression);
4569+
} else if (token.next.isIdentifier) {
4570+
Token identifier = token.next;
4571+
if (optional(".", identifier.next)) {
4572+
identifier = identifier.next.next;
4573+
}
4574+
if (identifier.isIdentifier) {
4575+
// Looking at `identifier ('.' identifier)?`.
4576+
if (optional("<", identifier.next)) {
4577+
BeginToken typeArguments = identifier.next;
4578+
Token endTypeArguments = typeArguments.endGroup;
4579+
if (endTypeArguments != null &&
4580+
optional(".", endTypeArguments.next)) {
4581+
return parseImplicitCreationExpression(token);
4582+
}
4583+
}
4584+
}
45714585
}
4586+
return parsePrimary(token, IdentifierContext.expression);
45724587
}
45734588

45744589
Token parseArgumentOrIndexStar(Token token, Token typeArguments) {
@@ -4981,6 +4996,15 @@ class Parser {
49814996
return token;
49824997
}
49834998

4999+
Token parseImplicitCreationExpression(Token token) {
5000+
Token begin = token;
5001+
listener.beginImplicitCreationExpression(token);
5002+
token = parseConstructorReference(token);
5003+
token = parseRequiredArguments(token);
5004+
listener.endImplicitCreationExpression(begin);
5005+
return token;
5006+
}
5007+
49845008
/// This method parses a list or map literal that is known to start with the
49855009
/// keyword 'const'.
49865010
///

tests/language_2/language_2_kernel.status

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,6 @@ identical_const_test/01: MissingCompileTimeError
115115
identical_const_test/02: MissingCompileTimeError
116116
identical_const_test/03: MissingCompileTimeError
117117
identical_const_test/04: MissingCompileTimeError
118-
implicit_creation/implicit_const_context_constructor_generic_named_test: CompileTimeError
119-
implicit_creation/implicit_const_context_prefix_constructor_generic_named_test: CompileTimeError
120-
implicit_creation/implicit_new_constructor_generic_named_test: CompileTimeError
121-
implicit_creation/implicit_new_or_const_generic_test: CompileTimeError
122-
implicit_creation/implicit_new_prefix_constructor_generic_named_test: CompileTimeError
123118
implicit_this_test/01: MissingCompileTimeError
124119
implicit_this_test/04: MissingCompileTimeError
125120
issue31596_override_test/07: MissingCompileTimeError
@@ -667,7 +662,6 @@ generic_no_such_method_dispatcher_test: CompileTimeError # Issue 31533
667662
generic_tearoff_test: CompileTimeError
668663
generic_tearoff_test: RuntimeError
669664
if_null_evaluation_order_test: Pass
670-
implicit_creation/implicit_new_constructor_generic_test: Pass
671665
initializing_formal_type_annotation_test/01: MissingCompileTimeError
672666
initializing_formal_type_annotation_test/02: MissingCompileTimeError
673667
instantiate_tearoff_of_call_test: CompileTimeError
@@ -1010,7 +1004,6 @@ getter_override_test/01: MissingCompileTimeError # Issue 32613: override check i
10101004
getter_override_test/02: MissingCompileTimeError # Issue 32613: override check is missing in CFE.
10111005
hello_dart_test: Skip # Incompatible flag: --compile_all
10121006
implicit_closure_test: Skip # Incompatible flag: --use_slow_path
1013-
implicit_creation/implicit_new_constructor_generic_test: Pass
10141007
implicit_downcast_during_assignment_test: Pass # Correctly passes.
10151008
implicit_downcast_during_combiner_test: Pass # Correctly passes.
10161009
implicit_downcast_during_compound_assignment_test: Pass # Correctly passes.

0 commit comments

Comments
 (0)