[dart2js] Migrate test/equivalence for null safety migration. Change-Id: I376c0312842b43a2b84998ab25e752404f368ec8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279242 Reviewed-by: Mayank Patke <fishythefish@google.com>
diff --git a/pkg/compiler/test/equivalence/check_functions.dart b/pkg/compiler/test/equivalence/check_functions.dart index 0059119..bbe5b89 100644 --- a/pkg/compiler/test/equivalence/check_functions.dart +++ b/pkg/compiler/test/equivalence/check_functions.dart
@@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart = 2.7 - /// Equivalence test functions for data objects. library dart2js.equivalence.functions; @@ -16,10 +14,10 @@ } class JsEquivalenceVisitor extends js.EquivalenceVisitor { - Map<String, String> labelsMap = <String, String>{}; + final labelsMap = <String?, String?>{}; @override - bool failAt(js.Node node1, js.Node node2) { + bool failAt(js.Node? node1, js.Node? node2) { print('Node mismatch:'); print(' ${node1 != null ? js.nodeToString(node1) : '<null>'}'); print(' ${node2 != null ? js.nodeToString(node2) : '<null>'}'); @@ -27,7 +25,8 @@ } @override - bool testValues(js.Node node1, Object value1, js.Node node2, Object value2) { + bool testValues( + js.Node? node1, Object? value1, js.Node? node2, Object? value2) { if (value1 != value2) { print('Value mismatch:'); print(' ${value1}'); @@ -41,10 +40,11 @@ } @override - bool testLabels(js.Node node1, String label1, js.Node node2, String label2) { + bool testLabels( + js.Node node1, String? label1, js.Node node2, String? label2) { if (label1 == null && label2 == null) return true; if (labelsMap.containsKey(label1)) { - String expectedValue = labelsMap[label1]; + String? expectedValue = labelsMap[label1]; if (expectedValue != label2) { print('Value mismatch:'); print(' ${label1}');
diff --git a/pkg/compiler/test/equivalence/check_helpers.dart b/pkg/compiler/test/equivalence/check_helpers.dart index 412d818..849a425 100644 --- a/pkg/compiler/test/equivalence/check_helpers.dart +++ b/pkg/compiler/test/equivalence/check_helpers.dart
@@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart = 2.7 - /// General equivalence test functions. library dart2js.equivalence.helpers; @@ -11,16 +9,16 @@ import 'package:compiler/src/elements/types.dart'; import 'package:expect/expect.dart'; -Check currentCheck; +Check? currentCheck; class Check { - final Check parent; + final Check? parent; final Object object1; final Object object2; final String property; - final Object value1; - final Object value2; - final Function toStringFunc; + final Object? value1; + final Object? value2; + final Function? toStringFunc; Check(this.parent, this.object1, this.object2, this.property, this.value1, this.value2, @@ -28,7 +26,7 @@ String printOn(StringBuffer sb, String indent) { if (parent != null) { - indent = parent.printOn(sb, indent); + indent = parent!.printOn(sb, indent); sb.write('\n$indent|\n'); } sb.write("${indent}property='$property'\n "); @@ -37,7 +35,7 @@ if (value1 == null) { sb.write("null"); } else if (toStringFunc != null) { - sb.write(toStringFunc(value1)); + sb.write(toStringFunc!(value1)); } else { sb.write("'$value1'"); } @@ -47,7 +45,7 @@ if (value2 == null) { sb.write("null"); } else if (toStringFunc != null) { - sb.write(toStringFunc(value2)); + sb.write(toStringFunc!(value2)); } else { sb.write("'$value2'"); } @@ -69,13 +67,13 @@ /// Check that the values [property] of [object1] and [object2], [value1] and /// [value2] respectively, are equal and throw otherwise. bool check<T>(var object1, var object2, String property, T value1, T value2, - [bool equivalence(T a, T b) = equality, String toString(T a)]) { + [bool equivalence(T a, T b) = equality, String toString(T a)?]) { currentCheck = new Check( currentCheck, object1, object2, property, value1, value2, toString); if (!equivalence(value1, value2)) { - throw currentCheck; + throw currentCheck!; } - currentCheck = currentCheck.parent; + currentCheck = currentCheck!.parent; return true; } @@ -96,19 +94,21 @@ checkEquivalence( object1, object2, property, list1.elementAt(i), list2.elementAt(i)); } - for (int i = list1.length; i < list2.length; i++) { + if (list1.length < list2.length) { throw 'Missing equivalent for element ' - '#$i ${list2.elementAt(i)} in `${property}` on $object2.\n' + '#${list1.length} ${list2.elementAt(list1.length)} in ' + '`${property}` on $object2.\n' '`${property}` on $object1:\n ${list1.join('\n ')}\n' '`${property}` on $object2:\n ${list2.join('\n ')}'; } - for (int i = list2.length; i < list1.length; i++) { + if (list2.length < list1.length) { throw 'Missing equivalent for element ' - '#$i ${list1.elementAt(i)} in `${property}` on $object1.\n' + '#${list2.length} ${list1.elementAt(list2.length)} in ' + '`${property}` on $object1.\n' '`${property}` on $object1:\n ${list1.join('\n ')}\n' '`${property}` on $object2:\n ${list2.join('\n ')}'; } - currentCheck = currentCheck.parent; + currentCheck = currentCheck!.parent; return true; } @@ -120,14 +120,14 @@ /// but not in [set1] are returned. Set<E> computeSetDifference<E>( Iterable<E> set1, Iterable<E> set2, List<List<E>> common, List<E> unfound, - {bool sameElement(E a, E b) = equality, void checkElements(E a, E b)}) { + {bool sameElement(E a, E b) = equality, void checkElements(E a, E b)?}) { // TODO(johnniwinther): Avoid the quadratic cost here. Some ideas: // - convert each set to a list and sort it first, then compare by walking // both lists in parallel // - map each element to a canonical object, create a map containing those // mappings, use the mapped sets to compare (then operations like // set.difference would work) - Set remaining = set2.toSet(); + Set<E> remaining = set2.toSet(); for (var element1 in set1) { bool found = false; var correspondingElement; @@ -157,7 +157,7 @@ /// Uses [object1], [object2] and [property] to provide context for failures. bool checkSetEquivalence<E>(var object1, var object2, String property, Iterable<E> set1, Iterable<E> set2, bool sameElement(E a, E b), - {void onSameElement(E a, E b)}) { + {void onSameElement(E a, E b)?}) { var common = <List<E>>[]; var unfound = <E>[]; Set<E> remaining = computeSetDifference(set1, set2, common, unfound, @@ -184,7 +184,7 @@ Map<K, V> map1, Map<K, V> map2, bool sameKey(K a, K b), - bool sameValue(V a, V b), + bool sameValue(V? a, V? b), {bool allowExtra = false}) { var common = <List<K>>[]; var unfound = <K>[]; @@ -208,10 +208,10 @@ void checkLists<T>(List<T> list1, List<T> list2, String messagePrefix, bool sameElement(T a, T b), {bool verbose = false, - void onSameElement(T a, T b), - void onDifferentElements(T a, T b), - void onUnfoundElement(T a), - void onExtraElement(T b), + void onSameElement(T a, T b)?, + void onDifferentElements(T a, T b)?, + void onUnfoundElement(T a)?, + void onExtraElement(T b)?, String elementToString(key) = defaultToString}) { List<List> common = <List>[]; List mismatch = []; @@ -284,11 +284,11 @@ {bool failOnUnfound = true, bool failOnExtra = true, bool verbose = false, - void onSameElement(E a, E b), - void onUnfoundElement(E a), - void onExtraElement(E b), - bool elementFilter(E element), - elementConverter(E element), + void onSameElement(E a, E b)?, + void onUnfoundElement(E a)?, + void onExtraElement(E b)?, + bool elementFilter(E element)?, + E elementConverter(E element)?, String elementToString(E key) = defaultToString}) { if (elementFilter != null) { set1 = set1.where(elementFilter); @@ -341,10 +341,10 @@ String defaultToString(obj) => '$obj'; void checkMaps<K, V>(Map<K, V> map1, Map<K, V> map2, String messagePrefix, - bool sameKey(K a, K b), bool sameValue(V a, V b), + bool sameKey(K a, K b), bool sameValue(V? a, V? b), {bool failOnUnfound = true, bool failOnMismatch = true, - bool keyFilter(K key), + bool keyFilter(K key)?, bool verbose = false, String keyToString(K key) = defaultToString, String valueToString(V key) = defaultToString}) { @@ -359,7 +359,7 @@ keys2 = keys2.where(keyFilter); } var remaining = computeSetDifference(keys1, keys2, common, unfound, - sameElement: sameKey, checkElements: (k1, k2) { + sameElement: sameKey, checkElements: (K k1, K k2) { var v1 = map1[k1]; var v2 = map2[k2]; if (!sameValue(v1, v2)) { @@ -373,8 +373,8 @@ for (List pair in common) { var k1 = pair[0]; var k2 = pair[1]; - var v1 = map1[k1]; - var v2 = map2[k2]; + var v1 = map1[k1]!; + var v2 = map2[k2]!; sb.write(" key1 =${keyToString(k1)}\n"); sb.write(" key2 =${keyToString(k2)}\n"); sb.write(" value1=${valueToString(v1)}\n"); @@ -384,7 +384,7 @@ if (unfound.isNotEmpty || verbose) { sb.write("\n Unfound: \n"); for (var k1 in unfound) { - var v1 = map1[k1]; + var v1 = map1[k1]!; sb.write(" key1 =${keyToString(k1)}\n"); sb.write(" value1=${valueToString(v1)}\n"); } @@ -392,7 +392,7 @@ if (remaining.isNotEmpty || verbose) { sb.write("\n Extra: \n"); for (var k2 in remaining) { - var v2 = map2[k2]; + var v2 = map2[k2]!; sb.write(" key2 =${keyToString(k2)}\n"); sb.write(" value2=${valueToString(v2)}\n"); } @@ -402,8 +402,8 @@ for (List pair in mismatch) { var k1 = pair[0]; var k2 = pair[1]; - var v1 = map1[k1]; - var v2 = map2[k2]; + var v1 = map1[k1]!; + var v2 = map2[k2]!; sb.write(" key1 =${keyToString(k1)}\n"); sb.write(" key2 =${keyToString(k2)}\n"); sb.write(" value1=${valueToString(v1)}\n");
diff --git a/pkg/compiler/test/equivalence/id_equivalence.dart b/pkg/compiler/test/equivalence/id_equivalence.dart index 6a91597..b0e9f78 100644 --- a/pkg/compiler/test/equivalence/id_equivalence.dart +++ b/pkg/compiler/test/equivalence/id_equivalence.dart
@@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart = 2.7 - import 'package:_fe_analyzer_shared/src/testing/id.dart'; import 'package:compiler/src/common.dart'; import 'package:compiler/src/ir/util.dart'; @@ -16,14 +14,9 @@ export 'package:front_end/src/testing/id_extractor.dart'; SourceSpan computeSourceSpanFromUriOffset(Uri uri, int offset) { - if (uri != null) { - if (offset != null && offset != -1) { - return new SourceSpan(uri, offset, offset + 1); - } else { - return new SourceSpan(uri, 0, 0); - } - } - return null; + return offset != -1 + ? SourceSpan(uri, offset, offset + 1) + : SourceSpan(uri, 0, 0); } abstract class IrDataRegistryMixin<T> implements DataRegistry<T> { @@ -55,7 +48,7 @@ @override visitLabeledStatement(ir.LabeledStatement node) { if (!JumpVisitor.canBeBreakTarget(node.body) && - !JumpVisitor.canBeContinueTarget(node.parent)) { + !JumpVisitor.canBeContinueTarget(node.parent!)) { computeForNode(node, createLabeledStatementId(node)); } super.visitLabeledStatement(node);
diff --git a/pkg/compiler/test/equivalence/id_equivalence_helper.dart b/pkg/compiler/test/equivalence/id_equivalence_helper.dart index 0f4ac79..bfca0ef 100644 --- a/pkg/compiler/test/equivalence/id_equivalence_helper.dart +++ b/pkg/compiler/test/equivalence/id_equivalence_helper.dart
@@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart = 2.7 - import 'dart:async'; import 'dart:io'; @@ -86,14 +84,14 @@ /// Fills [actualMap] with the data. void computeClassData( Compiler compiler, ClassEntity cls, Map<Id, ActualData<T>> actualMap, - {bool verbose}) {} + {required bool verbose}) {} /// Function that computes a data mapping for [library]. /// /// Fills [actualMap] with the data. void computeLibraryData(Compiler compiler, LibraryEntity library, Map<Id, ActualData<T>> actualMap, - {bool verbose}) {} + {required bool verbose}) {} /// Returns `true` if this data computer supports tests with compile-time /// errors. @@ -103,7 +101,8 @@ bool get supportsErrors => false; /// Returns data corresponding to [error]. - T computeErrorData(Compiler compiler, Id id, List<CollectedMessage> errors) => + T? computeErrorData( + Compiler compiler, Id id, List<CollectedMessage> errors) => null; DataInterpreter<T> get dataValidator; @@ -122,7 +121,7 @@ /// [entryPoint] and [memorySourceFiles]. /// /// Actual data is computed using [computeMemberData]. -Future<CompiledData<T>> computeData<T>(String name, Uri entryPoint, +Future<CompiledData<T>?> computeData<T>(String name, Uri entryPoint, Map<String, String> memorySourceFiles, DataComputer<T> dataComputer, {List<String> options = const <String>[], bool verbose = false, @@ -132,10 +131,10 @@ bool skipUnprocessedMembers = false, bool skipFailedCompilations = false, Iterable<Id> globalIds = const <Id>[], - Future<void> verifyCompiler(String test, Compiler compiler)}) async { + Future<void> verifyCompiler(String test, Compiler compiler)?}) async { OutputCollector outputCollector = new OutputCollector(); DiagnosticCollector diagnosticCollector = new DiagnosticCollector(); - Uri packageConfig; + Uri? packageConfig; Uri wantedPackageConfig = createUriForFileName(".dart_tool/package_config.json"); for (String key in memorySourceFiles.keys) { @@ -183,15 +182,15 @@ Map<Uri, Map<int, List<CollectedMessage>>> errors = {}; for (CollectedMessage error in diagnosticCollector.errors) { Map<int, List<CollectedMessage>> map = - errors.putIfAbsent(error.uri, () => {}); - List<CollectedMessage> list = map.putIfAbsent(error.begin, () => []); + errors.putIfAbsent(error.uri!, () => {}); + List<CollectedMessage> list = map.putIfAbsent(error.begin!, () => []); list.add(error); } errors.forEach((Uri uri, Map<int, List<CollectedMessage>> map) { map.forEach((int offset, List<CollectedMessage> list) { NodeId id = new NodeId(offset, IdKind.error); - T data = dataComputer.computeErrorData(compiler, id, list); + T? data = dataComputer.computeErrorData(compiler, id, list); if (data != null) { Map<Id, ActualData<T>> actualMap = actualMapForUri(uri); actualMap[id] = new ActualData<T>(id, data, uri, offset, list); @@ -225,7 +224,7 @@ return; } if (member.enclosingClass != null) { - if (elementEnvironment.isEnumClass(member.enclosingClass)) { + if (elementEnvironment.isEnumClass(member.enclosingClass!)) { if (member is ConstructorEntity || member.isInstanceMember || member.name == 'values') { @@ -258,7 +257,7 @@ KernelFrontendStrategy frontendStrategy = compiler.frontendStrategy; KernelToElementMap elementMap = frontendStrategy.elementMap; LibraryEntity kLibrary = - elementMap.elementEnvironment.lookupLibrary(library.canonicalUri); + elementMap.elementEnvironment.lookupLibrary(library.canonicalUri)!; return elementMap.getLibraryNode(kLibrary); } @@ -285,20 +284,20 @@ List<LibraryEntity> globalLibraries = <LibraryEntity>[ commonElements.coreLibrary, - elementEnvironment.lookupLibrary(Uri.parse('dart:collection')), - commonElements.interceptorsLibrary, - commonElements.jsHelperLibrary, - commonElements.asyncLibrary, + elementEnvironment.lookupLibrary(Uri.parse('dart:collection'))!, + commonElements.interceptorsLibrary!, + commonElements.jsHelperLibrary!, + commonElements.asyncLibrary!, ]; - LibraryEntity htmlLibrary = + LibraryEntity? htmlLibrary = elementEnvironment.lookupLibrary(Uri.parse('dart:html'), required: false); if (htmlLibrary != null) { globalLibraries.add(htmlLibrary); } ClassEntity getGlobalClass(String className) { - ClassEntity cls; + ClassEntity? cls; for (LibraryEntity library in globalLibraries) { cls ??= elementEnvironment.lookupClass(library, className); } @@ -306,11 +305,11 @@ cls, "Global class '$className' not found in the global " "libraries: ${globalLibraries.map((l) => l.canonicalUri).join(', ')}"); - return cls; + return cls!; } MemberEntity getGlobalMember(String memberName) { - MemberEntity member; + MemberEntity? member; for (LibraryEntity library in globalLibraries) { member ??= elementEnvironment.lookupLibraryMember(library, memberName); } @@ -318,14 +317,14 @@ member, "Global member '$memberName' not found in the global " "libraries: ${globalLibraries.map((l) => l.canonicalUri).join(', ')}"); - return member; + return member!; } for (Id id in globalIds) { if (id is MemberId) { - MemberEntity member; + MemberEntity? member; if (id.className != null) { - ClassEntity cls = getGlobalClass(id.className); + ClassEntity cls = getGlobalClass(id.className!); member = elementEnvironment.lookupClassMember( cls, Name(id.memberName, cls.library.canonicalUri)); member ??= elementEnvironment.lookupConstructor(cls, id.memberName); @@ -334,7 +333,7 @@ } else { member = getGlobalMember(id.memberName); } - processMember(member, globalData); + processMember(member!, globalData); } else if (id is ClassId) { ClassEntity cls = getGlobalClass(id.className); processClass(cls, globalData); @@ -349,7 +348,7 @@ class Dart2jsCompiledData<T> extends CompiledData<T> { final Compiler compiler; - final ElementEnvironment elementEnvironment; + final ElementEnvironment? elementEnvironment; Dart2jsCompiledData( this.compiler, @@ -363,7 +362,7 @@ int getOffsetFromId(Id id, Uri uri) { return compiler.reporter .spanFromSpannable(computeSpannable(elementEnvironment, uri, id)) - ?.begin; + .begin; } @override @@ -401,17 +400,17 @@ /// file and any supporting libraries. Future<void> checkTests<T>(Directory dataDir, DataComputer<T> dataComputer, {List<String> skip = const <String>[], - bool filterActualData(IdValue idValue, ActualData<T> actualData), + bool filterActualData(IdValue? idValue, ActualData<T> actualData)?, List<String> options = const <String>[], List<String> args = const <String>[], bool forUserLibrariesOnly = true, - Callback setUpFunction, + Callback? setUpFunction, int shards = 1, int shardIndex = 0, - void onTest(Uri uri), + void onTest(Uri uri)?, List<TestConfig> testedConfigs = const [], Map<String, List<String>> perTestOptions = const {}, - Future<void> verifyCompiler(String test, Compiler compiler)}) async { + Future<void> verifyCompiler(String test, Compiler compiler)?}) async { if (testedConfigs.isEmpty) testedConfigs = defaultInternalConfigs; Set<String> testedMarkers = testedConfigs.map((config) => config.marker).toSet(); @@ -424,12 +423,12 @@ Future<Map<String, TestResult<T>>> checkTest( MarkerOptions markerOptions, TestData testData, - {bool testAfterFailures, - bool verbose, - bool succinct, - bool printCode, - Map<String, List<String>> skipMap, - Uri nullUri}) async { + {required bool testAfterFailures, + required bool verbose, + required bool succinct, + required bool printCode, + Map<String, List<String>>? skipMap, + Uri? nullUri}) async { for (TestConfig testConfiguration in testedConfigs) { Expect.isTrue( testData.expectedMaps.containsKey(testConfiguration.marker), @@ -443,7 +442,7 @@ testOptions.add(Flags.enableAsserts); } if (perTestOptions.containsKey(name)) { - testOptions.addAll(perTestOptions[name]); + testOptions.addAll(perTestOptions[name]!); } if (setUpFunction != null) setUpFunction(); @@ -497,16 +496,16 @@ DataComputer<T> dataComputer, TestData testData, List<String> options, - {bool filterActualData(IdValue idValue, ActualData<T> actualData), + {bool filterActualData(IdValue? idValue, ActualData<T> actualData)?, bool verbose = false, bool succinct = false, bool printCode = false, bool forUserLibrariesOnly = true, bool testAfterFailures = false, - Future<void> verifyCompiler(String test, Compiler compiler)}) async { + Future<void> verifyCompiler(String test, Compiler compiler)?}) async { MemberAnnotations<IdValue> annotations = - testData.expectedMaps[testConfiguration.marker]; - CompiledData<T> compiledData = await computeData(testData.name, + testData.expectedMaps[testConfiguration.marker]!; + CompiledData<T> compiledData = (await computeData(testData.name, testData.entryPoint, testData.memorySourceFiles, dataComputer, options: [...options, ...testConfiguration.options], verbose: verbose, @@ -514,7 +513,7 @@ testFrontend: dataComputer.testFrontend, forUserLibrariesOnly: forUserLibrariesOnly, globalIds: annotations.globalData.keys, - verifyCompiler: verifyCompiler); + verifyCompiler: verifyCompiler))!; return await checkCode( markerOptions, testConfiguration.marker, @@ -531,7 +530,7 @@ /// Compute a [Spannable] from an [id] in the library [mainUri]. Spannable computeSpannable( - ElementEnvironment elementEnvironment, Uri mainUri, Id id) { + ElementEnvironment? elementEnvironment, Uri mainUri, Id id) { if (id is NodeId) { return new SourceSpan(mainUri, id.value, id.value + 1); } else if (id is MemberId) { @@ -546,18 +545,18 @@ isSetter = true; memberName = memberName.substring(0, memberName.length - 1); } - LibraryEntity library = elementEnvironment.lookupLibrary(mainUri); + LibraryEntity library = elementEnvironment.lookupLibrary(mainUri)!; if (id.className != null) { - ClassEntity cls = elementEnvironment.lookupClass(library, id.className); + ClassEntity? cls = elementEnvironment.lookupClass(library, id.className!); if (cls == null) { // Constant expression in CFE might remove inlined parts of sources. print("No class '${id.className}' in $mainUri."); return NO_LOCATION_SPANNABLE; } - MemberEntity member = elementEnvironment.lookupClassMember( + MemberEntity? member = elementEnvironment.lookupClassMember( cls, Name(memberName, cls.library.canonicalUri, isSetter: isSetter)); if (member == null) { - ConstructorEntity constructor = + ConstructorEntity? constructor = elementEnvironment.lookupConstructor(cls, memberName); if (constructor == null) { // Constant expression in CFE might remove inlined parts of sources. @@ -568,7 +567,7 @@ } return member; } else { - MemberEntity member = elementEnvironment + MemberEntity? member = elementEnvironment .lookupLibraryMember(library, memberName, setter: isSetter); if (member == null) { // Constant expression in CFE might remove inlined parts of sources. @@ -578,8 +577,8 @@ return member; } } else if (id is ClassId) { - LibraryEntity library = elementEnvironment.lookupLibrary(mainUri); - ClassEntity cls = elementEnvironment.lookupClass(library, id.className); + LibraryEntity library = elementEnvironment!.lookupLibrary(mainUri)!; + ClassEntity? cls = elementEnvironment.lookupClass(library, id.className); if (cls == null) { // Constant expression in CFE might remove inlined parts of sources. print("No class '${id.className}' in $mainUri."); @@ -587,7 +586,7 @@ } return cls; } else if (id is LibraryId) { - return new SourceSpan(id.uri, null, null); + return new SourceSpan(id.uri, 0, 0); } throw new UnsupportedError('Unsupported id $id.'); }
diff --git a/pkg/compiler/test/equivalence/id_testing_test.dart b/pkg/compiler/test/equivalence/id_testing_test.dart index 52fd489..d6f8382 100644 --- a/pkg/compiler/test/equivalence/id_testing_test.dart +++ b/pkg/compiler/test/equivalence/id_testing_test.dart
@@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart = 2.7 - import 'dart:io'; import 'package:async_helper/async_helper.dart'; import 'package:compiler/src/compiler.dart'; @@ -40,7 +38,7 @@ @override void computeClassData( Compiler compiler, ClassEntity cls, Map<Id, ActualData<String>> actualMap, - {bool verbose}) { + {required bool verbose}) { KernelFrontendStrategy frontendStrategy = compiler.frontendStrategy; KernelToElementMap elementMap = frontendStrategy.elementMap; ir.Class node = elementMap.getClassNode(cls); @@ -51,7 +49,7 @@ @override void computeLibraryData(Compiler compiler, LibraryEntity library, Map<Id, ActualData<String>> actualMap, - {bool verbose}) { + {required bool verbose}) { KernelFrontendStrategy frontendStrategy = compiler.frontendStrategy; KernelToElementMap elementMap = frontendStrategy.elementMap; ir.Library node = elementMap.getLibraryNode(library); @@ -65,7 +63,7 @@ @override String computeErrorData( Compiler compiler, Id id, List<CollectedMessage> errors) { - return errors.map((c) => c.message.message).join(','); + return errors.map((c) => c.message!.message).join(','); } @override @@ -99,7 +97,7 @@ String computeMemberName(ir.Member member) { if (member.enclosingClass != null) { - return '${computeClassName(member.enclosingClass)}.' + return '${computeClassName(member.enclosingClass!)}.' '${getMemberName(member)}'; } return getMemberName(member); @@ -111,7 +109,7 @@ } @override - String computeNodeValue(Id id, ir.TreeNode node) { + String? computeNodeValue(Id id, ir.TreeNode node) { if (node is ir.FunctionDeclaration) { return '${computeMemberName(getEnclosingMember(node))}.' '${node.variable.name}';
diff --git a/pkg/compiler/test/equivalence/show_helper.dart b/pkg/compiler/test/equivalence/show_helper.dart index 6f27a86..f06cbb8 100644 --- a/pkg/compiler/test/equivalence/show_helper.dart +++ b/pkg/compiler/test/equivalence/show_helper.dart
@@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart = 2.7 - /// Helper program that shows the equivalence-based data on a dart program. import 'dart:io'; @@ -38,7 +36,7 @@ String file = argResults.rest.first; Uri entryPoint = Uri.base.resolve(nativeToUriPath(file)); - List<String> show; + List<String>? show; if (argResults['all']) { show = null; } else if (argResults.rest.length > 1) { @@ -51,18 +49,18 @@ if (omitImplicitChecks) { options.add(Flags.omitImplicitChecks); } - Dart2jsCompiledData<T> data = await computeData<T>( + Dart2jsCompiledData<T>? data = await computeData<T>( file, entryPoint, const {}, dataComputer, options: options, testFrontend: dataComputer.testFrontend, forUserLibrariesOnly: false, skipUnprocessedMembers: true, skipFailedCompilations: true, - verbose: verbose); + verbose: verbose) as Dart2jsCompiledData<T>?; if (data == null) { print('Compilation failed.'); } else { - SourceFileProvider provider = data.compiler.provider; + final provider = data.compiler.provider as SourceFileProvider; for (Uri uri in data.actualMaps.keys) { Uri fileUri = uri; if (fileUri.isScheme('org-dartlang-sdk')) { @@ -71,18 +69,14 @@ if (show != null && !show.any((f) => '$fileUri'.endsWith(f))) { continue; } - SourceFile<List<int>> sourceFile = - provider.readUtf8FromFileSyncForTesting(fileUri); - String sourceCode = sourceFile?.slowText(); + final sourceFile = provider.readUtf8FromFileSyncForTesting(fileUri) + as SourceFile<List<int>>?; + String? sourceCode = sourceFile?.slowText(); if (sourceCode == null) { sourceCode = new File.fromUri(fileUri).readAsStringSync(); } - if (sourceCode == null) { - print('--source code missing for $uri--------------------------------'); - } else { - print('--annotations for $uri----------------------------------------'); - print(withAnnotations(sourceCode, data.computeAnnotations(uri))); - } + print('--annotations for $uri----------------------------------------'); + print(withAnnotations(sourceCode, data.computeAnnotations(uri))); } } }