From 2d46ebd6a5c5d826ccaa6a34b00ce8564bedeaa5 Mon Sep 17 00:00:00 2001 From: Kevin Millikin Date: Thu, 24 May 2018 10:14:20 +0000 Subject: [PATCH] Fix Dart 2 runtime errors in the front end MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix all the Dart 2 runtime errors revealed by compiling dart2js, the front end itself, the front end tests. Change-Id: Ic6e6dd9f85db845b6a351ebbcfea9a6045843fc2 Reviewed-on: https://dart-review.googlesource.com/56322 Commit-Queue: Kevin Millikin Reviewed-by: Aske Simon Christensen Reviewed-by: Peter von der Ahé --- pkg/analyzer/tool/summary/mini_ast.dart | 20 ++++--- .../lib/src/base/libraries_specification.dart | 5 +- .../src/fasta/builder/library_builder.dart | 8 +-- .../src/fasta/dill/dill_library_builder.dart | 12 ++++ .../lib/src/fasta/kernel/body_builder.dart | 36 +++++++++--- .../fasta/kernel/kernel_library_builder.dart | 17 +++++- .../lib/src/fasta/source/diet_listener.dart | 7 ++- .../lib/src/fasta/source/outline_builder.dart | 58 +++++++++++++++---- .../lib/src/fasta/source/stack_listener.dart | 11 ++-- .../fasta/testing/analyzer_diet_listener.dart | 3 +- pkg/front_end/test/fasta/testing/suite.dart | 2 +- pkg/kernel/lib/clone.dart | 2 +- pkg/testing/lib/src/analyze.dart | 15 +++-- pkg/testing/lib/src/chain.dart | 4 +- pkg/testing/lib/src/error_handling.dart | 3 +- pkg/testing/lib/src/expectation.dart | 2 +- pkg/testing/lib/src/run.dart | 6 +- pkg/testing/lib/src/run_tests.dart | 8 +-- pkg/testing/lib/src/test_dart.dart | 4 +- .../lib/src/test_dart/status_file_parser.dart | 30 +++++----- pkg/testing/lib/src/test_root.dart | 5 +- 21 files changed, 177 insertions(+), 81 deletions(-) diff --git a/pkg/analyzer/tool/summary/mini_ast.dart b/pkg/analyzer/tool/summary/mini_ast.dart index 6866377c81c..6dc47f7995b 100644 --- a/pkg/analyzer/tool/summary/mini_ast.dart +++ b/pkg/analyzer/tool/summary/mini_ast.dart @@ -178,13 +178,14 @@ class MiniAstBuilder extends StackListener { @override void endArguments(int count, Token beginToken, Token endToken) { debugEvent("Arguments"); - push(popList(count)); + push(popList(count, new List.filled(count, null, growable: true))); } @override void endClassBody(int memberCount, Token beginToken, Token endToken) { debugEvent("ClassBody"); - push(popList(memberCount)); + push(popList(memberCount, + new List.filled(memberCount, null, growable: true))); } @override @@ -229,7 +230,9 @@ class MiniAstBuilder extends StackListener { void endEnum(Token enumKeyword, Token leftBrace, int count) { debugEvent("Enum"); - List constants = popList(count); + List constants = + new List.filled(count, null, growable: true); + popList(count, constants); String name = pop(); List metadata = pop(); Comment comment = pop(); @@ -273,7 +276,7 @@ class MiniAstBuilder extends StackListener { @override void handleIdentifierList(int count) { debugEvent("IdentifierList"); - push(popList(count)); + push(popList(count, new List.filled(count, null, growable: true))); } @override @@ -345,7 +348,9 @@ class MiniAstBuilder extends StackListener { @override void endMetadataStar(int count) { debugEvent("MetadataStar"); - push(popList(count) ?? NullValue.Metadata); + push( + popList(count, new List.filled(count, null, growable: true)) ?? + NullValue.Metadata); } void endMethod( @@ -384,7 +389,8 @@ class MiniAstBuilder extends StackListener { // We ignore top level variable declarations; they are present just to make // the IDL analyze without warnings. debugEvent("TopLevelFields"); - popList(count); // Fields + popList( + count, new List.filled(count, null, growable: true)); // Fields pop(); // Type pop(); // Metadata pop(); // Comment @@ -393,7 +399,7 @@ class MiniAstBuilder extends StackListener { @override void endTypeArguments(int count, Token beginToken, Token endToken) { debugEvent("TypeArguments"); - push(popList(count)); + push(popList(count, new List.filled(count, null, growable: true))); } @override diff --git a/pkg/front_end/lib/src/base/libraries_specification.dart b/pkg/front_end/lib/src/base/libraries_specification.dart index 2f9f553a979..2a25b3020fd 100644 --- a/pkg/front_end/lib/src/base/libraries_specification.dart +++ b/pkg/front_end/lib/src/base/libraries_specification.dart @@ -164,9 +164,10 @@ class LibrariesSpecification { } var uri = checkAndResolve(data['uri']); - var patches; + List patches; if (data['patches'] is List) { - patches = data['patches'].map(baseUri.resolve).toList(); + patches = + data['patches'].map((s) => baseUri.resolve(s)).toList(); } else if (data['patches'] is String) { patches = [checkAndResolve(data['patches'])]; } else if (data['patches'] == null) { diff --git a/pkg/front_end/lib/src/fasta/builder/library_builder.dart b/pkg/front_end/lib/src/fasta/builder/library_builder.dart index 18153286d54..304d87f3ed8 100644 --- a/pkg/front_end/lib/src/fasta/builder/library_builder.dart +++ b/pkg/front_end/lib/src/fasta/builder/library_builder.dart @@ -24,7 +24,6 @@ import 'builder.dart' show Builder, ClassBuilder, - DynamicTypeBuilder, ModifierBuilder, PrefixBuilder, Scope, @@ -181,12 +180,7 @@ abstract class LibraryBuilder return 0; } - void becomeCoreLibrary(dynamicType) { - if (scope.local["dynamic"] == null) { - addBuilder("dynamic", - new DynamicTypeBuilder(dynamicType, this, -1), -1); - } - } + void becomeCoreLibrary(dynamicType); void forEach(void f(String name, Builder builder)) { scope.forEach((String name, Builder builder) { diff --git a/pkg/front_end/lib/src/fasta/dill/dill_library_builder.dart b/pkg/front_end/lib/src/fasta/dill/dill_library_builder.dart index 2b6c7334228..5a29dbe876e 100644 --- a/pkg/front_end/lib/src/fasta/dill/dill_library_builder.dart +++ b/pkg/front_end/lib/src/fasta/dill/dill_library_builder.dart @@ -9,6 +9,7 @@ import 'dart:convert' show jsonDecode; import 'package:kernel/ast.dart' show Class, + DartType, Field, Library, ListLiteral, @@ -25,6 +26,7 @@ import '../problems.dart' show internalProblem, unhandled, unimplemented; import '../kernel/kernel_builder.dart' show Builder, + DynamicTypeBuilder, InvalidTypeBuilder, KernelInvalidTypeBuilder, KernelTypeBuilder, @@ -65,6 +67,16 @@ class DillLibraryBuilder extends LibraryBuilder { @override Library get target => library; + void becomeCoreLibrary(dynamicType) { + if (scope.local["dynamic"] == null) { + addBuilder( + "dynamic", + new DynamicTypeBuilder( + dynamicType, this, -1), + -1); + } + } + void addClass(Class cls) { DillClassBuilder classBulder = new DillClassBuilder(cls, this); addBuilder(cls.name, classBulder, cls.fileOffset); diff --git a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart index b29d5fcfac6..c9047b5cd8d 100644 --- a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart +++ b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart @@ -445,7 +445,9 @@ abstract class BodyBuilder @override void endMetadataStar(int count) { debugEvent("MetadataStar"); - push(popList(count) ?? NullValue.Metadata); + push(popList( + count, new List.filled(count, null, growable: true)) ?? + NullValue.Metadata); } @override @@ -822,7 +824,9 @@ abstract class BodyBuilder @override void endArguments(int count, Token beginToken, Token endToken) { debugEvent("Arguments"); - List arguments = popList(count) ?? []; + List arguments = + new List.filled(count, null, growable: true); + popList(count, arguments); int firstNamedArgumentIndex = arguments.length; for (int i = 0; i < arguments.length; i++) { var node = arguments[i]; @@ -877,7 +881,9 @@ abstract class BodyBuilder } push(forest.arguments(positional, beginToken, named: named)); } else { - push(forest.arguments(arguments, beginToken)); + // TODO(kmillikin): Find a way to avoid allocating a second list in the + // case where there were no named arguments, which is a common one. + push(forest.arguments(new List.from(arguments), beginToken)); } } @@ -1510,7 +1516,9 @@ abstract class BodyBuilder String value = unescapeString(token.lexeme); push(forest.literalString(value, token)); } else { - List parts = popList(1 + interpolationCount * 2); + var count = 1 + interpolationCount * 2; + List parts = + popList(count, new List.filled(count, null, growable: true)); Token first = parts.first; Token last = parts.last; Quote quote = analyzeQuote(first.lexeme); @@ -2251,7 +2259,10 @@ abstract class BodyBuilder FormalParameterKind kind = optional("{", beginToken) ? FormalParameterKind.optionalNamed : FormalParameterKind.optionalPositional; - push(new OptionalFormals(kind, popList(count) ?? [])); + var variables = + new List.filled(count, null, growable: true); + popList(count, variables); + push(new OptionalFormals(kind, variables)); } @override @@ -2389,7 +2400,8 @@ abstract class BodyBuilder @override void endTryStatement(int catchCount, Token tryKeyword, Token finallyKeyword) { Statement finallyBlock = popStatementIfNotNull(finallyKeyword); - Object catches = popList(catchCount); + Object catches = popList( + catchCount, new List.filled(catchCount, null, growable: true)); Statement tryBlock = popStatement(); if (compileTimeErrorInTry == null) { push(forest.tryStatement( @@ -2910,7 +2922,8 @@ abstract class BodyBuilder @override void endTypeArguments(int count, Token beginToken, Token endToken) { debugEvent("TypeArguments"); - push(popList(count)); + push( + popList(count, new List.filled(count, null, growable: true))); } @override @@ -3372,7 +3385,9 @@ abstract class BodyBuilder @override void beginSwitchCase(int labelCount, int expressionCount, Token firstToken) { debugEvent("beginSwitchCase"); - List labelsAndExpressions = popList(labelCount + expressionCount); + var count = labelCount + expressionCount; + List labelsAndExpressions = + popList(count, new List.filled(count, null, growable: true)); List labels = []; List expressions = []; if (labelsAndExpressions != null) { @@ -3656,7 +3671,10 @@ abstract class BodyBuilder @override void endTypeVariables(int count, Token beginToken, Token endToken) { debugEvent("TypeVariables"); - List typeVariables = popList(count); + List typeVariables = popList( + count, + new List.filled(count, null, + growable: true)); if (typeVariables != null) { if (library.loader.target.strongMode) { List calculatedBounds = calculateBounds( diff --git a/pkg/front_end/lib/src/fasta/kernel/kernel_library_builder.dart b/pkg/front_end/lib/src/fasta/kernel/kernel_library_builder.dart index b5f68541523..81b4f1f559a 100644 --- a/pkg/front_end/lib/src/fasta/kernel/kernel_library_builder.dart +++ b/pkg/front_end/lib/src/fasta/kernel/kernel_library_builder.dart @@ -53,6 +53,7 @@ import 'kernel_builder.dart' BuiltinTypeBuilder, ClassBuilder, ConstructorReferenceBuilder, + DynamicTypeBuilder, FormalParameterBuilder, InvalidTypeBuilder, KernelClassBuilder, @@ -125,6 +126,16 @@ class KernelLibraryBuilder Uri get uri => library.importUri; + void becomeCoreLibrary(dynamicType) { + if (scope.local["dynamic"] == null) { + addBuilder( + "dynamic", + new DynamicTypeBuilder( + dynamicType, this, -1), + -1); + } + } + KernelTypeBuilder addNamedType( Object name, List arguments, int charOffset) { return addType(new KernelNamedTypeBuilder(name, arguments), charOffset); @@ -138,7 +149,8 @@ class KernelLibraryBuilder KernelTypeBuilder addVoidType(int charOffset) { return addNamedType("void", null, charOffset) - ..bind(new VoidTypeBuilder(const VoidType(), this, charOffset)); + ..bind(new VoidTypeBuilder( + const VoidType(), this, charOffset)); } void addClass( @@ -976,7 +988,8 @@ class KernelLibraryBuilder boundlessTypeVariables.add(newVariable); } for (TypeBuilder newType in newTypes) { - declaration.addType(new UnresolvedType(newType, -1, null)); + declaration + .addType(new UnresolvedType(newType, -1, null)); } return copy; } diff --git a/pkg/front_end/lib/src/fasta/source/diet_listener.dart b/pkg/front_end/lib/src/fasta/source/diet_listener.dart index b4639f1325f..4adca66da6d 100644 --- a/pkg/front_end/lib/src/fasta/source/diet_listener.dart +++ b/pkg/front_end/lib/src/fasta/source/diet_listener.dart @@ -90,7 +90,9 @@ class DietListener extends StackListener { @override void endMetadataStar(int count) { debugEvent("MetadataStar"); - push(popList(count)?.first ?? NullValue.Metadata); + push(popList(count, new List.filled(count, null, growable: true)) + ?.first ?? + NullValue.Metadata); } @override @@ -574,7 +576,8 @@ class DietListener extends StackListener { } void buildFields(int count, Token token, bool isTopLevel) { - List names = popList(count); + List names = + popList(count, new List.filled(count, null, growable: true)); Builder builder = lookupBuilder(token, null, names.first); Token metadata = pop(); // TODO(paulberry): don't re-parse the field if we've already parsed it 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 8244fca9d01..f2f3dfdf832 100644 --- a/pkg/front_end/lib/src/fasta/source/outline_builder.dart +++ b/pkg/front_end/lib/src/fasta/source/outline_builder.dart @@ -10,6 +10,8 @@ import '../../scanner/token.dart' show Token; import '../builder/builder.dart'; +import '../builder/metadata_builder.dart' show ExpressionMetadataBuilder; + import '../combinator.dart' show Combinator; import '../fasta_codes.dart' @@ -66,6 +68,13 @@ import 'stack_listener.dart' show NullValue, StackListener; import '../configuration.dart' show Configuration; +import '../kernel/kernel_builder.dart' + show + KernelFormalParameterBuilder, + KernelNamedTypeBuilder, + KernelTypeBuilder, + KernelTypeVariableBuilder; + enum MethodBody { Abstract, Regular, @@ -129,7 +138,11 @@ class OutlineBuilder extends StackListener { @override void endMetadataStar(int count) { debugEvent("MetadataStar"); - push(popList(count) ?? NullValue.Metadata); + push(popList( + count, + new List>.filled(count, null, + growable: true)) ?? + NullValue.Metadata); } @override @@ -155,7 +168,9 @@ class OutlineBuilder extends StackListener { @override void endCombinators(int count) { debugEvent("Combinators"); - push(popList(count) ?? NullValue.Combinators); + push(popList( + count, new List.filled(count, null, growable: true)) ?? + NullValue.Combinators); } @override @@ -202,7 +217,9 @@ class OutlineBuilder extends StackListener { @override void endConditionalUris(int count) { debugEvent("EndConditionalUris"); - push(popList(count) ?? NullValue.ConditionalUris); + push(popList(count, + new List.filled(count, null, growable: true)) ?? + NullValue.ConditionalUris); } @override @@ -388,7 +405,11 @@ class OutlineBuilder extends StackListener { @override void handleClassImplements(Token implementsKeyword, int interfacesCount) { debugEvent("handleClassImplements"); - push(popList(interfacesCount) ?? NullValue.TypeBuilderList); + push(popList( + interfacesCount, + new List.filled(interfacesCount, null, + growable: true)) ?? + NullValue.TypeBuilderList); } @override @@ -730,7 +751,9 @@ class OutlineBuilder extends StackListener { @override void endTypeArguments(int count, Token beginToken, Token endToken) { debugEvent("TypeArguments"); - push(popList(count) ?? NullValue.TypeArguments); + push(popList(count, + new List.filled(count, null, growable: true)) ?? + NullValue.TypeArguments); } @override @@ -750,13 +773,21 @@ class OutlineBuilder extends StackListener { @override void endTypeList(int count) { debugEvent("TypeList"); - push(popList(count) ?? NullValue.TypeList); + push(popList( + count, + new List.filled(count, null, + growable: true)) ?? + NullValue.TypeList); } @override void endTypeVariables(int count, Token beginToken, Token endToken) { debugEvent("TypeVariables"); - push(popList(count) ?? NullValue.TypeVariables); + push(popList( + count, + new List.filled(count, null, + growable: true)) ?? + NullValue.TypeVariables); } @override @@ -819,7 +850,9 @@ class OutlineBuilder extends StackListener { // 0. It might be simpler if the parser didn't call this method in that // case, however, then [beginOptionalFormalParameters] wouldn't always be // matched by this method. - List parameters = popList(count) ?? []; + var parameters = new List.filled(count, null, + growable: true); + popList(count, parameters); for (FormalParameterBuilder parameter in parameters) { parameter.kind = kind; } @@ -910,7 +943,8 @@ class OutlineBuilder extends StackListener { @override void endEnum(Token enumKeyword, Token leftBrace, int count) { String documentationComment = getDocumentationComment(enumKeyword); - List constantNamesAndOffsets = popList(count * 3); + List constantNamesAndOffsets = popList( + count * 3, new List.filled(count * 3, null, growable: true)); int charOffset = pop(); String name = pop(); List metadata = pop(); @@ -1007,7 +1041,8 @@ class OutlineBuilder extends StackListener { void endTopLevelFields(Token staticToken, Token covariantToken, Token varFinalOrConst, int count, Token beginToken, Token endToken) { debugEvent("endTopLevelFields"); - List fieldsInfo = popList(count * 4); + List fieldsInfo = popList( + count * 4, new List.filled(count * 4, null, growable: true)); TypeBuilder type = pop(); int modifiers = (staticToken != null ? staticMask : 0) | (covariantToken != null ? covariantMask : 0) | @@ -1023,7 +1058,8 @@ class OutlineBuilder extends StackListener { void endFields(Token staticToken, Token covariantToken, Token varFinalOrConst, int count, Token beginToken, Token endToken) { debugEvent("Fields"); - List fieldsInfo = popList(count * 4); + List fieldsInfo = popList( + count * 4, new List.filled(count * 4, null, growable: true)); TypeBuilder type = pop(); int modifiers = (staticToken != null ? staticMask : 0) | (covariantToken != null ? covariantMask : 0) | diff --git a/pkg/front_end/lib/src/fasta/source/stack_listener.dart b/pkg/front_end/lib/src/fasta/source/stack_listener.dart index ef9eda1c370..dd5fc5d2f1a 100644 --- a/pkg/front_end/lib/src/fasta/source/stack_listener.dart +++ b/pkg/front_end/lib/src/fasta/source/stack_listener.dart @@ -121,7 +121,7 @@ abstract class StackListener extends Listener { return value == null ? null : pop(); } - List popList(int n, [List list]) { + List popList(int n, List list) { if (n == 0) return null; return stack.popList(n, list); } @@ -314,7 +314,9 @@ abstract class StackListener extends Listener { @override void handleStringJuxtaposition(int literalCount) { debugEvent("StringJuxtaposition"); - push(popList(literalCount).join("")); + push(popList(literalCount, + new List.filled(literalCount, null, growable: true)) + .join("")); } @override @@ -396,16 +398,15 @@ class Stack { final table = array; final length = arrayLength; - final tailList = list ?? new List.filled(count, null, growable: true); final startIndex = length - count; for (int i = 0; i < count; i++) { final value = table[startIndex + i]; - tailList[i] = value is NullValue ? null : value; + list[i] = value is NullValue ? null : value; table[startIndex + i] = null; } arrayLength -= count; - return tailList; + return list; } List get values { diff --git a/pkg/front_end/test/fasta/testing/analyzer_diet_listener.dart b/pkg/front_end/test/fasta/testing/analyzer_diet_listener.dart index e0f5f3eccee..01ac3d2e201 100644 --- a/pkg/front_end/test/fasta/testing/analyzer_diet_listener.dart +++ b/pkg/front_end/test/fasta/testing/analyzer_diet_listener.dart @@ -58,7 +58,8 @@ class AnalyzerDietListener extends DietListener { @override void buildFields(int count, Token token, bool isTopLevel) { - List names = popList(count); + List names = + popList(count, new List.filled(count, null, growable: true)); Builder builder = lookupBuilder(token, null, names.first); Token metadata = pop(); AstBuilder listener = diff --git a/pkg/front_end/test/fasta/testing/suite.dart b/pkg/front_end/test/fasta/testing/suite.dart index ee0b49b12f2..39f0bfce4af 100644 --- a/pkg/front_end/test/fasta/testing/suite.dart +++ b/pkg/front_end/test/fasta/testing/suite.dart @@ -247,7 +247,7 @@ class Run extends Step { File generated = new File.fromUri(uri); StdioProcess process; try { - var args = []; + var args = []; if (context.strongMode) { args.add('--strong'); args.add('--reify-generic-functions'); diff --git a/pkg/kernel/lib/clone.dart b/pkg/kernel/lib/clone.dart index 5553fd03128..3a461aa1d77 100644 --- a/pkg/kernel/lib/clone.dart +++ b/pkg/kernel/lib/clone.dart @@ -52,7 +52,7 @@ class CloneVisitor implements TreeVisitor { return _activeFileUri == null ? TreeNode.noOffset : fileOffset; } - TreeNode clone(TreeNode node) { + T clone(T node) { final Uri activeFileUriSaved = _activeFileUri; if (node is FileUriNode) _activeFileUri = node.fileUri ?? _activeFileUri; final TreeNode result = node.accept(this) diff --git a/pkg/testing/lib/src/analyze.dart b/pkg/testing/lib/src/analyze.dart index 4471201e550..f9a23ee3f07 100644 --- a/pkg/testing/lib/src/analyze.dart +++ b/pkg/testing/lib/src/analyze.dart @@ -46,18 +46,23 @@ class Analyze extends Suite { String optionsPath = json["options"]; Uri optionsUri = optionsPath == null ? null : base.resolve(optionsPath); - List uris = new List.from( - json["uris"].map((String relative) => base.resolve(relative))); + List uris = json["uris"].map((relative) { + String r = relative; + return base.resolve(r); + }).toList(); List exclude = - new List.from(json["exclude"].map((String p) => new RegExp(p))); + json["exclude"].map((p) => new RegExp(p)).toList(); Map gitGrep = json["git grep"]; List gitGrepPathspecs; List gitGrepPatterns; if (gitGrep != null) { - gitGrepPathspecs = gitGrep["pathspecs"] ?? const ["."]; - gitGrepPatterns = gitGrep["patterns"]; + gitGrepPathspecs = gitGrep["pathspecs"] == null + ? const ["."] + : new List.from(gitGrep["pathspecs"]); + if (gitGrep["patterns"] != null) + gitGrepPatterns = new List.from(gitGrep["patterns"]); } return new Analyze( diff --git a/pkg/testing/lib/src/chain.dart b/pkg/testing/lib/src/chain.dart index f93a31b35d3..2a82f9940f6 100644 --- a/pkg/testing/lib/src/chain.dart +++ b/pkg/testing/lib/src/chain.dart @@ -63,9 +63,9 @@ class Chain extends Suite { Uri uri = base.resolve(path); Uri statusFile = base.resolve(json["status"]); List pattern = - new List.from(json["pattern"].map((String p) => new RegExp(p))); + json["pattern"].map((p) => new RegExp(p)).toList(); List exclude = - new List.from(json["exclude"].map((String p) => new RegExp(p))); + json["exclude"].map((p) => new RegExp(p)).toList(); bool processMultitests = json["process-multitests"] ?? false; return new Chain(name, kind, source, uri, statusFile, pattern, exclude, processMultitests); diff --git a/pkg/testing/lib/src/error_handling.dart b/pkg/testing/lib/src/error_handling.dart index b0f2bac4dce..bf13cb05b86 100644 --- a/pkg/testing/lib/src/error_handling.dart +++ b/pkg/testing/lib/src/error_handling.dart @@ -10,7 +10,7 @@ import 'dart:io' show exitCode, stderr; import 'dart:isolate' show ReceivePort; -Future withErrorHandling(Future f()) async { +Future withErrorHandling(Future f()) async { final ReceivePort port = new ReceivePort(); try { return await f(); @@ -20,6 +20,7 @@ Future withErrorHandling(Future f()) async { if (trace != null) { stderr.writeln(trace); } + return null; } finally { port.close(); } diff --git a/pkg/testing/lib/src/expectation.dart b/pkg/testing/lib/src/expectation.dart index 3ba1af80f87..8c8e7e9d492 100644 --- a/pkg/testing/lib/src/expectation.dart +++ b/pkg/testing/lib/src/expectation.dart @@ -78,7 +78,7 @@ class ExpectationSet { const ExpectationSet(this.internalMap); - operator [](String name) { + Expectation operator [](String name) { return internalMap[name.toLowerCase()] ?? (throw "No expectation named: '$name'."); } diff --git a/pkg/testing/lib/src/run.dart b/pkg/testing/lib/src/run.dart index c628a7a3ca8..a06d328b7bf 100644 --- a/pkg/testing/lib/src/run.dart +++ b/pkg/testing/lib/src/run.dart @@ -206,8 +206,10 @@ ${imports.toString().trim()} Future main() async { if ($isVerbose) enableVerboseOutput(); - Map environment = json.decode('${json.encode(environment)}'); - Set selectors = json.decode('${json.encode(selectors)}').toSet(); + Map environment = + new Map.from(json.decode('${json.encode(environment)}')); + Set selectors = + new Set.from(json.decode('${json.encode(selectors)}')); await runTests( { ${splitLines(dart.toString().trim()).join(' ')} }); diff --git a/pkg/testing/lib/src/run_tests.dart b/pkg/testing/lib/src/run_tests.dart index d1860a11204..ce0849d5588 100644 --- a/pkg/testing/lib/src/run_tests.dart +++ b/pkg/testing/lib/src/run_tests.dart @@ -39,11 +39,11 @@ class CommandLine { Set get skip => commaSeparated("--skip="); Set commaSeparated(String prefix) { - return options.expand((String s) { + return new Set.from(options.expand((String s) { if (!s.startsWith(prefix)) return const []; s = s.substring(prefix.length); return s.split(","); - }).toSet(); + })); } Map get environment { @@ -167,8 +167,8 @@ main(List arguments) => withErrorHandling(() async { print("Running tests took: ${sw.elapsed}."); }); -Future runTests(Map tests) => - withErrorHandling(() async { +Future runTests(Map tests) => + withErrorHandling(() async { int completed = 0; for (String name in tests.keys) { StringBuffer sb = new StringBuffer(); diff --git a/pkg/testing/lib/src/test_dart.dart b/pkg/testing/lib/src/test_dart.dart index 98e2b82db50..8ac84572e1f 100644 --- a/pkg/testing/lib/src/test_dart.dart +++ b/pkg/testing/lib/src/test_dart.dart @@ -29,7 +29,9 @@ class TestDart extends Suite { factory TestDart.fromJsonMap(Uri base, Map json, String name, String kind) { String common = json["common"] ?? ""; String processes = json["processes"] ?? "-j${Platform.numberOfProcessors}"; - List commandLines = json["command-lines"] ?? []; + List commandLines = json["command-lines"] == null + ? new List.from(json["command-lines"]) + : []; return new TestDart(name, common, processes, commandLines); } diff --git a/pkg/testing/lib/src/test_dart/status_file_parser.dart b/pkg/testing/lib/src/test_dart/status_file_parser.dart index 30b32c8c8f6..c7563410988 100644 --- a/pkg/testing/lib/src/test_dart/status_file_parser.dart +++ b/pkg/testing/lib/src/test_dart/status_file_parser.dart @@ -39,7 +39,7 @@ class Section { Section(this.statusFile, this.condition, this.lineNumber) : testRules = new List(); - bool isEnabled(environment) => + bool isEnabled(Map environment) => condition == null || condition.evaluate(environment); String toString() { @@ -48,15 +48,15 @@ class Section { } Future ReadTestExpectations(List statusFilePaths, - Map environment, ExpectationSet expectationSet) { + Map environment, ExpectationSet expectationSet) { var testExpectations = new TestExpectations(expectationSet); return Future.wait(statusFilePaths.map((String statusFile) { return ReadTestExpectationsInto(testExpectations, statusFile, environment); })).then((_) => testExpectations); } -Future ReadTestExpectationsInto( - TestExpectations expectations, String statusFilePath, environment) { +Future ReadTestExpectationsInto(TestExpectations expectations, + String statusFilePath, Map environment) { var completer = new Completer(); List
sections = new List
(); @@ -75,7 +75,7 @@ Future ReadTestExpectationsInto( return completer.future; } -void ReadConfigurationInto(Path path, sections, onDone) { +void ReadConfigurationInto(Path path, List
sections, void onDone()) { StatusFile statusFile = new StatusFile(path); File file = new File(path.toNativePath()); if (!file.existsSync()) { @@ -152,25 +152,25 @@ class TestExpectations { // Only create one copy of each Set. // We just use .toString as a key, so we may make a few // sets that only differ in their toString element order. - static Map _cachedSets = new Map(); + static Map> _cachedSets = {}; final ExpectationSet expectationSet; - Map _map; + Map> _map; bool _preprocessed = false; - Map _regExpCache; - Map _keyToRegExps; + Map _regExpCache; + Map> _keyToRegExps; /** * Create a TestExpectations object. See the [expectations] method * for an explanation of matching. */ - TestExpectations(this.expectationSet) : _map = new Map(); + TestExpectations(this.expectationSet) : _map = {}; /** * Add a rule to the expectations. */ - void addRule(testRule, environment) { + void addRule(TestRule testRule, Map environment) { // Once we have started using the expectations we cannot add more // rules. if (_preprocessed) { @@ -193,7 +193,7 @@ class TestExpectations { * "^$keyComponent\$" matches the corresponding filename component. */ Set expectations(String filename) { - var result = new Set(); + var result = new Set(); var splitFilename = filename.split('/'); // Create mapping from keys to list of RegExps once and for all. @@ -224,13 +224,13 @@ class TestExpectations { void _preprocessForMatching() { if (_preprocessed) return; - _keyToRegExps = new Map(); - _regExpCache = new Map(); + _keyToRegExps = {}; + _regExpCache = {}; _map.forEach((key, expectations) { if (_keyToRegExps[key] != null) return; var splitKey = key.split('/'); - var regExps = new List(splitKey.length); + var regExps = new List(splitKey.length); for (var i = 0; i < splitKey.length; i++) { var component = splitKey[i]; var regExp = _regExpCache[component]; diff --git a/pkg/testing/lib/src/test_root.dart b/pkg/testing/lib/src/test_root.dart index 16aa0c40ab0..9e3b65e7285 100644 --- a/pkg/testing/lib/src/test_root.dart +++ b/pkg/testing/lib/src/test_root.dart @@ -75,8 +75,9 @@ class TestRoot { Uri packages = uri.resolve(data["packages"]); - List suites = new List.from( - data["suites"].map((Map json) => new Suite.fromJsonMap(uri, json))); + List suites = data["suites"] + .map((json) => new Suite.fromJsonMap(uri, json)) + .toList(); Analyze analyze = await Analyze.fromJsonMap(uri, data["analyze"], suites);