Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Unified Diff: pkg/front_end/lib/src/fasta/source/outline_builder.dart

Issue 2730093002: Avoid crashing on function syntax. (Closed)
Patch Set: Update status. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/front_end/lib/src/fasta/source/outline_builder.dart
diff --git a/pkg/front_end/lib/src/fasta/source/outline_builder.dart b/pkg/front_end/lib/src/fasta/source/outline_builder.dart
index 215d2eb04fc582f20332322e26b1b2ac5526bb38..8f187293986d12feab049eafa8a79300ac02de2b 100644
--- a/pkg/front_end/lib/src/fasta/source/outline_builder.dart
+++ b/pkg/front_end/lib/src/fasta/source/outline_builder.dart
@@ -482,13 +482,46 @@ class OutlineBuilder extends UnhandledListener {
}
@override
- void endFunctionTypeAlias(
- Token typedefKeyword, Token equals, Token endToken) {
- debugEvent("endFunctionTypeAlias");
+ void handleFunctionType(Token functionToken, Token endToken) {
+ debugEvent("FunctionType");
List<FormalParameterBuilder> formals = pop();
List<TypeVariableBuilder> typeVariables = pop();
- String name = pop();
TypeBuilder returnType = pop();
+ push(library.addFunctionType(
+ returnType, typeVariables, formals, functionToken.charOffset));
+ }
+
+ @override
+ void endFunctionTypeAlias(
+ Token typedefKeyword, Token equals, Token endToken) {
+ debugEvent("endFunctionTypeAlias");
+ List<FormalParameterBuilder> formals;
+ List<TypeVariableBuilder> typeVariables;
+ String name;
+ TypeBuilder returnType;
+ if (equals == null) {
+ formals = pop();
+ typeVariables = pop();
+ name = pop();
+ returnType = pop();
+ } else {
+ var type = pop();
+ typeVariables = pop();
+ name = pop();
+ if (type is FunctionTypeBuilder) {
+ // TODO(ahe): We need to start a nested declaration when parsing the
+ // formals and return type so we can correctly bind
+ // `type.typeVariables`. A typedef can have type variables, and a new
+ // function type can also have type variables (representing the type of
+ // a generic function).
+ formals = type.formals;
+ returnType = type.returnType;
+ } else {
+ // TODO(ahe): Improve this error message.
+ library.addCompileTimeError(
+ equals.charOffset, "Can't create typedef from non-function type.");
+ }
+ }
List<MetadataBuilder> metadata = pop();
library.addFunctionTypeAlias(metadata, returnType, name, typeVariables,
formals, typedefKeyword.charOffset);
« no previous file with comments | « pkg/front_end/lib/src/fasta/source/diet_listener.dart ('k') | pkg/front_end/lib/src/fasta/source/source_library_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698