Skip to content

Commit

Permalink
Implement type arguments to implicit creation
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
peter-ahe-google authored and [email protected] committed Apr 6, 2018
1 parent 8ada18e commit 60af3ba
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 22 deletions.
38 changes: 25 additions & 13 deletions pkg/front_end/lib/src/fasta/kernel/body_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,8 @@ class BodyBuilder<Arguments> extends ScopeListener<JumpTarget>
pushQualifiedReference(beginToken.next, periodBeforeName);
if (arguments != null) {
push(arguments);
endNewExpression(beginToken);
buildConstructorReferenceInvocation(
beginToken, beginToken.offset, Constness.explicitConst);
push(popForValue());
} else {
String name = pop();
Expand Down Expand Up @@ -2660,6 +2661,12 @@ class BodyBuilder<Arguments> extends ScopeListener<JumpTarget>
constantContext = ConstantContext.inferred;
}

@override
void beginImplicitCreationExpression(Token token) {
debugEvent("beginImplicitCreationExpression");
super.push(constantContext);
}

@override
void endConstLiteral(Token token) {
debugEvent("endConstLiteral");
Expand All @@ -2671,7 +2678,12 @@ class BodyBuilder<Arguments> extends ScopeListener<JumpTarget>
@override
void endNewExpression(Token token) {
debugEvent("NewExpression");
Token nameToken = token.next;
buildConstructorReferenceInvocation(
token.next, token.offset, Constness.explicitNew);
}

void buildConstructorReferenceInvocation(
Token nameToken, int offset, Constness constness) {
Arguments arguments = pop();
String name = pop();
List<DartType> typeArguments = pop();
Expand All @@ -2697,27 +2709,26 @@ class BodyBuilder<Arguments> extends ScopeListener<JumpTarget>
ConstantContext savedConstantContext = pop();
if (type is TypeDeclarationBuilder) {
Expression expression = buildConstructorInvocation(
type,
nameToken,
arguments,
name,
typeArguments,
token.charOffset,
optional("const", token) || optional("@", token)
? Constness.explicitConst
: Constness.explicitNew);
type, nameToken, arguments, name, typeArguments, offset, constness);
push(deferredPrefix != null
? wrapInDeferredCheck(expression, deferredPrefix, checkOffset)
: expression);
} else if (type is ErrorAccessor) {
push(type.buildError(arguments));
} else {
push(throwNoSuchMethodError(forest.literalNull(token),
push(throwNoSuchMethodError(storeOffset(forest.literalNull(null), offset),
debugName(getNodeName(type), name), arguments, nameToken.charOffset));
}
constantContext = savedConstantContext;
}

@override
void endImplicitCreationExpression(Token token) {
debugEvent("ImplicitCreationExpression");
buildConstructorReferenceInvocation(
token, token.offset, Constness.implicit);
}

@override
Expression buildConstructorInvocation(
TypeDeclarationBuilder type,
Expand Down Expand Up @@ -2816,7 +2827,8 @@ class BodyBuilder<Arguments> extends ScopeListener<JumpTarget>
@override
void endConstExpression(Token token) {
debugEvent("endConstExpression");
endNewExpression(token);
buildConstructorReferenceInvocation(
token.next, token.offset, Constness.explicitConst);
}

@override
Expand Down
10 changes: 10 additions & 0 deletions pkg/front_end/lib/src/fasta/parser/forwarding_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,16 @@ class ForwardingListener implements Listener {
listener?.handleDottedName(count, firstIdentifier);
}

@override
void beginImplicitCreationExpression(Token token) {
listener?.beginImplicitCreationExpression(token);
}

@override
void endImplicitCreationExpression(Token token) {
listener?.endImplicitCreationExpression(token);
}

@override
void handleEmptyStatement(Token token) {
listener?.handleEmptyStatement(token);
Expand Down
6 changes: 6 additions & 0 deletions pkg/front_end/lib/src/fasta/parser/listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,12 @@ class Listener {
logEvent("DottedName");
}

void beginImplicitCreationExpression(Token token) {}

void endImplicitCreationExpression(Token token) {
logEvent("ImplicitCreationExpression");
}

void beginInitializedIdentifier(Token token) {}

void endInitializedIdentifier(Token nameToken) {
Expand Down
28 changes: 26 additions & 2 deletions pkg/front_end/lib/src/fasta/parser/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4566,9 +4566,24 @@ class Parser {
token.next, POSTFIX_PRECEDENCE, allowCascades);
listener.handleUnaryPrefixAssignmentExpression(operator);
return token;
} else {
return parsePrimary(token, IdentifierContext.expression);
} else if (token.next.isIdentifier) {
Token identifier = token.next;
if (optional(".", identifier.next)) {
identifier = identifier.next.next;
}
if (identifier.isIdentifier) {
// Looking at `identifier ('.' identifier)?`.
if (optional("<", identifier.next)) {
BeginToken typeArguments = identifier.next;
Token endTypeArguments = typeArguments.endGroup;
if (endTypeArguments != null &&
optional(".", endTypeArguments.next)) {
return parseImplicitCreationExpression(token);
}
}
}
}
return parsePrimary(token, IdentifierContext.expression);
}

Token parseArgumentOrIndexStar(Token token, Token typeArguments) {
Expand Down Expand Up @@ -4981,6 +4996,15 @@ class Parser {
return token;
}

Token parseImplicitCreationExpression(Token token) {
Token begin = token;
listener.beginImplicitCreationExpression(token);
token = parseConstructorReference(token);
token = parseRequiredArguments(token);
listener.endImplicitCreationExpression(begin);
return token;
}

/// This method parses a list or map literal that is known to start with the
/// keyword 'const'.
///
Expand Down
7 changes: 0 additions & 7 deletions tests/language_2/language_2_kernel.status
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,6 @@ identical_const_test/01: MissingCompileTimeError
identical_const_test/02: MissingCompileTimeError
identical_const_test/03: MissingCompileTimeError
identical_const_test/04: MissingCompileTimeError
implicit_creation/implicit_const_context_constructor_generic_named_test: CompileTimeError
implicit_creation/implicit_const_context_prefix_constructor_generic_named_test: CompileTimeError
implicit_creation/implicit_new_constructor_generic_named_test: CompileTimeError
implicit_creation/implicit_new_or_const_generic_test: CompileTimeError
implicit_creation/implicit_new_prefix_constructor_generic_named_test: CompileTimeError
implicit_this_test/01: MissingCompileTimeError
implicit_this_test/04: MissingCompileTimeError
issue31596_override_test/07: MissingCompileTimeError
Expand Down Expand Up @@ -667,7 +662,6 @@ generic_no_such_method_dispatcher_test: CompileTimeError # Issue 31533
generic_tearoff_test: CompileTimeError
generic_tearoff_test: RuntimeError
if_null_evaluation_order_test: Pass
implicit_creation/implicit_new_constructor_generic_test: Pass
initializing_formal_type_annotation_test/01: MissingCompileTimeError
initializing_formal_type_annotation_test/02: MissingCompileTimeError
instantiate_tearoff_of_call_test: CompileTimeError
Expand Down Expand Up @@ -1010,7 +1004,6 @@ getter_override_test/01: MissingCompileTimeError # Issue 32613: override check i
getter_override_test/02: MissingCompileTimeError # Issue 32613: override check is missing in CFE.
hello_dart_test: Skip # Incompatible flag: --compile_all
implicit_closure_test: Skip # Incompatible flag: --use_slow_path
implicit_creation/implicit_new_constructor_generic_test: Pass
implicit_downcast_during_assignment_test: Pass # Correctly passes.
implicit_downcast_during_combiner_test: Pass # Correctly passes.
implicit_downcast_during_compound_assignment_test: Pass # Correctly passes.
Expand Down

0 comments on commit 60af3ba

Please sign in to comment.