From 82e3a751a9b3061cfbaf2d2695fc5cadbd4b8201 Mon Sep 17 00:00:00 2001 From: Johnni Winther Date: Thu, 8 Jun 2023 08:46:47 +0000 Subject: [PATCH] [cfe] Remove unnecessary_null_comparison code The frontend is now run with sound null safety so these are no longer needed. TEST=existing Change-Id: I6c1776845854695ff34e310a3bb5bc9d86715f06 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307901 Reviewed-by: Jens Johansen Reviewed-by: Srujan Gaddam Reviewed-by: Alexander Markov Commit-Queue: Johnni Winther --- .../lib/src/base/errors.dart | 6 +- .../lib/src/messages/codes_generated.dart | 82 +- .../lib/src/parser/parser_impl.dart | 10 - .../lib/src/parser/type_info_impl.dart | 9 +- .../lib/src/scanner/scanner.dart | 2 - .../src/testing/annotated_code_helper.dart | 4 +- .../lib/src/testing/id.dart | 6 +- .../lib/src/testing/id_generation.dart | 9 - .../lib/src/testing/id_testing.dart | 12 +- .../lib/src/util/colors.dart | 2 - .../test/id_generation_test.dart | 4 +- pkg/_fe_analyzer_shared/test/mini_ast.dart | 4 - .../lib/js_interop_checks.dart | 3 +- .../src/api_prototype/experimental_flags.dart | 2 - .../src/api_prototype/language_version.dart | 17 +- .../api_prototype/lowering_predicates.dart | 4 - pkg/front_end/lib/src/api_unstable/ddc.dart | 6 +- .../lib/src/base/processed_options.dart | 3 +- .../compute_platform_binaries_location.dart | 13 +- .../builder/formal_parameter_builder.dart | 2 - .../lib/src/fasta/builder/member_builder.dart | 5 +- .../src/fasta/builder/named_type_builder.dart | 4 +- .../fasta/builder/nullability_builder.dart | 3 - .../builder/type_declaration_builder.dart | 4 +- pkg/front_end/lib/src/fasta/crash.dart | 25 +- .../src/fasta/dill/dill_class_builder.dart | 3 +- .../src/fasta/dill/dill_library_builder.dart | 10 - .../lib/src/fasta/dill/dill_loader.dart | 7 +- .../src/fasta/dill/dill_member_builder.dart | 4 +- .../lib/src/fasta/dill/dill_target.dart | 8 +- .../src/fasta/fasta_codes_cfe_generated.dart | 19 +- .../lib/src/fasta/incremental_compiler.dart | 30 +- .../lib/src/fasta/kernel/body_builder.dart | 26 +- .../lib/src/fasta/kernel/collections.dart | 244 +-- .../kernel/combined_member_signature.dart | 31 +- .../src/fasta/kernel/constant_evaluator.dart | 140 +- .../fasta/kernel/expression_generator.dart | 89 +- .../lib/src/fasta/kernel/forest.dart | 174 --- .../lib/src/fasta/kernel/forwarding_node.dart | 5 - .../fasta/kernel/hierarchy/class_member.dart | 12 +- .../kernel/hierarchy/hierarchy_builder.dart | 2 - .../kernel/hierarchy/hierarchy_node.dart | 13 +- .../fasta/kernel/hierarchy/members_node.dart | 9 +- .../lib/src/fasta/kernel/internal_ast.dart | 364 +---- .../lib/src/fasta/kernel/kernel_target.dart | 16 +- .../lib/src/fasta/kernel/late_lowering.dart | 14 - .../src/fasta/kernel/member_covariance.dart | 2 - .../lib/src/fasta/kernel/type_algorithms.dart | 24 - .../lib/src/fasta/kernel/type_labeler.dart | 6 - .../lib/src/fasta/library_graph.dart | 3 +- pkg/front_end/lib/src/fasta/scope.dart | 5 +- .../lib/src/fasta/source/diet_listener.dart | 4 - .../lib/src/fasta/source/name_scheme.dart | 6 +- .../fasta/source/source_class_builder.dart | 219 ++- .../source/source_extension_builder.dart | 2 - .../fasta/source/source_field_builder.dart | 35 +- .../source/source_inline_class_builder.dart | 2 - .../fasta/source/source_library_builder.dart | 22 +- .../lib/src/fasta/source/source_loader.dart | 18 +- .../source/source_type_alias_builder.dart | 28 +- .../src/fasta/source/stack_listener_impl.dart | 2 - .../fasta/type_inference/closure_context.dart | 10 - .../type_inference/inference_results.dart | 20 +- .../type_inference/inference_visitor.dart | 112 +- .../inference_visitor_base.dart | 91 +- .../type_inference/object_access_target.dart | 8 +- .../type_constraint_gatherer.dart | 30 +- .../fasta/type_inference/type_demotion.dart | 6 +- .../fasta/type_inference/type_inferrer.dart | 8 +- .../type_schema_environment.dart | 2 - .../lib/src/fasta/uri_translator.dart | 2 - .../lib/src/fasta/util/parser_ast.dart | 5 - .../lib/src/fasta/util/textual_outline.dart | 9 +- .../lib/src/testing/id_extractor.dart | 2 - .../lib/src/testing/id_testing_helper.dart | 6 +- pkg/front_end/lib/widget_cache.dart | 6 +- .../crashing_test_case_minimizer_impl.dart | 18 - pkg/front_end/test/fasta/testing/suite.dart | 24 +- pkg/front_end/test/incremental_suite.dart | 3 +- pkg/front_end/test/incremental_utils.dart | 2 - pkg/front_end/test/parser_suite.dart | 15 - pkg/front_end/test/utils/kernel_chain.dart | 4 +- pkg/front_end/tool/_fasta/entry_points.dart | 9 +- .../tool/_fasta/generate_messages.dart | 27 +- pkg/front_end/tool/fasta_perf.dart | 2 - .../tool/kernel_ast_file_rewriter.dart | 4 - pkg/frontend_server/lib/frontend_server.dart | 2 - pkg/kernel/lib/ast.dart | 1379 +++++------------ pkg/kernel/lib/binary/ast_from_binary.dart | 14 +- pkg/kernel/lib/binary/ast_to_binary.dart | 28 +- pkg/kernel/lib/canonical_name.dart | 8 - pkg/kernel/lib/class_hierarchy.dart | 3 - pkg/kernel/lib/clone.dart | 7 +- pkg/kernel/lib/import_table.dart | 6 +- pkg/kernel/lib/src/bounds_checks.dart | 22 +- pkg/kernel/lib/src/const_canonical_type.dart | 3 - pkg/kernel/lib/target/targets.dart | 24 - .../lib/testing/type_parser_environment.dart | 5 +- pkg/kernel/lib/text/ast_to_text.dart | 144 +- .../track_widget_constructor_locations.dart | 3 +- pkg/kernel/lib/type_algebra.dart | 52 +- pkg/kernel/lib/verifier.dart | 25 +- pkg/kernel/lib/visitor.dart | 29 +- pkg/testing/lib/src/error_handling.dart | 5 +- pkg/testing/lib/src/log.dart | 5 +- .../lib/transformations/ffi/finalizable.dart | 23 +- .../transformations/mixin_deduplication.dart | 2 - .../specializer/factory_specializer.dart | 5 - 108 files changed, 828 insertions(+), 3230 deletions(-) diff --git a/pkg/_fe_analyzer_shared/lib/src/base/errors.dart b/pkg/_fe_analyzer_shared/lib/src/base/errors.dart index 683754d00bc..6d275d9375d 100644 --- a/pkg/_fe_analyzer_shared/lib/src/base/errors.dart +++ b/pkg/_fe_analyzer_shared/lib/src/base/errors.dart @@ -53,11 +53,7 @@ abstract class ErrorCode { required String problemMessage, required this.uniqueName, }) : _correctionMessage = correctionMessage, - _problemMessage = problemMessage, - // ignore: unnecessary_null_comparison - assert(hasPublishedDocs != null), - // ignore: unnecessary_null_comparison - assert(isUnresolvedIdentifier != null); + _problemMessage = problemMessage; /** * The template used to create the correction to be displayed for this error, diff --git a/pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart b/pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart index 18b81a63409..9e3a7f7585f 100644 --- a/pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart +++ b/pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart @@ -1501,8 +1501,7 @@ const Code codeConstEvalDeferredLibrary = // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. Message _withArgumentsConstEvalDeferredLibrary(String nameOKEmpty) { - // ignore: unnecessary_null_comparison - if (nameOKEmpty == null || nameOKEmpty.isEmpty) nameOKEmpty = '(unnamed)'; + if (nameOKEmpty.isEmpty) nameOKEmpty = '(unnamed)'; return new Message(codeConstEvalDeferredLibrary, problemMessage: """'${nameOKEmpty}' can't be used in a constant expression because it's marked as 'deferred' which means it isn't available until loaded.""", @@ -1588,8 +1587,7 @@ const Code // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. Message _withArgumentsConstEvalFailedAssertionWithMessage( String stringOKEmpty) { - // ignore: unnecessary_null_comparison - if (stringOKEmpty == null || stringOKEmpty.isEmpty) stringOKEmpty = '(empty)'; + if (stringOKEmpty.isEmpty) stringOKEmpty = '(empty)'; return new Message(codeConstEvalFailedAssertionWithMessage, problemMessage: """This assertion failed with message: ${stringOKEmpty}""", @@ -1622,8 +1620,7 @@ const Code codeConstEvalGetterNotFound = // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. Message _withArgumentsConstEvalGetterNotFound(String nameOKEmpty) { - // ignore: unnecessary_null_comparison - if (nameOKEmpty == null || nameOKEmpty.isEmpty) nameOKEmpty = '(unnamed)'; + if (nameOKEmpty.isEmpty) nameOKEmpty = '(unnamed)'; return new Message(codeConstEvalGetterNotFound, problemMessage: """Variable get not found: '${nameOKEmpty}'""", arguments: {'nameOKEmpty': nameOKEmpty}); @@ -1646,8 +1643,7 @@ const Code // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. Message _withArgumentsConstEvalInvalidStaticInvocation(String nameOKEmpty) { - // ignore: unnecessary_null_comparison - if (nameOKEmpty == null || nameOKEmpty.isEmpty) nameOKEmpty = '(unnamed)'; + if (nameOKEmpty.isEmpty) nameOKEmpty = '(unnamed)'; return new Message(codeConstEvalInvalidStaticInvocation, problemMessage: """The invocation of '${nameOKEmpty}' is not allowed in a constant expression.""", @@ -1704,8 +1700,7 @@ const Code // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. Message _withArgumentsConstEvalNonConstantVariableGet(String nameOKEmpty) { - // ignore: unnecessary_null_comparison - if (nameOKEmpty == null || nameOKEmpty.isEmpty) nameOKEmpty = '(unnamed)'; + if (nameOKEmpty.isEmpty) nameOKEmpty = '(unnamed)'; return new Message(codeConstEvalNonConstantVariableGet, problemMessage: """The variable '${nameOKEmpty}' is not a constant, only constant expressions are allowed.""", @@ -1809,8 +1804,7 @@ const Code // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. Message _withArgumentsConstEvalUnhandledCoreException(String stringOKEmpty) { - // ignore: unnecessary_null_comparison - if (stringOKEmpty == null || stringOKEmpty.isEmpty) stringOKEmpty = '(empty)'; + if (stringOKEmpty.isEmpty) stringOKEmpty = '(empty)'; return new Message(codeConstEvalUnhandledCoreException, problemMessage: """Unhandled core exception: ${stringOKEmpty}""", arguments: {'stringOKEmpty': stringOKEmpty}); @@ -2464,18 +2458,8 @@ const Code< // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. Message _withArgumentsDillOutlineSummary( int count, int count2, num _num1, num _num2, num _num3) { - // ignore: unnecessary_null_comparison - if (count == null) throw 'No count provided'; - // ignore: unnecessary_null_comparison - if (count2 == null) throw 'No count provided'; - // ignore: unnecessary_null_comparison - if (_num1 == null) throw 'No number provided'; String num1 = _num1.toStringAsFixed(3); - // ignore: unnecessary_null_comparison - if (_num2 == null) throw 'No number provided'; String num2 = _num2.toStringAsFixed(3).padLeft(12); - // ignore: unnecessary_null_comparison - if (_num3 == null) throw 'No number provided'; String num3 = _num3.toStringAsFixed(3).padLeft(12); return new Message(codeDillOutlineSummary, problemMessage: @@ -4070,8 +4054,6 @@ Message _withArgumentsExplicitExtensionTypeArgumentMismatch( String name, int count) { if (name.isEmpty) throw 'No name provided'; name = demangleMixinApplicationName(name); - // ignore: unnecessary_null_comparison - if (count == null) throw 'No count provided'; return new Message(codeExplicitExtensionTypeArgumentMismatch, problemMessage: """Explicit extension application of extension '${name}' takes '${count}' type argument(s).""", @@ -4917,10 +4899,6 @@ const Code // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. Message _withArgumentsFfiNativeUnexpectedNumberOfParameters( int count, int count2) { - // ignore: unnecessary_null_comparison - if (count == null) throw 'No count provided'; - // ignore: unnecessary_null_comparison - if (count2 == null) throw 'No count provided'; return new Message(codeFfiNativeUnexpectedNumberOfParameters, problemMessage: """Unexpected number of FfiNative annotation parameters. Expected ${count} but has ${count2}.""", @@ -4946,10 +4924,6 @@ const Code // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. Message _withArgumentsFfiNativeUnexpectedNumberOfParametersWithReceiver( int count, int count2) { - // ignore: unnecessary_null_comparison - if (count == null) throw 'No count provided'; - // ignore: unnecessary_null_comparison - if (count2 == null) throw 'No count provided'; return new Message(codeFfiNativeUnexpectedNumberOfParametersWithReceiver, problemMessage: """Unexpected number of FfiNative annotation parameters. Expected ${count} but has ${count2}. FfiNative instance method annotation must have receiver as first argument.""", @@ -5871,8 +5845,6 @@ const Code codeImplementsRepeated = Message _withArgumentsImplementsRepeated(String name, int count) { if (name.isEmpty) throw 'No name provided'; name = demangleMixinApplicationName(name); - // ignore: unnecessary_null_comparison - if (count == null) throw 'No count provided'; return new Message(codeImplementsRepeated, problemMessage: """'${name}' can only be implemented once.""", correctionMessage: """Try removing ${count} of the occurrences.""", @@ -6430,10 +6402,6 @@ const Code // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. Message _withArgumentsInstantiationTooFewArguments(int count, int count2) { - // ignore: unnecessary_null_comparison - if (count == null) throw 'No count provided'; - // ignore: unnecessary_null_comparison - if (count2 == null) throw 'No count provided'; return new Message(codeInstantiationTooFewArguments, problemMessage: """Too few type arguments: ${count} required, ${count2} given.""", @@ -6460,10 +6428,6 @@ const Code // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. Message _withArgumentsInstantiationTooManyArguments(int count, int count2) { - // ignore: unnecessary_null_comparison - if (count == null) throw 'No count provided'; - // ignore: unnecessary_null_comparison - if (count2 == null) throw 'No count provided'; return new Message(codeInstantiationTooManyArguments, problemMessage: """Too many type arguments: ${count} allowed, but ${count2} found.""", @@ -8621,10 +8585,6 @@ const Code codeLanguageVersionTooHigh = // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. Message _withArgumentsLanguageVersionTooHigh(int count, int count2) { - // ignore: unnecessary_null_comparison - if (count == null) throw 'No count provided'; - // ignore: unnecessary_null_comparison - if (count2 == null) throw 'No count provided'; return new Message(codeLanguageVersionTooHigh, problemMessage: """The specified language version is too high. The highest supported language version is ${count}.${count2}.""", @@ -11849,18 +11809,8 @@ const Code< // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. Message _withArgumentsSourceBodySummary( int count, int count2, num _num1, num _num2, num _num3) { - // ignore: unnecessary_null_comparison - if (count == null) throw 'No count provided'; - // ignore: unnecessary_null_comparison - if (count2 == null) throw 'No count provided'; - // ignore: unnecessary_null_comparison - if (_num1 == null) throw 'No number provided'; String num1 = _num1.toStringAsFixed(3); - // ignore: unnecessary_null_comparison - if (_num2 == null) throw 'No number provided'; String num2 = _num2.toStringAsFixed(3).padLeft(12); - // ignore: unnecessary_null_comparison - if (_num3 == null) throw 'No number provided'; String num3 = _num3.toStringAsFixed(3).padLeft(12); return new Message(codeSourceBodySummary, problemMessage: @@ -11904,18 +11854,8 @@ const Code< // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. Message _withArgumentsSourceOutlineSummary( int count, int count2, num _num1, num _num2, num _num3) { - // ignore: unnecessary_null_comparison - if (count == null) throw 'No count provided'; - // ignore: unnecessary_null_comparison - if (count2 == null) throw 'No count provided'; - // ignore: unnecessary_null_comparison - if (_num1 == null) throw 'No number provided'; String num1 = _num1.toStringAsFixed(3); - // ignore: unnecessary_null_comparison - if (_num2 == null) throw 'No number provided'; String num2 = _num2.toStringAsFixed(3).padLeft(12); - // ignore: unnecessary_null_comparison - if (_num3 == null) throw 'No number provided'; String num3 = _num3.toStringAsFixed(3).padLeft(12); return new Message(codeSourceOutlineSummary, problemMessage: @@ -12553,10 +12493,6 @@ const Code codeTooFewArguments = // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. Message _withArgumentsTooFewArguments(int count, int count2) { - // ignore: unnecessary_null_comparison - if (count == null) throw 'No count provided'; - // ignore: unnecessary_null_comparison - if (count2 == null) throw 'No count provided'; return new Message(codeTooFewArguments, problemMessage: """Too few positional arguments: ${count} required, ${count2} given.""", @@ -12583,10 +12519,6 @@ const Code codeTooManyArguments = // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. Message _withArgumentsTooManyArguments(int count, int count2) { - // ignore: unnecessary_null_comparison - if (count == null) throw 'No count provided'; - // ignore: unnecessary_null_comparison - if (count2 == null) throw 'No count provided'; return new Message(codeTooManyArguments, problemMessage: """Too many positional arguments: ${count} allowed, but ${count2} found.""", @@ -12628,8 +12560,6 @@ const Code codeTypeArgumentMismatch = // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. Message _withArgumentsTypeArgumentMismatch(int count) { - // ignore: unnecessary_null_comparison - if (count == null) throw 'No count provided'; return new Message(codeTypeArgumentMismatch, problemMessage: """Expected ${count} type arguments.""", arguments: {'count': count}); diff --git a/pkg/_fe_analyzer_shared/lib/src/parser/parser_impl.dart b/pkg/_fe_analyzer_shared/lib/src/parser/parser_impl.dart index 219c80ef89b..fee813abda8 100644 --- a/pkg/_fe_analyzer_shared/lib/src/parser/parser_impl.dart +++ b/pkg/_fe_analyzer_shared/lib/src/parser/parser_impl.dart @@ -1897,8 +1897,6 @@ class Parser { /// ``` Token parseFormalParameter( Token token, FormalParameterKind parameterKind, MemberKind memberKind) { - // ignore: unnecessary_null_comparison - assert(parameterKind != null); token = parseMetadataStar(token); Token? skippedNonRequiredRequired; @@ -3159,14 +3157,10 @@ class Parser { /// identifier in the given [context], create a synthetic identifier, report /// an error, and return the synthetic identifier. Token ensureIdentifier(Token token, IdentifierContext context) { - // ignore: unnecessary_null_comparison - assert(context != null); _tryRewriteNewToIdentifier(token, context); Token identifier = token.next!; if (identifier.kind != IDENTIFIER_TOKEN) { identifier = context.ensureIdentifier(token, this); - // ignore: unnecessary_null_comparison - assert(identifier != null); assert(identifier.isKeywordOrIdentifier); } listener.handleIdentifier(identifier, context); @@ -3224,14 +3218,10 @@ class Parser { /// to use the token as an identifier, even if it isn't a valid identifier. Token ensureIdentifierPotentiallyRecovered( Token token, IdentifierContext context, bool isRecovered) { - // ignore: unnecessary_null_comparison - assert(context != null); Token identifier = token.next!; if (identifier.kind != IDENTIFIER_TOKEN) { identifier = context.ensureIdentifierPotentiallyRecovered( token, this, isRecovered); - // ignore: unnecessary_null_comparison - assert(identifier != null); assert(identifier.isKeywordOrIdentifier); } listener.handleIdentifier(identifier, context); diff --git a/pkg/_fe_analyzer_shared/lib/src/parser/type_info_impl.dart b/pkg/_fe_analyzer_shared/lib/src/parser/type_info_impl.dart index 81333dd7eac..3cfae5f23cd 100644 --- a/pkg/_fe_analyzer_shared/lib/src/parser/type_info_impl.dart +++ b/pkg/_fe_analyzer_shared/lib/src/parser/type_info_impl.dart @@ -521,10 +521,7 @@ class ComplexTypeInfo implements TypeInfo { ComplexTypeInfo(Token beforeStart, this.typeArguments) : this.start = beforeStart.next!, - recovered = typeArguments.recovered { - // ignore: unnecessary_null_comparison - assert(typeArguments != null); - } + recovered = typeArguments.recovered; ComplexTypeInfo._nonNullable( this.start, @@ -1226,10 +1223,6 @@ class ComplexTypeParamOrArgInfo extends TypeParamOrArgInfo { ComplexTypeParamOrArgInfo( Token token, this.inDeclaration, this.allowsVariance) : assert(optional('<', token.next!)), - // ignore: unnecessary_null_comparison - assert(inDeclaration != null), - // ignore: unnecessary_null_comparison - assert(allowsVariance != null), start = token.next!; /// Parse the tokens and return the receiver or [noTypeParamOrArg] if there diff --git a/pkg/_fe_analyzer_shared/lib/src/scanner/scanner.dart b/pkg/_fe_analyzer_shared/lib/src/scanner/scanner.dart index 62c5159d517..11fe97a5b6a 100644 --- a/pkg/_fe_analyzer_shared/lib/src/scanner/scanner.dart +++ b/pkg/_fe_analyzer_shared/lib/src/scanner/scanner.dart @@ -85,8 +85,6 @@ ScannerResult scanString(String source, {ScannerConfiguration? configuration, bool includeComments = false, LanguageVersionChanged? languageVersionChanged}) { - // ignore: unnecessary_null_comparison - assert(source != null, 'source must not be null'); StringScanner scanner = new StringScanner(source, configuration: configuration, includeComments: includeComments, diff --git a/pkg/_fe_analyzer_shared/lib/src/testing/annotated_code_helper.dart b/pkg/_fe_analyzer_shared/lib/src/testing/annotated_code_helper.dart index 0477566b427..75cfc13d8d4 100644 --- a/pkg/_fe_analyzer_shared/lib/src/testing/annotated_code_helper.dart +++ b/pkg/_fe_analyzer_shared/lib/src/testing/annotated_code_helper.dart @@ -37,9 +37,7 @@ class Annotation { Annotation(this.index, this.lineNo, this.columnNo, this.offset, this.prefix, this.text, this.suffix) - // ignore: unnecessary_null_comparison - : assert(offset != null), - assert(offset >= 0); + : assert(offset >= 0); @override String toString() => diff --git a/pkg/_fe_analyzer_shared/lib/src/testing/id.dart b/pkg/_fe_analyzer_shared/lib/src/testing/id.dart index 8d9db1afc7e..1953e4ee352 100644 --- a/pkg/_fe_analyzer_shared/lib/src/testing/id.dart +++ b/pkg/_fe_analyzer_shared/lib/src/testing/id.dart @@ -305,11 +305,7 @@ class NodeId implements Id { @override final IdKind kind; - const NodeId(this.value, this.kind) - : - // ignore: unnecessary_null_comparison - assert(value != null), - assert(value >= 0); + const NodeId(this.value, this.kind) : assert(value >= 0); @override bool get isGlobal => false; diff --git a/pkg/_fe_analyzer_shared/lib/src/testing/id_generation.dart b/pkg/_fe_analyzer_shared/lib/src/testing/id_generation.dart index 1be8ff91321..6be2cf16d0d 100644 --- a/pkg/_fe_analyzer_shared/lib/src/testing/id_generation.dart +++ b/pkg/_fe_analyzer_shared/lib/src/testing/id_generation.dart @@ -43,12 +43,6 @@ Map> computeAnnotationsPerUri( actualData .forEach((String marker, Map>> dataPerUri) { dataPerUri.forEach((Uri uri, Map> dataMap) { - // ignore: unnecessary_null_comparison - if (uri == null) { - // TODO(johnniwinther): Avoid `null` URIs. - assert(dataMap.isEmpty, "Non-empty data for `null` uri: $dataMap"); - return; - } uriSet.add(uri); dataMap.forEach((Id id, ActualData data) { Map>> actualDataPerId = @@ -88,9 +82,6 @@ List _computeAnnotations( bool sortMarkers = true, Annotation? Function(Annotation? expected, Annotation? actual)? createDiff, bool forceUpdate = false}) { - // ignore: unnecessary_null_comparison - assert(annotatedCode != null); - Annotation createAnnotationFromData( ActualData actualData, Annotation? annotation) { String getIndentationFromOffset(int offset) { diff --git a/pkg/_fe_analyzer_shared/lib/src/testing/id_testing.dart b/pkg/_fe_analyzer_shared/lib/src/testing/id_testing.dart index d5e2c422412..d0a3d0502c8 100644 --- a/pkg/_fe_analyzer_shared/lib/src/testing/id_testing.dart +++ b/pkg/_fe_analyzer_shared/lib/src/testing/id_testing.dart @@ -225,8 +225,6 @@ void computeExpectedMap(Uri sourceUri, String filename, AnnotatedCode code, split.forEach((String marker, AnnotatedCode code) { MemberAnnotations fileAnnotations = maps[marker]!; - // ignore: unnecessary_null_comparison - assert(fileAnnotations != null, "No annotations for $marker in $maps"); Map expectedValues = fileAnnotations[sourceUri]!; for (Annotation annotation in code.annotations) { String text = annotation.text; @@ -940,13 +938,9 @@ Future runTests(Directory dataDir, actualData[marker] = {}; void addActualData(Uri uri, Map> actualData) { - assert( - // ignore: unnecessary_null_comparison - uri != null && testData.code.containsKey(uri) || - actualData.isEmpty, + assert(testData.code.containsKey(uri) || actualData.isEmpty, "Unexpected data ${actualData} for $uri"); - // ignore: unnecessary_null_comparison - if (uri == null || actualData.isEmpty) { + if (actualData.isEmpty) { // TODO(johnniwinther): Avoid collecting data without // invalid uris. return; @@ -969,8 +963,6 @@ Future runTests(Directory dataDir, dataInterpreter!, forceUpdate: forceUpdate); annotations.forEach((Uri uri, List annotations) { - // ignore: unnecessary_null_comparison - assert(uri != null, "Annotations without uri: $annotations"); AnnotatedCode? code = testData.code[uri]; assert(code != null, "No annotated code for $uri with annotations: $annotations"); diff --git a/pkg/_fe_analyzer_shared/lib/src/util/colors.dart b/pkg/_fe_analyzer_shared/lib/src/util/colors.dart index 3882e59c14c..88fff7d08af 100644 --- a/pkg/_fe_analyzer_shared/lib/src/util/colors.dart +++ b/pkg/_fe_analyzer_shared/lib/src/util/colors.dart @@ -87,8 +87,6 @@ bool get enableColors => _enableColors ??= _computeEnableColors(); /// Allows the client to override the decision of whether to disable ANSI /// colors. void set enableColors(bool value) { - // ignore: unnecessary_null_comparison - assert(value != null); _enableColors = value; } diff --git a/pkg/_fe_analyzer_shared/test/id_generation_test.dart b/pkg/_fe_analyzer_shared/test/id_generation_test.dart index 6297ffedc07..6dfbe685200 100644 --- a/pkg/_fe_analyzer_shared/test/id_generation_test.dart +++ b/pkg/_fe_analyzer_shared/test/id_generation_test.dart @@ -551,9 +551,7 @@ void testGeneral(DataInterpreter dataInterpreter, String text, code.annotatedCode, code.sourceCode, annotations[mainUri]!); String actualResult = generated.toText(); if (expectedResult != actualResult) { - print("Unexpected result for '$text'" - // ignore: unnecessary_null_comparison - "${actualData != null ? ' with actualData=$actualData' : ''}"); + print("Unexpected result for '$text' with actualData=$actualData"); print('---expected-------------------------------------------------------'); print(expectedResult); print('---actual---------------------------------------------------------'); diff --git a/pkg/_fe_analyzer_shared/test/mini_ast.dart b/pkg/_fe_analyzer_shared/test/mini_ast.dart index 8fcb293f809..eb82a4da76f 100644 --- a/pkg/_fe_analyzer_shared/test/mini_ast.dart +++ b/pkg/_fe_analyzer_shared/test/mini_ast.dart @@ -177,8 +177,6 @@ Statement forEachWithNonVariable(Expression iterable, List body) { /// } Statement forEachWithVariableDecl( Var variable, Expression iterable, List body) { - // ignore: unnecessary_null_comparison - assert(variable != null); return new ForEach._(variable, iterable, block(body), true, location: computeLocation()); } @@ -193,8 +191,6 @@ Statement forEachWithVariableDecl( /// } Statement forEachWithVariableSet( Var variable, Expression iterable, List body) { - // ignore: unnecessary_null_comparison - assert(variable != null); var location = computeLocation(); return new ForEach._( variable, iterable, Block._(body, location: location), false, diff --git a/pkg/_js_interop_checks/lib/js_interop_checks.dart b/pkg/_js_interop_checks/lib/js_interop_checks.dart index 2dbdbd7f2ef..6bd58d19d92 100644 --- a/pkg/_js_interop_checks/lib/js_interop_checks.dart +++ b/pkg/_js_interop_checks/lib/js_interop_checks.dart @@ -792,8 +792,7 @@ class JsInteropChecks extends RecursiveVisitor { /// Reports an error if [functionNode] has named parameters. void _checkNoNamedParameters(FunctionNode functionNode) { - // ignore: unnecessary_null_comparison - if (functionNode != null && functionNode.namedParameters.isNotEmpty) { + if (functionNode.namedParameters.isNotEmpty) { final firstNamedParam = functionNode.namedParameters[0]; _reporter.report( messageJsInteropNamedParameters, diff --git a/pkg/front_end/lib/src/api_prototype/experimental_flags.dart b/pkg/front_end/lib/src/api_prototype/experimental_flags.dart index d53bd6f2862..236335995e3 100644 --- a/pkg/front_end/lib/src/api_prototype/experimental_flags.dart +++ b/pkg/front_end/lib/src/api_prototype/experimental_flags.dart @@ -158,8 +158,6 @@ Version getExperimentEnabledVersionInLibrary(ExperimentalFlag flag, } version ??= flag.experimentEnabledVersion; } - // ignore: unnecessary_null_comparison - assert(version != null, "No version for enabling $flag in $canonicalUri."); return version; } diff --git a/pkg/front_end/lib/src/api_prototype/language_version.dart b/pkg/front_end/lib/src/api_prototype/language_version.dart index 94dcb51b170..82cdd7ed90a 100644 --- a/pkg/front_end/lib/src/api_prototype/language_version.dart +++ b/pkg/front_end/lib/src/api_prototype/language_version.dart @@ -40,14 +40,11 @@ Future languageVersionForUri( bool good = false; late final int currentSdkVersionMajor; late final int currentSdkVersionMinor; - // ignore: unnecessary_null_comparison - if (currentSdkVersion != null) { - List dotSeparatedParts = currentSdkVersion.split("."); - if (dotSeparatedParts.length >= 2) { - currentSdkVersionMajor = int.parse(dotSeparatedParts[0]); - currentSdkVersionMinor = int.parse(dotSeparatedParts[1]); - good = true; - } + List dotSeparatedParts = currentSdkVersion.split("."); + if (dotSeparatedParts.length >= 2) { + currentSdkVersionMajor = int.parse(dotSeparatedParts[0]); + currentSdkVersionMinor = int.parse(dotSeparatedParts[1]); + good = true; } if (!good) { throw new StateError("Unparsable sdk version given: $currentSdkVersion"); @@ -67,9 +64,7 @@ Future languageVersionForUri( Uri packageUri = uri; if (!packageUri.isScheme('dart') && !packageUri.isScheme('package') && - package != null && - // ignore: unnecessary_null_comparison - package.name != null) { + package != null) { packageUri = new Uri(scheme: 'package', path: package.name); } diff --git a/pkg/front_end/lib/src/api_prototype/lowering_predicates.dart b/pkg/front_end/lib/src/api_prototype/lowering_predicates.dart index fa7da29c04c..560900e0a5f 100644 --- a/pkg/front_end/lib/src/api_prototype/lowering_predicates.dart +++ b/pkg/front_end/lib/src/api_prototype/lowering_predicates.dart @@ -31,8 +31,6 @@ export '../fasta/kernel/constructor_tearoff_lowering.dart' /// The default value of this field is `null`. bool isLateLoweredField(Field node) { return node.isInternalImplementation && - // ignore: unnecessary_null_comparison - node.name != null && node.name.text.startsWith(lateFieldPrefix) && !node.name.text.endsWith(lateIsSetSuffix); } @@ -87,8 +85,6 @@ Name extractFieldNameFromLateLoweredField(Field node) { /// The default value of this field is `false`. bool isLateLoweredIsSetField(Field node) { return node.isInternalImplementation && - // ignore: unnecessary_null_comparison - node.name != null && node.name.text.startsWith(lateFieldPrefix) && node.name.text.endsWith(lateIsSetSuffix); } diff --git a/pkg/front_end/lib/src/api_unstable/ddc.dart b/pkg/front_end/lib/src/api_unstable/ddc.dart index 7bf57f12882..93c206a0b08 100644 --- a/pkg/front_end/lib/src/api_unstable/ddc.dart +++ b/pkg/front_end/lib/src/api_unstable/ddc.dart @@ -88,9 +88,7 @@ class DdcResult { final Set? neededDillLibraries; DdcResult(this.component, this.sdkSummary, this.additionalDills, - this.classHierarchy, this.neededDillLibraries) - // ignore: unnecessary_null_comparison - : assert(classHierarchy != null); + this.classHierarchy, this.neededDillLibraries); Set computeLibrariesFromDill() { Set librariesFromDill = new Set(); @@ -123,8 +121,6 @@ InitializedCompilerState initializeCompiler( Map? explicitExperimentalFlags, Map? environmentDefines, required NnbdMode nnbdMode}) { - // ignore: unnecessary_null_comparison - assert(nnbdMode != null, "No NnbdMode provided."); additionalDills.sort((a, b) => a.toString().compareTo(b.toString())); if (oldState != null && diff --git a/pkg/front_end/lib/src/base/processed_options.dart b/pkg/front_end/lib/src/base/processed_options.dart index 82ea63c1bec..b26ce3a9323 100644 --- a/pkg/front_end/lib/src/base/processed_options.dart +++ b/pkg/front_end/lib/src/base/processed_options.dart @@ -439,8 +439,7 @@ class ProcessedOptions { Future> loadAdditionalDills(CanonicalName? nameRoot) async { if (_additionalDillComponents == null) { List uris = _raw.additionalDills; - // ignore: unnecessary_null_comparison - if (uris == null || uris.isEmpty) return const []; + if (uris.isEmpty) return const []; // TODO(sigmund): throttle # of concurrent operations. List?> allBytes = await Future.wait( uris.map((uri) => _readAsBytes(fileSystem.entityForUri(uri)))); diff --git a/pkg/front_end/lib/src/compute_platform_binaries_location.dart b/pkg/front_end/lib/src/compute_platform_binaries_location.dart index d9a595002f7..b543881a668 100644 --- a/pkg/front_end/lib/src/compute_platform_binaries_location.dart +++ b/pkg/front_end/lib/src/compute_platform_binaries_location.dart @@ -125,14 +125,11 @@ Uri translateSdk(Uri uri) { if (sdkRoot == null) { sdkRoot = (options.sdkSummary ?? computePlatformBinariesLocation()) .resolve("../../"); - // ignore: unnecessary_null_comparison - if (sdkRoot != null) { - if (!isExistingFile(sdkRoot.resolve("lib/libraries.json"))) { - if (isExistingFile(sdkRoot.resolve("sdk/lib/libraries.json"))) { - sdkRoot = sdkRoot.resolve("sdk/"); - } else { - sdkRoot = null; - } + if (!isExistingFile(sdkRoot.resolve("lib/libraries.json"))) { + if (isExistingFile(sdkRoot.resolve("sdk/lib/libraries.json"))) { + sdkRoot = sdkRoot.resolve("sdk/"); + } else { + sdkRoot = null; } } } diff --git a/pkg/front_end/lib/src/fasta/builder/formal_parameter_builder.dart b/pkg/front_end/lib/src/fasta/builder/formal_parameter_builder.dart index eacb37d75b8..de7527ba00a 100644 --- a/pkg/front_end/lib/src/fasta/builder/formal_parameter_builder.dart +++ b/pkg/front_end/lib/src/fasta/builder/formal_parameter_builder.dart @@ -193,8 +193,6 @@ class FormalParameterBuilder extends ModifierBuilderImpl } FormalParameterBuilder forFormalParameterInitializerScope() { - // ignore: unnecessary_null_comparison - assert(variable != null); if (isInitializingFormal) { return new FormalParameterBuilder( metadata, diff --git a/pkg/front_end/lib/src/fasta/builder/member_builder.dart b/pkg/front_end/lib/src/fasta/builder/member_builder.dart index f0b248e6885..b92d24b1108 100644 --- a/pkg/front_end/lib/src/fasta/builder/member_builder.dart +++ b/pkg/front_end/lib/src/fasta/builder/member_builder.dart @@ -188,10 +188,7 @@ abstract class BuilderClassMember implements ClassMember { String get fullName { String suffix = isSetter ? "=" : ""; String className = classBuilder.fullNameForErrors; - // ignore: unnecessary_null_comparison - return className == null - ? "${fullNameForErrors}$suffix" - : "${className}.${fullNameForErrors}$suffix"; + return "${className}.${fullNameForErrors}$suffix"; } @override diff --git a/pkg/front_end/lib/src/fasta/builder/named_type_builder.dart b/pkg/front_end/lib/src/fasta/builder/named_type_builder.dart index 5401d44e6dc..8df48c21ad5 100644 --- a/pkg/front_end/lib/src/fasta/builder/named_type_builder.dart +++ b/pkg/front_end/lib/src/fasta/builder/named_type_builder.dart @@ -382,9 +382,7 @@ abstract class NamedTypeBuilder extends TypeBuilder { if (declaration!.isTypeVariable) { message = templateSupertypeIsTypeVariable.withArguments(fullNameForErrors); - } else - // ignore: unnecessary_null_comparison - if (type != null && type.nullability == Nullability.nullable) { + } else if (type.nullability == Nullability.nullable) { message = templateSupertypeIsNullableAliased.withArguments( fullNameForErrors, type, library.isNonNullableByDefault); } else { diff --git a/pkg/front_end/lib/src/fasta/builder/nullability_builder.dart b/pkg/front_end/lib/src/fasta/builder/nullability_builder.dart index db68182e356..f88fef59edc 100644 --- a/pkg/front_end/lib/src/fasta/builder/nullability_builder.dart +++ b/pkg/front_end/lib/src/fasta/builder/nullability_builder.dart @@ -55,9 +55,6 @@ class NullabilityBuilder { } Nullability build(LibraryBuilder libraryBuilder) { - // ignore: unnecessary_null_comparison - assert(libraryBuilder != null); - switch (_syntacticNullability) { case SyntacticNullability.legacy: return Nullability.legacy; diff --git a/pkg/front_end/lib/src/fasta/builder/type_declaration_builder.dart b/pkg/front_end/lib/src/fasta/builder/type_declaration_builder.dart index 358215d8aa8..eeeab5db3c7 100644 --- a/pkg/front_end/lib/src/fasta/builder/type_declaration_builder.dart +++ b/pkg/front_end/lib/src/fasta/builder/type_declaration_builder.dart @@ -76,9 +76,7 @@ abstract class TypeDeclarationBuilderImpl extends ModifierBuilderImpl TypeDeclarationBuilderImpl( this.metadata, this.modifiers, this.name, Builder? parent, int charOffset) - // ignore: unnecessary_null_comparison - : assert(modifiers != null), - super(parent, charOffset); + : super(parent, charOffset); @override TypeDeclarationBuilder get origin => this; diff --git a/pkg/front_end/lib/src/fasta/crash.dart b/pkg/front_end/lib/src/fasta/crash.dart index 17e1cc23e34..5a8314709c9 100644 --- a/pkg/front_end/lib/src/fasta/crash.dart +++ b/pkg/front_end/lib/src/fasta/crash.dart @@ -98,20 +98,17 @@ Future reportCrash(error, StackTrace trace, new Crash(uri, charOffset, error, trace).._hasBeenReported = true, trace); } - // ignore: unnecessary_null_comparison - if (request != null) { - await note("\nSending crash report data"); - request.persistentConnection = false; - request.bufferOutput = false; - String? host = request.connectionInfo?.remoteAddress.host; - int? port = request.connectionInfo?.remotePort; - await note(" to $host:$port"); - await request - ..headers.contentType = ContentType.json - ..write(json); - await request.close(); - await note("."); - } + await note("\nSending crash report data"); + request.persistentConnection = false; + request.bufferOutput = false; + String? host = request.connectionInfo?.remoteAddress.host; + int? port = request.connectionInfo?.remotePort; + await note(" to $host:$port"); + await request + ..headers.contentType = ContentType.json + ..write(json); + await request.close(); + await note("."); } catch (e, s) { await note("\n${safeToString(e)}\n$s\n"); await note("\n\n\nFE::ERROR::$json\n\n\n"); diff --git a/pkg/front_end/lib/src/fasta/dill/dill_class_builder.dart b/pkg/front_end/lib/src/fasta/dill/dill_class_builder.dart index 3ca720c7d9f..537edabc404 100644 --- a/pkg/front_end/lib/src/fasta/dill/dill_class_builder.dart +++ b/pkg/front_end/lib/src/fasta/dill/dill_class_builder.dart @@ -234,8 +234,7 @@ int computeModifiers(Class cls) { if (cls.isAbstract) { modifiers |= abstractMask; } - // ignore: unnecessary_null_comparison - if (cls.isMixinApplication && cls.name != null) { + if (cls.isMixinApplication) { modifiers |= namedMixinApplicationMask; } return modifiers; 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 f5d8af7c4ca..1ef10f43d12 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 @@ -340,8 +340,6 @@ class DillLibraryBuilder extends LibraryBuilderImpl { String name; if (sourceBuildersMap?.containsKey(reference) == true) { declaration = sourceBuildersMap![reference]!; - // ignore: unnecessary_null_comparison - assert(declaration != null); if (declaration is ModifierBuilder) { name = declaration.name!; } else { @@ -395,14 +393,6 @@ class DillLibraryBuilder extends LibraryBuilderImpl { library.exportScope.lookupLocalMember(name, setter: false)!; exportScope.addLocalMember(name, declaration, setter: false); } - // ignore: unnecessary_null_comparison - if (declaration == null) { - internalProblem( - templateUnspecified.withArguments( - "Exported element '$name' not found in '$libraryUri'."), - -1, - fileUri); - } } assert( diff --git a/pkg/front_end/lib/src/fasta/dill/dill_loader.dart b/pkg/front_end/lib/src/fasta/dill/dill_loader.dart index 1cf609c4429..bc994b4e6a9 100644 --- a/pkg/front_end/lib/src/fasta/dill/dill_loader.dart +++ b/pkg/front_end/lib/src/fasta/dill/dill_loader.dart @@ -32,7 +32,7 @@ import '../messages.dart' messagePlatformPrivateLibraryAccess, templateInternalProblemContextSeverity; -import '../problems.dart' show internalProblem, unhandled; +import '../problems.dart' show internalProblem; import '../source/source_loader.dart' show SourceLoader; @@ -118,7 +118,6 @@ class DillLoader extends Loader { DillLibraryBuilder? libraryBuilder = _builders[uri]; if (libraryBuilder == null) { libraryBuilder = _knownLibraryBuilders.remove(uri); - // ignore: unnecessary_null_comparison assert(libraryBuilder != null, "No library found for $uri."); _builders[uri] = libraryBuilder!; assert(libraryBuilder.loader == this); @@ -311,10 +310,6 @@ severity: $severity } void buildOutline(DillLibraryBuilder builder) { - // ignore: unnecessary_null_comparison - if (builder.library == null) { - unhandled("null", "builder.library", 0, builder.fileUri); - } builder.markAsReadyToBuild(); } diff --git a/pkg/front_end/lib/src/fasta/dill/dill_member_builder.dart b/pkg/front_end/lib/src/fasta/dill/dill_member_builder.dart index e81109a5206..ad5ea374f9e 100644 --- a/pkg/front_end/lib/src/fasta/dill/dill_member_builder.dart +++ b/pkg/front_end/lib/src/fasta/dill/dill_member_builder.dart @@ -262,9 +262,7 @@ class DillClassMember extends BuilderClassMember { @override final bool forSetter; - DillClassMember(this.memberBuilder, {required this.forSetter}) - // ignore: unnecessary_null_comparison - : assert(forSetter != null); + DillClassMember(this.memberBuilder, {required this.forSetter}); @override bool get isSourceDeclaration => false; diff --git a/pkg/front_end/lib/src/fasta/dill/dill_target.dart b/pkg/front_end/lib/src/fasta/dill/dill_target.dart index d63a6b564f0..4a81132c866 100644 --- a/pkg/front_end/lib/src/fasta/dill/dill_target.dart +++ b/pkg/front_end/lib/src/fasta/dill/dill_target.dart @@ -45,13 +45,7 @@ class DillTarget extends TargetImplementation { final Benchmarker? benchmarker; DillTarget(this.ticker, this.uriTranslator, this.backendTarget, - {this.benchmarker}) - // ignore: unnecessary_null_comparison - : assert(ticker != null), - // ignore: unnecessary_null_comparison - assert(uriTranslator != null), - // ignore: unnecessary_null_comparison - assert(backendTarget != null) { + {this.benchmarker}) { loader = new DillLoader(this); } diff --git a/pkg/front_end/lib/src/fasta/fasta_codes_cfe_generated.dart b/pkg/front_end/lib/src/fasta/fasta_codes_cfe_generated.dart index 7c0c9a8cadc..acb883252c5 100644 --- a/pkg/front_end/lib/src/fasta/fasta_codes_cfe_generated.dart +++ b/pkg/front_end/lib/src/fasta/fasta_codes_cfe_generated.dart @@ -589,8 +589,7 @@ Message _withArgumentsConstEvalInvalidBinaryOperandType( DartType _type, DartType _type2, bool isNonNullableByDefault) { - // ignore: unnecessary_null_comparison - if (stringOKEmpty == null || stringOKEmpty.isEmpty) stringOKEmpty = '(empty)'; + if (stringOKEmpty.isEmpty) stringOKEmpty = '(empty)'; TypeLabeler labeler = new TypeLabeler(isNonNullableByDefault); List constantParts = labeler.labelConstant(_constant); List typeParts = labeler.labelType(_type); @@ -673,8 +672,7 @@ const Code< // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. Message _withArgumentsConstEvalInvalidMethodInvocation( String stringOKEmpty, Constant _constant, bool isNonNullableByDefault) { - // ignore: unnecessary_null_comparison - if (stringOKEmpty == null || stringOKEmpty.isEmpty) stringOKEmpty = '(empty)'; + if (stringOKEmpty.isEmpty) stringOKEmpty = '(empty)'; TypeLabeler labeler = new TypeLabeler(isNonNullableByDefault); List constantParts = labeler.labelConstant(_constant); String constant = constantParts.join(); @@ -711,8 +709,7 @@ const Code< // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. Message _withArgumentsConstEvalInvalidPropertyGet( String stringOKEmpty, Constant _constant, bool isNonNullableByDefault) { - // ignore: unnecessary_null_comparison - if (stringOKEmpty == null || stringOKEmpty.isEmpty) stringOKEmpty = '(empty)'; + if (stringOKEmpty.isEmpty) stringOKEmpty = '(empty)'; TypeLabeler labeler = new TypeLabeler(isNonNullableByDefault); List constantParts = labeler.labelConstant(_constant); String constant = constantParts.join(); @@ -749,8 +746,7 @@ const Code< // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. Message _withArgumentsConstEvalInvalidRecordIndexGet( String stringOKEmpty, Constant _constant, bool isNonNullableByDefault) { - // ignore: unnecessary_null_comparison - if (stringOKEmpty == null || stringOKEmpty.isEmpty) stringOKEmpty = '(empty)'; + if (stringOKEmpty.isEmpty) stringOKEmpty = '(empty)'; TypeLabeler labeler = new TypeLabeler(isNonNullableByDefault); List constantParts = labeler.labelConstant(_constant); String constant = constantParts.join(); @@ -787,8 +783,7 @@ const Code< // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. Message _withArgumentsConstEvalInvalidRecordNameGet( String stringOKEmpty, Constant _constant, bool isNonNullableByDefault) { - // ignore: unnecessary_null_comparison - if (stringOKEmpty == null || stringOKEmpty.isEmpty) stringOKEmpty = '(empty)'; + if (stringOKEmpty.isEmpty) stringOKEmpty = '(empty)'; TypeLabeler labeler = new TypeLabeler(isNonNullableByDefault); List constantParts = labeler.labelConstant(_constant); String constant = constantParts.join(); @@ -2039,10 +2034,6 @@ const Code< // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. Message _withArgumentsIndexOutOfBoundInRecordIndexGet( int count, int count2, DartType _type, bool isNonNullableByDefault) { - // ignore: unnecessary_null_comparison - if (count == null) throw 'No count provided'; - // ignore: unnecessary_null_comparison - if (count2 == null) throw 'No count provided'; TypeLabeler labeler = new TypeLabeler(isNonNullableByDefault); List typeParts = labeler.labelType(_type); String type = typeParts.join(); diff --git a/pkg/front_end/lib/src/fasta/incremental_compiler.dart b/pkg/front_end/lib/src/fasta/incremental_compiler.dart index 349c62ae5be..8c3421cc274 100644 --- a/pkg/front_end/lib/src/fasta/incremental_compiler.dart +++ b/pkg/front_end/lib/src/fasta/incremental_compiler.dart @@ -1465,11 +1465,9 @@ class IncrementalCompiler implements IncrementalKernelGenerator { } if (childReplacementMap == null) return; - Builder replacement = childReplacementMap[declaration.name]!; + Builder? replacement = childReplacementMap[declaration.name]; assert( - // ignore: unnecessary_null_comparison - replacement != null, - "Didn't find the replacement for $typeBuilder"); + replacement != null, "Didn't find the replacement for $typeBuilder"); typeBuilder.bind( parent as LibraryBuilder, replacement as TypeDeclarationBuilder); } @@ -2366,18 +2364,7 @@ class ReusageResult { this.directlyInvalidated, this.invalidatedBecauseOfPackageUpdate, this.reusedLibraries, - this.partUriToParent) - : - // ignore: unnecessary_null_comparison - assert(notReusedLibraries != null), - // ignore: unnecessary_null_comparison - assert(directlyInvalidated != null), - // ignore: unnecessary_null_comparison - assert(invalidatedBecauseOfPackageUpdate != null), - // ignore: unnecessary_null_comparison - assert(reusedLibraries != null), - // ignore: unnecessary_null_comparison - assert(partUriToParent != null); + this.partUriToParent); } class ExperimentalInvalidation { @@ -2386,13 +2373,7 @@ class ExperimentalInvalidation { final Set missingSources; ExperimentalInvalidation( - this.rebuildBodies, this.originalNotReusedLibraries, this.missingSources) - // ignore: unnecessary_null_comparison - : assert(rebuildBodies != null), - // ignore: unnecessary_null_comparison - assert(originalNotReusedLibraries != null), - // ignore: unnecessary_null_comparison - assert(missingSources != null); + this.rebuildBodies, this.originalNotReusedLibraries, this.missingSources); } class IncrementalKernelTarget extends KernelTarget @@ -2637,8 +2618,7 @@ class _InitializationFromUri extends _InitializationFromSdkSummary { context.options.fileSystem.entityForUri(initializeFromDillUri); if (await entity.exists()) { List initializationBytes = await entity.readAsBytes(); - // ignore: unnecessary_null_comparison - if (initializationBytes != null && initializationBytes.isNotEmpty) { + if (initializationBytes.isNotEmpty) { dillLoadedData.ticker.logMs("Read $initializeFromDillUri"); data.initializationBytes = initializationBytes; 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 afc1a3f14f1..966f5757555 100644 --- a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart +++ b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart @@ -424,8 +424,6 @@ class BodyBuilder extends StackListenerImpl } } scope = pop() as Scope; - // ignore: unnecessary_null_comparison - assert(scope != null); } void enterBreakTarget(int charOffset, [JumpTarget? target]) { @@ -1497,20 +1495,11 @@ class BodyBuilder extends StackListenerImpl // set its inferredType field. If type inference is disabled, reach to // the outermost parent to check if the node is a dead code. if (invocation.parent == null) continue; - // ignore: unnecessary_null_comparison - if (typeInferrer != null) { - if (!invocation.hasBeenInferred) { - if (allowFurtherDelays) { - delayedRedirectingFactoryInvocations.add(invocation); - } - continue; + if (!invocation.hasBeenInferred) { + if (allowFurtherDelays) { + delayedRedirectingFactoryInvocations.add(invocation); } - } else { - TreeNode? parent = invocation.parent; - while (parent is! Component && parent != null) { - parent = parent.parent; - } - if (parent == null) continue; + continue; } Expression? replacement = _resolveRedirectingFactoryTarget( invocation.target, @@ -6400,8 +6389,7 @@ class BodyBuilder extends StackListenerImpl } List typeArgumentsToCheck = const []; - // ignore: unnecessary_null_comparison - if (typeArgumentBuilders != null && typeArgumentBuilders.isNotEmpty) { + if (typeArgumentBuilders.isNotEmpty) { typeArgumentsToCheck = new List.filled( typeArgumentBuilders.length, const DynamicType(), growable: false); @@ -8925,8 +8913,6 @@ class BodyBuilder extends StackListenerImpl @override TypeBuilder validateTypeVariableUse(TypeBuilder typeBuilder, {required bool allowPotentiallyConstantType}) { - // ignore: unnecessary_null_comparison - assert(allowPotentiallyConstantType != null); _validateTypeVariableUseInternal(typeBuilder, allowPotentiallyConstantType: allowPotentiallyConstantType); return typeBuilder; @@ -8934,8 +8920,6 @@ class BodyBuilder extends StackListenerImpl void _validateTypeVariableUseInternal(TypeBuilder? builder, {required bool allowPotentiallyConstantType}) { - // ignore: unnecessary_null_comparison - assert(allowPotentiallyConstantType != null); if (builder is NamedTypeBuilder) { if (builder.declaration!.isTypeVariable) { TypeVariableBuilder typeParameterBuilder = diff --git a/pkg/front_end/lib/src/fasta/kernel/collections.dart b/pkg/front_end/lib/src/fasta/kernel/collections.dart index 821edd1e830..aca0a8d18fb 100644 --- a/pkg/front_end/lib/src/fasta/kernel/collections.dart +++ b/pkg/front_end/lib/src/fasta/kernel/collections.dart @@ -67,11 +67,7 @@ class SpreadElement extends Expression with ControlFlowElement { /// during the desugaring. DartType? elementType; - SpreadElement(this.expression, {required this.isNullAware}) - // ignore: unnecessary_null_comparison - : assert(expression != null), - // ignore: unnecessary_null_comparison - assert(isNullAware != null) { + SpreadElement(this.expression, {required this.isNullAware}) { expression.parent = this; } @@ -82,20 +78,14 @@ class SpreadElement extends Expression with ControlFlowElement { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (expression != null) { - expression = v.transform(expression); - expression.parent = this; - } + expression = v.transform(expression); + expression.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (expression != null) { - expression = v.transform(expression); - expression.parent = this; - } + expression = v.transform(expression); + expression.parent = this; } @override @@ -126,11 +116,7 @@ class IfElement extends Expression with ControlFlowElement { Expression then; Expression? otherwise; - IfElement(this.condition, this.then, this.otherwise) - // ignore: unnecessary_null_comparison - : assert(condition != null), - // ignore: unnecessary_null_comparison - assert(then != null) { + IfElement(this.condition, this.then, this.otherwise) { condition.parent = this; then.parent = this; otherwise?.parent = this; @@ -145,16 +131,10 @@ class IfElement extends Expression with ControlFlowElement { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (condition != null) { - condition = v.transform(condition); - condition.parent = this; - } - // ignore: unnecessary_null_comparison - if (then != null) { - then = v.transform(then); - then.parent = this; - } + condition = v.transform(condition); + condition.parent = this; + then = v.transform(then); + then.parent = this; if (otherwise != null) { otherwise = v.transform(otherwise!); otherwise?.parent = this; @@ -163,16 +143,10 @@ class IfElement extends Expression with ControlFlowElement { @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (condition != null) { - condition = v.transform(condition); - condition.parent = this; - } - // ignore: unnecessary_null_comparison - if (then != null) { - then = v.transform(then); - then.parent = this; - } + condition = v.transform(condition); + condition.parent = this; + then = v.transform(then); + then.parent = this; if (otherwise != null) { otherwise = v.transformOrRemoveExpression(otherwise!); otherwise?.parent = this; @@ -229,9 +203,7 @@ class ForElement extends Expression with ControlFlowElement { final List updates; // May be empty, but not null. Expression body; - ForElement(this.variables, this.condition, this.updates, this.body) - // ignore: unnecessary_null_comparison - : assert(body != null) { + ForElement(this.variables, this.condition, this.updates, this.body) { setParents(variables, this); condition?.parent = this; setParents(updates, this); @@ -254,11 +226,8 @@ class ForElement extends Expression with ControlFlowElement { condition?.parent = this; } v.transformList(updates, this); - // ignore: unnecessary_null_comparison - if (body != null) { - body = v.transform(body); - body.parent = this; - } + body = v.transform(body); + body.parent = this; } @override @@ -269,11 +238,8 @@ class ForElement extends Expression with ControlFlowElement { condition?.parent = this; } v.transformExpressionList(updates, this); - // ignore: unnecessary_null_comparison - if (body != null) { - body = v.transform(body); - body.parent = this; - } + body = v.transform(body); + body.parent = this; } @override @@ -331,13 +297,7 @@ class ForInElement extends Expression with ControlFlowElement { ForInElement(this.variable, this.iterable, this.syntheticAssignment, this.expressionEffects, this.body, this.problem, - {this.isAsync = false}) - // ignore: unnecessary_null_comparison - : assert(variable != null), - // ignore: unnecessary_null_comparison - assert(iterable != null), - // ignore: unnecessary_null_comparison - assert(body != null) { + {this.isAsync = false}) { variable.parent = this; iterable.parent = this; syntheticAssignment?.parent = this; @@ -363,16 +323,10 @@ class ForInElement extends Expression with ControlFlowElement { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (variable != null) { - variable = v.transform(variable); - variable.parent = this; - } - // ignore: unnecessary_null_comparison - if (iterable != null) { - iterable = v.transform(iterable); - iterable.parent = this; - } + variable = v.transform(variable); + variable.parent = this; + iterable = v.transform(iterable); + iterable.parent = this; if (syntheticAssignment != null) { syntheticAssignment = v.transform(syntheticAssignment!); syntheticAssignment?.parent = this; @@ -381,11 +335,8 @@ class ForInElement extends Expression with ControlFlowElement { expressionEffects = v.transform(expressionEffects!); expressionEffects?.parent = this; } - // ignore: unnecessary_null_comparison - if (body != null) { - body = v.transform(body); - body.parent = this; - } + body = v.transform(body); + body.parent = this; if (problem != null) { problem = v.transform(problem!); problem?.parent = this; @@ -394,16 +345,10 @@ class ForInElement extends Expression with ControlFlowElement { @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (variable != null) { - variable = v.transform(variable); - variable.parent = this; - } - // ignore: unnecessary_null_comparison - if (iterable != null) { - iterable = v.transform(iterable); - iterable.parent = this; - } + variable = v.transform(variable); + variable.parent = this; + iterable = v.transform(iterable); + iterable.parent = this; if (syntheticAssignment != null) { syntheticAssignment = v.transformOrRemoveExpression(syntheticAssignment!); syntheticAssignment?.parent = this; @@ -412,11 +357,8 @@ class ForInElement extends Expression with ControlFlowElement { expressionEffects = v.transformOrRemoveStatement(expressionEffects!); expressionEffects?.parent = this; } - // ignore: unnecessary_null_comparison - if (body != null) { - body = v.transform(body); - body.parent = this; - } + body = v.transform(body); + body.parent = this; if (problem != null) { problem = v.transformOrRemoveExpression(problem!); problem?.parent = this; @@ -493,11 +435,7 @@ class SpreadMapEntry extends TreeNode with ControlFlowMapEntry { /// during the desugaring. DartType? entryType; - SpreadMapEntry(this.expression, {required this.isNullAware}) - // ignore: unnecessary_null_comparison - : assert(expression != null), - // ignore: unnecessary_null_comparison - assert(isNullAware != null) { + SpreadMapEntry(this.expression, {required this.isNullAware}) { expression.parent = this; } @@ -508,20 +446,14 @@ class SpreadMapEntry extends TreeNode with ControlFlowMapEntry { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (expression != null) { - expression = v.transform(expression); - expression.parent = this; - } + expression = v.transform(expression); + expression.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (expression != null) { - expression = v.transform(expression); - expression.parent = this; - } + expression = v.transform(expression); + expression.parent = this; } @override @@ -542,11 +474,7 @@ class IfMapEntry extends TreeNode with ControlFlowMapEntry { MapLiteralEntry then; MapLiteralEntry? otherwise; - IfMapEntry(this.condition, this.then, this.otherwise) - // ignore: unnecessary_null_comparison - : assert(condition != null), - // ignore: unnecessary_null_comparison - assert(then != null) { + IfMapEntry(this.condition, this.then, this.otherwise) { condition.parent = this; then.parent = this; otherwise?.parent = this; @@ -561,16 +489,10 @@ class IfMapEntry extends TreeNode with ControlFlowMapEntry { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (condition != null) { - condition = v.transform(condition); - condition.parent = this; - } - // ignore: unnecessary_null_comparison - if (then != null) { - then = v.transform(then); - then.parent = this; - } + condition = v.transform(condition); + condition.parent = this; + then = v.transform(then); + then.parent = this; if (otherwise != null) { otherwise = v.transform(otherwise!); otherwise?.parent = this; @@ -579,16 +501,10 @@ class IfMapEntry extends TreeNode with ControlFlowMapEntry { @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (condition != null) { - condition = v.transform(condition); - condition.parent = this; - } - // ignore: unnecessary_null_comparison - if (then != null) { - then = v.transform(then); - then.parent = this; - } + condition = v.transform(condition); + condition.parent = this; + then = v.transform(then); + then.parent = this; if (otherwise != null) { otherwise = v.transformOrRemove(otherwise!, dummyMapLiteralEntry); otherwise?.parent = this; @@ -620,9 +536,7 @@ class ForMapEntry extends TreeNode with ControlFlowMapEntry { final List updates; // May be empty, but not null. MapLiteralEntry body; - ForMapEntry(this.variables, this.condition, this.updates, this.body) - // ignore: unnecessary_null_comparison - : assert(body != null) { + ForMapEntry(this.variables, this.condition, this.updates, this.body) { setParents(variables, this); condition?.parent = this; setParents(updates, this); @@ -645,11 +559,8 @@ class ForMapEntry extends TreeNode with ControlFlowMapEntry { condition?.parent = this; } v.transformList(updates, this); - // ignore: unnecessary_null_comparison - if (body != null) { - body = v.transform(body); - body.parent = this; - } + body = v.transform(body); + body.parent = this; } @override @@ -660,11 +571,8 @@ class ForMapEntry extends TreeNode with ControlFlowMapEntry { condition?.parent = this; } v.transformExpressionList(updates, this); - // ignore: unnecessary_null_comparison - if (body != null) { - body = v.transform(body); - body.parent = this; - } + body = v.transform(body); + body.parent = this; } @override @@ -705,13 +613,7 @@ class ForInMapEntry extends TreeNode with ControlFlowMapEntry { ForInMapEntry(this.variable, this.iterable, this.syntheticAssignment, this.expressionEffects, this.body, this.problem, - {required this.isAsync}) - // ignore: unnecessary_null_comparison - : assert(iterable != null), - // ignore: unnecessary_null_comparison - assert(body != null), - // ignore: unnecessary_null_comparison - assert(isAsync != null) { + {required this.isAsync}) { variable.parent = this; iterable.parent = this; syntheticAssignment?.parent = this; @@ -737,16 +639,10 @@ class ForInMapEntry extends TreeNode with ControlFlowMapEntry { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (variable != null) { - variable = v.transform(variable); - variable.parent = this; - } - // ignore: unnecessary_null_comparison - if (iterable != null) { - iterable = v.transform(iterable); - iterable.parent = this; - } + variable = v.transform(variable); + variable.parent = this; + iterable = v.transform(iterable); + iterable.parent = this; if (syntheticAssignment != null) { syntheticAssignment = v.transform(syntheticAssignment!); syntheticAssignment?.parent = this; @@ -755,11 +651,8 @@ class ForInMapEntry extends TreeNode with ControlFlowMapEntry { expressionEffects = v.transform(expressionEffects!); expressionEffects?.parent = this; } - // ignore: unnecessary_null_comparison - if (body != null) { - body = v.transform(body); - body.parent = this; - } + body = v.transform(body); + body.parent = this; if (problem != null) { problem = v.transform(problem!); problem?.parent = this; @@ -768,16 +661,10 @@ class ForInMapEntry extends TreeNode with ControlFlowMapEntry { @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (variable != null) { - variable = v.transform(variable); - variable.parent = this; - } - // ignore: unnecessary_null_comparison - if (iterable != null) { - iterable = v.transform(iterable); - iterable.parent = this; - } + variable = v.transform(variable); + variable.parent = this; + iterable = v.transform(iterable); + iterable.parent = this; if (syntheticAssignment != null) { syntheticAssignment = v.transformOrRemoveExpression(syntheticAssignment!); syntheticAssignment?.parent = this; @@ -786,11 +673,8 @@ class ForInMapEntry extends TreeNode with ControlFlowMapEntry { expressionEffects = v.transformOrRemoveStatement(expressionEffects!); expressionEffects?.parent = this; } - // ignore: unnecessary_null_comparison - if (body != null) { - body = v.transform(body); - body.parent = this; - } + body = v.transform(body); + body.parent = this; if (problem != null) { problem = v.transformOrRemoveExpression(problem!); problem?.parent = this; diff --git a/pkg/front_end/lib/src/fasta/kernel/combined_member_signature.dart b/pkg/front_end/lib/src/fasta/kernel/combined_member_signature.dart index a2ca1ab2a5b..dada39d8662 100644 --- a/pkg/front_end/lib/src/fasta/kernel/combined_member_signature.dart +++ b/pkg/front_end/lib/src/fasta/kernel/combined_member_signature.dart @@ -104,9 +104,7 @@ abstract class CombinedMemberSignatureBase { /// Creates a [CombinedClassMemberSignature] whose canonical member is already /// defined. CombinedMemberSignatureBase.internal( - this.classBuilder, this._canonicalMemberIndex, this.forSetter) - // ignore: unnecessary_null_comparison - : assert(forSetter != null); + this.classBuilder, this._canonicalMemberIndex, this.forSetter); /// Creates a [CombinedClassMemberSignature] for [members] inherited into /// [classBuilder]. @@ -115,8 +113,6 @@ abstract class CombinedMemberSignatureBase { /// compute the most specific member type. Otherwise covariance of the getter /// types or function types is used. CombinedMemberSignatureBase(this.classBuilder, {required this.forSetter}) { - // ignore: unnecessary_null_comparison - assert(forSetter != null); int? bestSoFarIndex; if (members.length == 1) { bestSoFarIndex = 0; @@ -292,9 +288,6 @@ abstract class CombinedMemberSignatureBase { DartType? candidateType = _memberTypes![index]; if (candidateType == null) { Member target = _getMember(index); - // ignore: unnecessary_null_comparison - assert(target != null, - "No member computed for index ${index} in ${members}"); candidateType = _computeMemberType(thisType, target); if (!classBuilder.libraryBuilder.isNonNullableByDefault) { DartType? legacyErasure; @@ -526,8 +519,6 @@ abstract class CombinedMemberSignatureBase { /// [type]. Procedure _createGetterMemberSignature(Member member, DartType type, {required bool copyLocation}) { - // ignore: unnecessary_null_comparison - assert(copyLocation != null); Class enclosingClass = classBuilder.cls; Reference? reference = classBuilder.referencesFromIndexed?.lookupGetterReference(member.name); @@ -570,12 +561,6 @@ abstract class CombinedMemberSignatureBase { required bool isCovariantByClass, VariableDeclaration? parameter, required bool copyLocation}) { - // ignore: unnecessary_null_comparison - assert(isCovariantByDeclaration != null); - // ignore: unnecessary_null_comparison - assert(isCovariantByClass != null); - // ignore: unnecessary_null_comparison - assert(copyLocation != null); Class enclosingClass = classBuilder.cls; Reference? reference = classBuilder.referencesFromIndexed?.lookupSetterReference(member.name); @@ -620,8 +605,6 @@ abstract class CombinedMemberSignatureBase { Procedure _createMethodSignature( Procedure procedure, FunctionType functionType, {required bool copyLocation}) { - // ignore: unnecessary_null_comparison - assert(copyLocation != null); Class enclosingClass = classBuilder.cls; Reference? reference = classBuilder.referencesFromIndexed ?.lookupGetterReference(procedure.name); @@ -778,21 +761,13 @@ class CombinedClassMemberSignature @override Member _getMember(int index) { ClassMember candidate = members[index]; - Member target = candidate.getMember(membersBuilder); - // ignore: unnecessary_null_comparison - assert(target != null, - "No member computed for ${candidate} (${candidate.runtimeType})"); - return target; + return candidate.getMember(membersBuilder); } @override Covariance _getMemberCovariance(int index) { ClassMember candidate = members[index]; - Covariance covariance = candidate.getCovariance(membersBuilder); - // ignore: unnecessary_null_comparison - assert(covariance != null, - "No covariance computed for ${candidate} (${candidate.runtimeType})"); - return covariance; + return candidate.getCovariance(membersBuilder); } } diff --git a/pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart b/pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart index 9a6686114f0..18f74ecf423 100644 --- a/pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart +++ b/pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart @@ -64,18 +64,6 @@ Component transformComponent( CoreTypes? coreTypes, ClassHierarchy? hierarchy, ExhaustivenessDataForTesting? exhaustivenessDataForTesting}) { - // ignore: unnecessary_null_comparison - assert(evaluateAnnotations != null); - // ignore: unnecessary_null_comparison - assert(desugarSets != null); - // ignore: unnecessary_null_comparison - assert(enableTripleShift != null); - // ignore: unnecessary_null_comparison - assert(enableConstFunctions != null); - // ignore: unnecessary_null_comparison - assert(errorOnUnevaluatedConstant != null); - // ignore: unnecessary_null_comparison - assert(enableConstructorTearOff != null); coreTypes ??= new CoreTypes(component); hierarchy ??= new ClassHierarchy(component, coreTypes); @@ -106,16 +94,6 @@ ConstantEvaluationData transformLibraries( required bool errorOnUnevaluatedConstant, required bool enableConstructorTearOff, ExhaustivenessDataForTesting? exhaustivenessDataForTesting}) { - // ignore: unnecessary_null_comparison - assert(evaluateAnnotations != null); - // ignore: unnecessary_null_comparison - assert(enableTripleShift != null); - // ignore: unnecessary_null_comparison - assert(enableConstFunctions != null); - // ignore: unnecessary_null_comparison - assert(errorOnUnevaluatedConstant != null); - // ignore: unnecessary_null_comparison - assert(enableConstructorTearOff != null); final ConstantsTransformer constantsTransformer = new ConstantsTransformer( target, environmentDefines, @@ -151,16 +129,6 @@ void transformProcedure( required bool enableConstFunctions, required bool enableConstructorTearOff, required bool errorOnUnevaluatedConstant}) { - // ignore: unnecessary_null_comparison - assert(evaluateAnnotations != null); - // ignore: unnecessary_null_comparison - assert(enableTripleShift != null); - // ignore: unnecessary_null_comparison - assert(enableConstFunctions != null); - // ignore: unnecessary_null_comparison - assert(errorOnUnevaluatedConstant != null); - // ignore: unnecessary_null_comparison - assert(enableConstructorTearOff != null); final ConstantsTransformer constantsTransformer = new ConstantsTransformer( target, environmentDefines, @@ -657,10 +625,7 @@ class ConstantsTransformer extends RemovingTransformer { TreeNode visitFunctionDeclaration( FunctionDeclaration node, TreeNode? removalSentinel) { if (enableConstFunctions) { - // ignore: unnecessary_null_comparison - if (node.function != null) { - node.function = transform(node.function)..parent = node; - } + node.function = transform(node.function)..parent = node; constantEvaluator.env.addVariableValue( node.variable, new FunctionValue(node.function, null)); } else { @@ -1609,27 +1574,23 @@ class ConstantsTransformer extends RemovingTransformer { TreeNode visitSwitchStatement( SwitchStatement node, TreeNode? removalSentinel) { TreeNode result = super.visitSwitchStatement(node, removalSentinel); - Library library = currentLibrary; - // ignore: unnecessary_null_comparison - if (library != null) { - for (SwitchCase switchCase in node.cases) { - for (Expression caseExpression in switchCase.expressions) { - if (caseExpression is ConstantExpression) { - if (!constantEvaluator.hasPrimitiveEqual(caseExpression.constant, - staticTypeContext: staticTypeContext)) { - constantEvaluator.errorReporter.report( - constantEvaluator.createLocatedMessage( - caseExpression, - templateConstEvalCaseImplementsEqual.withArguments( - caseExpression.constant, - staticTypeContext.nonNullable == - Nullability.nonNullable)), - null); - } - } else { - // If caseExpression is not ConstantExpression, an error is - // reported elsewhere. + for (SwitchCase switchCase in node.cases) { + for (Expression caseExpression in switchCase.expressions) { + if (caseExpression is ConstantExpression) { + if (!constantEvaluator.hasPrimitiveEqual(caseExpression.constant, + staticTypeContext: staticTypeContext)) { + constantEvaluator.errorReporter.report( + constantEvaluator.createLocatedMessage( + caseExpression, + templateConstEvalCaseImplementsEqual.withArguments( + caseExpression.constant, + staticTypeContext.nonNullable == + Nullability.nonNullable)), + null); } + } else { + // If caseExpression is not ConstantExpression, an error is + // reported elsewhere. } } } @@ -2871,8 +2832,6 @@ class ConstantEvaluator implements ExpressionVisitor { return error; } assert(_gotError == null); - // ignore: unnecessary_null_comparison - assert(type != null); return canonicalize(new TypeLiteralConstant(type)); } @@ -2912,8 +2871,6 @@ class ConstantEvaluator implements ExpressionVisitor { return error; } assert(_gotError == null); - // ignore: unnecessary_null_comparison - assert(type != null); final ListConstantBuilder builder = new ListConstantBuilder( node, convertType(type), this, @@ -2949,8 +2906,6 @@ class ConstantEvaluator implements ExpressionVisitor { return error; } assert(_gotError == null); - // ignore: unnecessary_null_comparison - assert(positional != null); Map? named = _evaluateNamedArguments(node.named); if (named == null) { @@ -2959,8 +2914,6 @@ class ConstantEvaluator implements ExpressionVisitor { return error; } assert(_gotError == null); - // ignore: unnecessary_null_comparison - assert(named != null); if (shouldBeUnevaluated) { return unevaluated( @@ -3003,8 +2956,6 @@ class ConstantEvaluator implements ExpressionVisitor { return error; } assert(_gotError == null); - // ignore: unnecessary_null_comparison - assert(type != null); final SetConstantBuilder builder = new SetConstantBuilder(node, convertType(type), this); @@ -3050,8 +3001,6 @@ class ConstantEvaluator implements ExpressionVisitor { return error; } assert(_gotError == null); - // ignore: unnecessary_null_comparison - assert(keyType != null); DartType? valueType = _evaluateDartType(node, node.valueType); if (valueType == null) { @@ -3060,8 +3009,6 @@ class ConstantEvaluator implements ExpressionVisitor { return error; } assert(_gotError == null); - // ignore: unnecessary_null_comparison - assert(valueType != null); final MapConstantBuilder builder = new MapConstantBuilder( node, convertType(keyType), convertType(valueType), this); @@ -3127,8 +3074,6 @@ class ConstantEvaluator implements ExpressionVisitor { return error; } assert(_gotError == null); - // ignore: unnecessary_null_comparison - assert(positional != null); final Map? named = _evaluateNamedArguments(node.arguments.named); @@ -3138,8 +3083,6 @@ class ConstantEvaluator implements ExpressionVisitor { return error; } assert(_gotError == null); - // ignore: unnecessary_null_comparison - assert(named != null); bool isSymbol = klass == coreTypes.internalSymbolClass; if (isSymbol && shouldBeUnevaluated) { @@ -3174,8 +3117,6 @@ class ConstantEvaluator implements ExpressionVisitor { return error; } assert(_gotError == null); - // ignore: unnecessary_null_comparison - assert(types != null); final List typeArguments = convertTypes(types); @@ -3307,8 +3248,6 @@ class ConstantEvaluator implements ExpressionVisitor { 'unary-' }; - // ignore: unnecessary_null_comparison - if (name == null) return false; if (name == '') return true; final List parts = name.split('.'); @@ -3463,8 +3402,6 @@ class ConstantEvaluator implements ExpressionVisitor { return error; } assert(_gotError == null); - // ignore: unnecessary_null_comparison - assert(types != null); List? positionalArguments = _evaluatePositionalArguments(init.arguments.positional); @@ -3474,8 +3411,6 @@ class ConstantEvaluator implements ExpressionVisitor { return error; } assert(_gotError == null); - // ignore: unnecessary_null_comparison - assert(positionalArguments != null); Map? namedArguments = _evaluateNamedArguments(init.arguments.named); if (namedArguments == null) { @@ -3484,8 +3419,6 @@ class ConstantEvaluator implements ExpressionVisitor { return error; } assert(_gotError == null); - // ignore: unnecessary_null_comparison - assert(namedArguments != null); error = handleConstructorInvocation( init.target, types, positionalArguments, namedArguments, caller); if (error != null) return error; @@ -3504,8 +3437,6 @@ class ConstantEvaluator implements ExpressionVisitor { return error; } assert(_gotError == null); - // ignore: unnecessary_null_comparison - assert(positionalArguments != null); Map? namedArguments = _evaluateNamedArguments(init.arguments.named); @@ -3515,8 +3446,6 @@ class ConstantEvaluator implements ExpressionVisitor { return error; } assert(_gotError == null); - // ignore: unnecessary_null_comparison - assert(namedArguments != null); error = handleConstructorInvocation(init.target, typeArguments, positionalArguments, namedArguments, caller); @@ -3544,8 +3473,7 @@ class ConstantEvaluator implements ExpressionVisitor { instanceBuilder!.unusedArguments.add(_wrap(constant)); } - // ignore: unnecessary_null_comparison - if (enableConstFunctions && constructor.function != null) { + if (enableConstFunctions) { AbortConstant? error = executeConstructorBody(constructor); if (error != null) return error; } @@ -3643,8 +3571,6 @@ class ConstantEvaluator implements ExpressionVisitor { return error; } assert(_gotError == null); - // ignore: unnecessary_null_comparison - assert(positionalArguments != null); if (shouldBeUnevaluated) { return unevaluated( @@ -3688,8 +3614,6 @@ class ConstantEvaluator implements ExpressionVisitor { return error; } assert(_gotError == null); - // ignore: unnecessary_null_comparison - assert(positionalArguments != null); if (shouldBeUnevaluated) { return unevaluated( @@ -3733,8 +3657,6 @@ class ConstantEvaluator implements ExpressionVisitor { } final Constant receiver = env.lookupVariable(node.variable)!; - // ignore: unnecessary_null_comparison - assert(receiver != null); if (receiver is AbortConstant) return receiver; return _evaluateFunctionInvocation(node, receiver, node.arguments); @@ -3751,8 +3673,6 @@ class ConstantEvaluator implements ExpressionVisitor { return error; } assert(_gotError == null); - // ignore: unnecessary_null_comparison - assert(positional != null); // Evaluate type arguments of the function invoked. List? types = _evaluateTypeArguments(node, arguments); @@ -3762,8 +3682,6 @@ class ConstantEvaluator implements ExpressionVisitor { return error; } assert(_gotError == null); - // ignore: unnecessary_null_comparison - assert(types != null); // Evaluate named arguments of the function invoked. final Map? named = @@ -3774,8 +3692,6 @@ class ConstantEvaluator implements ExpressionVisitor { return error; } assert(_gotError == null); - // ignore: unnecessary_null_comparison - assert(named != null); if (receiver is FunctionValue) { return _handleFunctionInvocation( @@ -4048,8 +3964,6 @@ class ConstantEvaluator implements ExpressionVisitor { return error; } assert(_gotError == null); - // ignore: unnecessary_null_comparison - assert(typeArguments != null); // Evaluate named arguments of the method invoked. final Map? namedArguments = @@ -4060,8 +3974,6 @@ class ConstantEvaluator implements ExpressionVisitor { return error; } assert(_gotError == null); - // ignore: unnecessary_null_comparison - assert(namedArguments != null); if (receiver is FunctionValue && name == Name.callName) { return _handleFunctionInvocation(receiver.function, typeArguments, @@ -4616,8 +4528,6 @@ class ConstantEvaluator implements ExpressionVisitor { return error; } assert(_gotError == null); - // ignore: unnecessary_null_comparison - assert(types != null); final List typeArguments = convertTypes(types); @@ -4629,8 +4539,6 @@ class ConstantEvaluator implements ExpressionVisitor { return error; } assert(_gotError == null); - // ignore: unnecessary_null_comparison - assert(positional != null); final Map? named = _evaluateNamedArguments(arguments.named); @@ -4640,8 +4548,6 @@ class ConstantEvaluator implements ExpressionVisitor { return error; } assert(_gotError == null); - // ignore: unnecessary_null_comparison - assert(named != null); if (shouldBeUnevaluated) { return unevaluated( @@ -4815,8 +4721,6 @@ class ConstantEvaluator implements ExpressionVisitor { return error; } assert(_gotError == null); - // ignore: unnecessary_null_comparison - assert(type != null); return ensureIsSubtype(constant, type, node); } @@ -4839,12 +4743,8 @@ class ConstantEvaluator implements ExpressionVisitor { return error; } assert(_gotError == null); - // ignore: unnecessary_null_comparison - assert(type != null); bool performIs(Constant constant, {required bool strongMode}) { - // ignore: unnecessary_null_comparison - assert(strongMode != null); if (strongMode) { return isSubtype(constant, type, SubtypeCheckMode.withNullabilities); } else { @@ -4970,8 +4870,6 @@ class ConstantEvaluator implements ExpressionVisitor { return error; } assert(_gotError == null); - // ignore: unnecessary_null_comparison - assert(types != null); return canonicalize( new InstantiationConstant(constant, convertTypes(types))); @@ -5248,8 +5146,6 @@ class ConstantEvaluator implements ExpressionVisitor { return null; } assert(_gotError == null); - // ignore: unnecessary_null_comparison - assert(type != null); result[i] = type; } return result; diff --git a/pkg/front_end/lib/src/fasta/kernel/expression_generator.dart b/pkg/front_end/lib/src/fasta/kernel/expression_generator.dart index 53fe605a182..88cdbd53efb 100644 --- a/pkg/front_end/lib/src/fasta/kernel/expression_generator.dart +++ b/pkg/front_end/lib/src/fasta/kernel/expression_generator.dart @@ -223,8 +223,6 @@ abstract class Generator { Expression_Generator buildEqualsOperation(Token token, Expression right, {required bool isNot}) { - // ignore: unnecessary_null_comparison - assert(isNot != null); return _forest.createEquals(offsetForToken(token), buildSimpleRead(), right, isNot: isNot); } @@ -401,8 +399,6 @@ class VariableUseGenerator extends Generator { @override Generator buildIndexedAccess(Expression index, Token token, {required bool isNullAware}) { - // ignore: unnecessary_null_comparison - assert(isNullAware != null); return new IndexedAccessGenerator(_helper, token, buildSimpleRead(), index, isNullAware: isNullAware); } @@ -525,8 +521,6 @@ class PropertyAccessGenerator extends Generator { @override Generator buildIndexedAccess(Expression index, Token token, {required bool isNullAware}) { - // ignore: unnecessary_null_comparison - assert(isNullAware != null); return new IndexedAccessGenerator(_helper, token, buildSimpleRead(), index, isNullAware: isNullAware); } @@ -687,8 +681,6 @@ class ThisPropertyAccessGenerator extends Generator { @override Generator buildIndexedAccess(Expression index, Token token, {required bool isNullAware}) { - // ignore: unnecessary_null_comparison - assert(isNullAware != null); return new IndexedAccessGenerator(_helper, token, buildSimpleRead(), index, isNullAware: isNullAware); } @@ -794,8 +786,6 @@ class NullAwarePropertyAccessGenerator extends Generator { @override Generator buildIndexedAccess(Expression index, Token token, {required bool isNullAware}) { - // ignore: unnecessary_null_comparison - assert(isNullAware != null); return new IndexedAccessGenerator(_helper, token, buildSimpleRead(), index, isNullAware: isNullAware); } @@ -919,8 +909,6 @@ class SuperPropertyAccessGenerator extends Generator { @override Generator buildIndexedAccess(Expression index, Token token, {required bool isNullAware}) { - // ignore: unnecessary_null_comparison - assert(isNullAware != null); return new IndexedAccessGenerator(_helper, token, buildSimpleRead(), index, isNullAware: isNullAware); } @@ -946,9 +934,7 @@ class IndexedAccessGenerator extends Generator { IndexedAccessGenerator( ExpressionGeneratorHelper helper, Token token, this.receiver, this.index, {required this.isNullAware}) - // ignore: unnecessary_null_comparison - : assert(isNullAware != null), - super(helper, token); + : super(helper, token); @override String get _plainNameForRead => "[]"; @@ -1072,8 +1058,6 @@ class IndexedAccessGenerator extends Generator { @override Generator buildIndexedAccess(Expression index, Token token, {required bool isNullAware}) { - // ignore: unnecessary_null_comparison - assert(isNullAware != null); return new IndexedAccessGenerator(_helper, token, buildSimpleRead(), index, isNullAware: isNullAware); } @@ -1091,8 +1075,6 @@ class IndexedAccessGenerator extends Generator { static Generator make(ExpressionGeneratorHelper helper, Token token, Expression receiver, Expression index, {required bool isNullAware}) { - // ignore: unnecessary_null_comparison - assert(isNullAware != null); if (helper.forest.isThisExpression(receiver)) { return new ThisIndexedAccessGenerator(helper, token, index, thisOffset: receiver.fileOffset, isNullAware: isNullAware); @@ -1195,8 +1177,6 @@ class ThisIndexedAccessGenerator extends Generator { @override Generator buildIndexedAccess(Expression index, Token token, {required bool isNullAware}) { - // ignore: unnecessary_null_comparison - assert(isNullAware != null); return new IndexedAccessGenerator(_helper, token, buildSimpleRead(), index, isNullAware: isNullAware); } @@ -1321,8 +1301,6 @@ class SuperIndexedAccessGenerator extends Generator { @override Generator buildIndexedAccess(Expression index, Token token, {required bool isNullAware}) { - // ignore: unnecessary_null_comparison - assert(isNullAware != null); return new IndexedAccessGenerator(_helper, token, buildSimpleRead(), index, isNullAware: isNullAware); } @@ -1401,9 +1379,7 @@ class StaticAccessGenerator extends Generator { StaticAccessGenerator(ExpressionGeneratorHelper helper, Token token, this.targetName, this.parentBuilder, this.readTarget, this.writeTarget, {this.typeOffset, this.isNullAware = false}) - // ignore: unnecessary_null_comparison - : assert(targetName != null), - assert(readTarget != null || writeTarget != null), + : assert(readTarget != null || writeTarget != null), assert(parentBuilder is DeclarationBuilder || parentBuilder is LibraryBuilder), super(helper, token); @@ -1563,8 +1539,6 @@ class StaticAccessGenerator extends Generator { @override Generator buildIndexedAccess(Expression index, Token token, {required bool isNullAware}) { - // ignore: unnecessary_null_comparison - assert(isNullAware != null); return new IndexedAccessGenerator(_helper, token, buildSimpleRead(), index, isNullAware: isNullAware); } @@ -1647,12 +1621,8 @@ class ExtensionInstanceAccessGenerator extends Generator { this.writeTarget, this.extensionThis, this.extensionTypeParameters) - // ignore: unnecessary_null_comparison - : assert(targetName != null), - assert( + : assert( readTarget != null || invokeTarget != null || writeTarget != null), - // ignore: unnecessary_null_comparison - assert(extensionThis != null), super(helper, token); factory ExtensionInstanceAccessGenerator.fromBuilder( @@ -1850,8 +1820,6 @@ class ExtensionInstanceAccessGenerator extends Generator { @override Generator buildIndexedAccess(Expression index, Token token, {required bool isNullAware}) { - // ignore: unnecessary_null_comparison - assert(isNullAware != null); return new IndexedAccessGenerator(_helper, token, buildSimpleRead(), index, isNullAware: isNullAware); } @@ -1948,14 +1916,8 @@ class ExplicitExtensionInstanceAccessGenerator extends Generator { this.explicitTypeArguments, this.extensionTypeParameterCount, {required this.isNullAware}) - // ignore: unnecessary_null_comparison - : assert(targetName != null), - assert( + : assert( readTarget != null || invokeTarget != null || writeTarget != null), - // ignore: unnecessary_null_comparison - assert(receiver != null), - // ignore: unnecessary_null_comparison - assert(isNullAware != null), super(helper, token); factory ExplicitExtensionInstanceAccessGenerator.fromBuilder( @@ -2276,8 +2238,6 @@ class ExplicitExtensionInstanceAccessGenerator extends Generator { @override Generator buildIndexedAccess(Expression index, Token token, {required bool isNullAware}) { - // ignore: unnecessary_null_comparison - assert(isNullAware != null); return new IndexedAccessGenerator(_helper, token, buildSimpleRead(), index, isNullAware: isNullAware); } @@ -2339,10 +2299,6 @@ class ExplicitExtensionIndexedAccessGenerator extends Generator { this.extensionTypeParameterCount, {required this.isNullAware}) : assert(readTarget != null || writeTarget != null), - // ignore: unnecessary_null_comparison - assert(receiver != null), - // ignore: unnecessary_null_comparison - assert(isNullAware != null), super(helper, token); factory ExplicitExtensionIndexedAccessGenerator.fromBuilder( @@ -2357,8 +2313,6 @@ class ExplicitExtensionIndexedAccessGenerator extends Generator { List? explicitTypeArguments, int extensionTypeParameterCount, {required bool isNullAware}) { - // ignore: unnecessary_null_comparison - assert(isNullAware != null); Procedure? readTarget; if (getterBuilder != null) { if (getterBuilder is AccessErrorBuilder) { @@ -2561,8 +2515,6 @@ class ExplicitExtensionIndexedAccessGenerator extends Generator { @override Generator buildIndexedAccess(Expression index, Token token, {required bool isNullAware}) { - // ignore: unnecessary_null_comparison - assert(isNullAware != null); return new IndexedAccessGenerator(_helper, token, buildSimpleRead(), index, isNullAware: isNullAware); } @@ -2747,8 +2699,6 @@ class ExplicitExtensionAccessGenerator extends Generator { @override Generator buildIndexedAccess(Expression index, Token token, {required bool isNullAware}) { - // ignore: unnecessary_null_comparison - assert(isNullAware != null); Builder? getter = extensionBuilder.lookupLocalMemberByName(indexGetName); Builder? setter = extensionBuilder.lookupLocalMemberByName(indexSetName); if (getter == null && setter == null) { @@ -2852,8 +2802,6 @@ class LoadLibraryGenerator extends Generator { @override Generator buildIndexedAccess(Expression index, Token token, {required bool isNullAware}) { - // ignore: unnecessary_null_comparison - assert(isNullAware != null); return new IndexedAccessGenerator(_helper, token, buildSimpleRead(), index, isNullAware: isNullAware); } @@ -3018,8 +2966,6 @@ class DeferredAccessGenerator extends Generator { @override Generator buildIndexedAccess(Expression index, Token token, {required bool isNullAware}) { - // ignore: unnecessary_null_comparison - assert(isNullAware != null); return new IndexedAccessGenerator(_helper, token, buildSimpleRead(), index, isNullAware: isNullAware); } @@ -3547,15 +3493,11 @@ abstract class AbstractReadOnlyAccessGenerator extends Generator { Expression _makeInvalidWrite(Expression value) { switch (kind) { case ReadOnlyAccessKind.ConstVariable: - // ignore: unnecessary_null_comparison - assert(targetName != null); return _helper.buildProblem( templateCannotAssignToConstVariable.withArguments(targetName), fileOffset, lengthForToken(token)); case ReadOnlyAccessKind.FinalVariable: - // ignore: unnecessary_null_comparison - assert(targetName != null); return _helper.buildProblem( templateCannotAssignToFinalVariable.withArguments(targetName), fileOffset, @@ -3622,8 +3564,6 @@ abstract class AbstractReadOnlyAccessGenerator extends Generator { @override Generator buildIndexedAccess(Expression index, Token token, {required bool isNullAware}) { - // ignore: unnecessary_null_comparison - assert(isNullAware != null); // TODO(johnniwinther): The read-only quality of the variable should be // passed on to the generator. return new IndexedAccessGenerator(_helper, token, _createRead(), index, @@ -3757,8 +3697,6 @@ abstract class ErroneousExpressionGenerator extends Generator { @override Generator buildIndexedAccess(Expression index, Token token, {required bool isNullAware}) { - // ignore: unnecessary_null_comparison - assert(isNullAware != null); return new IndexedAccessGenerator(_helper, token, buildSimpleRead(), index, isNullAware: isNullAware); } @@ -3846,8 +3784,6 @@ class UnresolvedNameGenerator extends ErroneousExpressionGenerator { @override Generator buildIndexedAccess(Expression index, Token token, {required bool isNullAware}) { - // ignore: unnecessary_null_comparison - assert(isNullAware != null); return new IndexedAccessGenerator(_helper, token, buildSimpleRead(), index, isNullAware: isNullAware); } @@ -3918,8 +3854,6 @@ abstract class ContextAwareGenerator extends Generator { @override Generator buildIndexedAccess(Expression index, Token token, {required bool isNullAware}) { - // ignore: unnecessary_null_comparison - assert(isNullAware != null); return new IndexedAccessGenerator(_helper, token, buildSimpleRead(), index, isNullAware: isNullAware); } @@ -4155,8 +4089,6 @@ class PrefixUseGenerator extends Generator { @override Generator buildIndexedAccess(Expression index, Token token, {required bool isNullAware}) { - // ignore: unnecessary_null_comparison - assert(isNullAware != null); return new IndexedAccessGenerator(_helper, token, buildSimpleRead(), index, isNullAware: isNullAware); } @@ -4249,8 +4181,6 @@ class UnexpectedQualifiedUseGenerator extends Generator { @override Generator buildIndexedAccess(Expression index, Token token, {required bool isNullAware}) { - // ignore: unnecessary_null_comparison - assert(isNullAware != null); return new IndexedAccessGenerator(_helper, token, buildSimpleRead(), index, isNullAware: isNullAware); } @@ -4379,8 +4309,6 @@ class ParserErrorGenerator extends Generator { @override Generator buildIndexedAccess(Expression index, Token token, {required bool isNullAware}) { - // ignore: unnecessary_null_comparison - assert(isNullAware != null); return new IndexedAccessGenerator(_helper, token, buildSimpleRead(), index, isNullAware: isNullAware); } @@ -4572,8 +4500,6 @@ class ThisAccessGenerator extends Generator { @override Expression_Generator buildEqualsOperation(Token token, Expression right, {required bool isNot}) { - // ignore: unnecessary_null_comparison - assert(isNot != null); if (isSuper) { int offset = offsetForToken(token); Expression result = _helper.buildSuperInvocation(equalsName, @@ -4669,8 +4595,6 @@ class ThisAccessGenerator extends Generator { @override Generator buildIndexedAccess(Expression index, Token token, {required bool isNullAware}) { - // ignore: unnecessary_null_comparison - assert(isNullAware != null); if (isSuper) { return new SuperIndexedAccessGenerator( _helper, @@ -4909,10 +4833,7 @@ class InvocationSelector extends Selector { InvocationSelector(ExpressionGeneratorHelper helper, Token token, this.name, this.typeArguments, this.arguments, {this.isPotentiallyConstant = false, this.isTypeArgumentsInForest = true}) - : super(helper, token) { - // ignore: unnecessary_null_comparison - assert(arguments != null); - } + : super(helper, token); @override String get _debugName => 'InvocationSelector'; diff --git a/pkg/front_end/lib/src/fasta/kernel/forest.dart b/pkg/front_end/lib/src/fasta/kernel/forest.dart index 8f2b4d2dcae..afaccf75c1d 100644 --- a/pkg/front_end/lib/src/fasta/kernel/forest.dart +++ b/pkg/front_end/lib/src/fasta/kernel/forest.dart @@ -32,8 +32,6 @@ class Forest { List? named, bool hasExplicitTypeArguments = true, List? argumentsOriginalOrder}) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); if (!hasExplicitTypeArguments) { ArgumentsImpl arguments = new ArgumentsImpl(positional, types: [], @@ -61,8 +59,6 @@ class Forest { List positionalArguments = const [], List namedArguments = const [], List? argumentsOriginalOrder}) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new ArgumentsImpl.forExtensionMethod( extensionTypeParameterCount, typeParameterCount, receiver, extensionTypeArguments: extensionTypeArguments, @@ -75,8 +71,6 @@ class Forest { } ArgumentsImpl createArgumentsEmpty(int fileOffset) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return createArguments(fileOffset, []); } @@ -100,30 +94,22 @@ class Forest { /// Return a representation of a boolean literal at the given [fileOffset]. /// The literal has the given [value]. BoolLiteral createBoolLiteral(int fileOffset, bool value) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new BoolLiteral(value)..fileOffset = fileOffset; } /// Return a representation of a double literal at the given [fileOffset]. The /// literal has the given [value]. DoubleLiteral createDoubleLiteral(int fileOffset, double value) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new DoubleLiteral(value)..fileOffset = fileOffset; } /// Return a representation of an integer literal at the given [fileOffset]. /// The literal has the given [value]. IntLiteral createIntLiteral(int fileOffset, int value, [String? literal]) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new IntJudgment(value, literal)..fileOffset = fileOffset; } IntLiteral createIntLiteralLarge(int fileOffset, String literal) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new ShadowLargeIntLiteral(literal, fileOffset); } @@ -137,10 +123,6 @@ class Forest { ListLiteral createListLiteral( int fileOffset, DartType typeArgument, List expressions, {required bool isConst}) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); - // ignore: unnecessary_null_comparison - assert(isConst != null); return new ListLiteral(expressions, typeArgument: typeArgument, isConst: isConst) ..fileOffset = fileOffset; @@ -156,10 +138,6 @@ class Forest { SetLiteral createSetLiteral( int fileOffset, DartType typeArgument, List expressions, {required bool isConst}) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); - // ignore: unnecessary_null_comparison - assert(isConst != null); return new SetLiteral(expressions, typeArgument: typeArgument, isConst: isConst) ..fileOffset = fileOffset; @@ -177,10 +155,6 @@ class Forest { MapLiteral createMapLiteral(int fileOffset, DartType keyType, DartType valueType, List entries, {required bool isConst}) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); - // ignore: unnecessary_null_comparison - assert(isConst != null); return new MapLiteral(entries, keyType: keyType, valueType: valueType, isConst: isConst) ..fileOffset = fileOffset; @@ -188,8 +162,6 @@ class Forest { /// Return a representation of a null literal at the given [fileOffset]. NullLiteral createNullLiteral(int fileOffset) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new NullLiteral()..fileOffset = fileOffset; } @@ -197,22 +169,16 @@ class Forest { /// [fileOffset]. The literal has the given [value]. This does not include /// either adjacent strings or interpolated strings. StringLiteral createStringLiteral(int fileOffset, String value) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new StringLiteral(value)..fileOffset = fileOffset; } /// Return a representation of a symbol literal defined by [value] at the /// given [fileOffset]. SymbolLiteral createSymbolLiteral(int fileOffset, String value) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new SymbolLiteral(value)..fileOffset = fileOffset; } TypeLiteral createTypeLiteral(int fileOffset, DartType type) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new TypeLiteral(type)..fileOffset = fileOffset; } @@ -222,32 +188,22 @@ class Forest { /// to compute the value. MapLiteralEntry createMapEntry( int fileOffset, Expression key, Expression value) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new MapLiteralEntry(key, value)..fileOffset = fileOffset; } LoadLibrary createLoadLibrary( int fileOffset, LibraryDependency dependency, Arguments? arguments) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new LoadLibraryImpl(dependency, arguments)..fileOffset = fileOffset; } Expression checkLibraryIsLoaded( int fileOffset, LibraryDependency dependency) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new CheckLibraryIsLoaded(dependency)..fileOffset = fileOffset; } Expression createAsExpression( int fileOffset, Expression expression, DartType type, {required bool forNonNullableByDefault, bool forDynamic = false}) { - // ignore: unnecessary_null_comparison - assert(forNonNullableByDefault != null); - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new AsExpression(expression, type) ..fileOffset = fileOffset ..isForNonNullableByDefault = forNonNullableByDefault @@ -256,10 +212,6 @@ class Forest { Expression createSpreadElement(int fileOffset, Expression expression, {required bool isNullAware}) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); - // ignore: unnecessary_null_comparison - assert(isNullAware != null); return new SpreadElement(expression, isNullAware: isNullAware) ..fileOffset = fileOffset; } @@ -267,8 +219,6 @@ class Forest { Expression createIfElement( int fileOffset, Expression condition, Expression then, [Expression? otherwise]) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new IfElement(condition, then, otherwise)..fileOffset = fileOffset; } @@ -278,8 +228,6 @@ class Forest { required PatternGuard patternGuard, required Expression then, Expression? otherwise}) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new IfCaseElement( prelude: prelude, expression: expression, @@ -292,8 +240,6 @@ class Forest { MapLiteralEntry createIfMapEntry( int fileOffset, Expression condition, MapLiteralEntry then, [MapLiteralEntry? otherwise]) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new IfMapEntry(condition, then, otherwise)..fileOffset = fileOffset; } @@ -303,8 +249,6 @@ class Forest { required PatternGuard patternGuard, required MapLiteralEntry then, MapLiteralEntry? otherwise}) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new IfCaseMapEntry( prelude: prelude, expression: expression, @@ -320,8 +264,6 @@ class Forest { Expression? condition, List updates, Expression body) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new ForElement(variables, condition, updates, body) ..fileOffset = fileOffset; } @@ -333,8 +275,6 @@ class Forest { required Expression? condition, required List updates, required Expression body}) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new PatternForElement( patternVariableDeclaration: patternVariableDeclaration, intermediateVariables: intermediateVariables, @@ -351,8 +291,6 @@ class Forest { Expression? condition, List updates, MapLiteralEntry body) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new ForMapEntry(variables, condition, updates, body) ..fileOffset = fileOffset; } @@ -364,8 +302,6 @@ class Forest { required Expression? condition, required List updates, required MapLiteralEntry body}) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new PatternForMapEntry( patternVariableDeclaration: patternVariableDeclaration, intermediateVariables: intermediateVariables, @@ -385,8 +321,6 @@ class Forest { Expression body, Expression? problem, {bool isAsync = false}) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new ForInElement(variable, iterable, synthesizedAssignment, expressionEffects, body, problem, isAsync: isAsync) @@ -402,8 +336,6 @@ class Forest { MapLiteralEntry body, Expression? problem, {bool isAsync = false}) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new ForInMapEntry(variable, iterable, synthesizedAssignment, expressionEffects, body, problem, isAsync: isAsync) @@ -414,16 +346,12 @@ class Forest { /// initializer list. AssertInitializer createAssertInitializer( int fileOffset, AssertStatement assertStatement) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new AssertInitializer(assertStatement)..fileOffset = fileOffset; } /// Return a representation of an assert that appears as a statement. AssertStatement createAssertStatement(int fileOffset, Expression condition, Expression? message, int conditionStartOffset, int conditionEndOffset) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new AssertStatement(condition, conditionStartOffset: conditionStartOffset, conditionEndOffset: conditionEndOffset, @@ -432,8 +360,6 @@ class Forest { } Expression createAwaitExpression(int fileOffset, Expression operand) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new AwaitExpression(operand)..fileOffset = fileOffset; } @@ -441,8 +367,6 @@ class Forest { /// [fileOffset]. Block createBlock( int fileOffset, int fileEndOffset, List statements) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); List? copy; for (int i = 0; i < statements.length; i++) { Statement statement = statements[i]; @@ -460,8 +384,6 @@ class Forest { /// Return a representation of a break statement. Statement createBreakStatement(int fileOffset, Object? label) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); // TODO(johnniwinther): Use [label]? return new BreakStatementImpl(isContinue: false) ..fileOffset = fileOffset @@ -476,8 +398,6 @@ class Forest { VariableDeclaration? stackTraceParameter, DartType stackTraceType, Statement body) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new Catch(exceptionParameter, body, guard: exceptionType, stackTrace: stackTraceParameter) ..fileOffset = fileOffset; @@ -499,8 +419,6 @@ class Forest { /// Return a representation of a continue statement. Statement createContinueStatement(int fileOffset, Object? label) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); // TODO(johnniwinther): Use [label]? return new BreakStatementImpl(isContinue: true)..fileOffset = fileOffset; } @@ -508,23 +426,17 @@ class Forest { /// Return a representation of a do statement. Statement createDoStatement( int fileOffset, Statement body, Expression condition) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new DoStatement(body, condition)..fileOffset = fileOffset; } /// Return a representation of an expression statement at the given /// [fileOffset] containing the [expression]. Statement createExpressionStatement(int fileOffset, Expression expression) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new ExpressionStatement(expression)..fileOffset = fileOffset; } /// Return a representation of an empty statement at the given [fileOffset]. Statement createEmptyStatement(int fileOffset) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new EmptyStatement()..fileOffset = fileOffset; } @@ -535,8 +447,6 @@ class Forest { Expression? condition, List updaters, Statement body) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new ForStatement(variables ?? [], condition, updaters, body) ..fileOffset = fileOffset; } @@ -544,8 +454,6 @@ class Forest { /// Return a representation of an `if` statement. Statement createIfStatement(int fileOffset, Expression condition, Statement thenStatement, Statement? elseStatement) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new IfStatement(condition, thenStatement, elseStatement) ..fileOffset = fileOffset; } @@ -553,8 +461,6 @@ class Forest { /// Return a representation of a `switch` statement. Statement createSwitchStatement( int fileOffset, Expression expression, List cases) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new SwitchStatement(expression, cases)..fileOffset = fileOffset; } @@ -565,10 +471,6 @@ class Forest { Expression createIsExpression( int fileOffset, Expression operand, DartType type, {required bool forNonNullableByDefault, int? notFileOffset}) { - // ignore: unnecessary_null_comparison - assert(forNonNullableByDefault != null); - // ignore: unnecessary_null_comparison - assert(fileOffset != null); Expression result = new IsExpression(operand, type) ..fileOffset = fileOffset ..isForNonNullableByDefault = forNonNullableByDefault; @@ -583,8 +485,6 @@ class Forest { /// (either `&&` or `||`). Expression createLogicalExpression(int fileOffset, Expression leftOperand, String operatorString, Expression rightOperand) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); LogicalExpressionOperator operator; if (operatorString == '&&') { operator = LogicalExpressionOperator.AND; @@ -600,8 +500,6 @@ class Forest { } Expression createNot(int fileOffset, Expression operand) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new Not(operand)..fileOffset = fileOffset; } @@ -609,10 +507,6 @@ class Forest { /// rethrow at [rethrowFileOffset] and the statement at [statementFileOffset]. Statement createRethrowStatement( int rethrowFileOffset, int statementFileOffset) { - // ignore: unnecessary_null_comparison - assert(rethrowFileOffset != null); - // ignore: unnecessary_null_comparison - assert(statementFileOffset != null); return new ExpressionStatement( new Rethrow()..fileOffset = rethrowFileOffset) ..fileOffset = statementFileOffset; @@ -621,16 +515,12 @@ class Forest { /// Return a representation of a return statement. Statement createReturnStatement(int fileOffset, Expression? expression, {bool isArrow = true}) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new ReturnStatementImpl(isArrow, expression) ..fileOffset = fileOffset; } Expression createStringConcatenation( int fileOffset, List expressions) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); assert(fileOffset != TreeNode.noOffset); return new StringConcatenation(expressions)..fileOffset = fileOffset; } @@ -643,15 +533,11 @@ class Forest { } Expression createThisExpression(int fileOffset) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new ThisExpression()..fileOffset = fileOffset; } /// Return a representation of a throw expression at the given [fileOffset]. Expression createThrow(int fileOffset, Expression expression) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new Throw(expression)..fileOffset = fileOffset; } @@ -659,8 +545,6 @@ class Forest { Statement createTryStatement(int fileOffset, Statement tryBlock, List? catchBlocks, Statement? finallyBlock) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new TryStatement(tryBlock, catchBlocks ?? [], finallyBlock) ..fileOffset = fileOffset; } @@ -692,8 +576,6 @@ class Forest { /// consisting of the given [condition] and [body]. Statement createWhileStatement( int fileOffset, Expression condition, Statement body) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new WhileStatement(condition, body)..fileOffset = fileOffset; } @@ -702,10 +584,6 @@ class Forest { /// statement is a yield* statement. Statement createYieldStatement(int fileOffset, Expression expression, {required bool isYieldStar}) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); - // ignore: unnecessary_null_comparison - assert(isYieldStar != null); return new YieldStatement(expression, isYieldStar: isYieldStar) ..fileOffset = fileOffset; } @@ -741,8 +619,6 @@ class Forest { bool isCovariantByDeclaration = false, bool isLocalFunction = false, bool isSynthesized = false}) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new VariableDeclarationImpl(name, type: type, initializer: initializer, @@ -778,8 +654,6 @@ class Forest { DartType returnType = const DynamicType(), AsyncMarker asyncMarker = AsyncMarker.Sync, AsyncMarker? dartAsyncMarker}) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new FunctionNode(body, typeParameters: typeParameters, positionalParameters: positionalParameters, @@ -807,66 +681,48 @@ class Forest { FunctionExpression createFunctionExpression( int fileOffset, FunctionNode function) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new FunctionExpression(function)..fileOffset = fileOffset; } Expression createExpressionInvocation( int fileOffset, Expression expression, Arguments arguments) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new ExpressionInvocation(expression, arguments) ..fileOffset = fileOffset; } Expression createMethodInvocation( int fileOffset, Expression expression, Name name, Arguments arguments) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new MethodInvocation(expression, name, arguments) ..fileOffset = fileOffset; } NamedExpression createNamedExpression( int fileOffset, String name, Expression expression) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new NamedExpression(name, expression)..fileOffset = fileOffset; } StaticInvocation createStaticInvocation( int fileOffset, Procedure procedure, Arguments arguments) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new StaticInvocation(procedure, arguments)..fileOffset = fileOffset; } SuperMethodInvocation createSuperMethodInvocation( int fileOffset, Name name, Procedure procedure, Arguments arguments) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new SuperMethodInvocation(name, arguments, procedure) ..fileOffset = fileOffset; } NullCheck createNullCheck(int fileOffset, Expression expression) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new NullCheck(expression)..fileOffset = fileOffset; } Expression createPropertyGet(int fileOffset, Expression receiver, Name name) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new PropertyGet(receiver, name)..fileOffset = fileOffset; } Expression createPropertySet( int fileOffset, Expression receiver, Name name, Expression value, {required bool forEffect, bool readOnlyReceiver = false}) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new PropertySet(receiver, name, value, forEffect: forEffect, readOnlyReceiver: readOnlyReceiver) ..fileOffset = fileOffset; @@ -874,25 +730,17 @@ class Forest { IndexGet createIndexGet( int fileOffset, Expression receiver, Expression index) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new IndexGet(receiver, index)..fileOffset = fileOffset; } IndexSet createIndexSet( int fileOffset, Expression receiver, Expression index, Expression value, {required bool forEffect}) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); - // ignore: unnecessary_null_comparison - assert(forEffect != null); return new IndexSet(receiver, index, value, forEffect: forEffect) ..fileOffset = fileOffset; } VariableGet createVariableGet(int fileOffset, VariableDeclaration variable) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new VariableGetImpl(variable, forNullGuardedAccess: false) ..fileOffset = fileOffset; } @@ -900,47 +748,33 @@ class Forest { EqualsExpression createEquals( int fileOffset, Expression left, Expression right, {required bool isNot}) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); - // ignore: unnecessary_null_comparison - assert(isNot != null); return new EqualsExpression(left, right, isNot: isNot) ..fileOffset = fileOffset; } BinaryExpression createBinary( int fileOffset, Expression left, Name binaryName, Expression right) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new BinaryExpression(left, binaryName, right) ..fileOffset = fileOffset; } UnaryExpression createUnary( int fileOffset, Name unaryName, Expression expression) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new UnaryExpression(unaryName, expression)..fileOffset = fileOffset; } ParenthesizedExpression createParenthesized( int fileOffset, Expression expression) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new ParenthesizedExpression(expression)..fileOffset = fileOffset; } ConstructorTearOff createConstructorTearOff(int fileOffset, Member target) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); assert(target is Constructor || (target is Procedure && target.isFactory), "Unexpected constructor tear off target: $target"); return new ConstructorTearOff(target)..fileOffset = fileOffset; } StaticTearOff createStaticTearOff(int fileOffset, Procedure procedure) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); assert(procedure.kind == ProcedureKind.Method, "Unexpected static tear off target: $procedure"); assert(!procedure.isRedirectingFactory, @@ -949,24 +783,18 @@ class Forest { } StaticGet createStaticGet(int fileOffset, Member target) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); assert(target is Field || (target is Procedure && target.isGetter)); return new StaticGet(target)..fileOffset = fileOffset; } RedirectingFactoryTearOff createRedirectingFactoryTearOff( int fileOffset, Procedure procedure) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); assert(procedure.isRedirectingFactory); return new RedirectingFactoryTearOff(procedure)..fileOffset = fileOffset; } Instantiation createInstantiation( int fileOffset, Expression expression, List typeArguments) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new Instantiation(expression, typeArguments) ..fileOffset = fileOffset; } @@ -976,8 +804,6 @@ class Forest { List typeParameters, Expression expression, List typeArguments) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); return new TypedefTearOff(typeParameters, expression, typeArguments) ..fileOffset = fileOffset; } diff --git a/pkg/front_end/lib/src/fasta/kernel/forwarding_node.dart b/pkg/front_end/lib/src/fasta/kernel/forwarding_node.dart index 3f032bc60b0..7df14777f4f 100644 --- a/pkg/front_end/lib/src/fasta/kernel/forwarding_node.dart +++ b/pkg/front_end/lib/src/fasta/kernel/forwarding_node.dart @@ -244,8 +244,6 @@ class ForwardingNode { void _createForwardingImplIfNeeded(FunctionNode function, Name name, Class enclosingClass, Member? superTarget, {required bool isForwardingStub}) { - // ignore: unnecessary_null_comparison - assert(isForwardingStub != null); if (function.body != null) { // There is already an implementation; nothing further needs to be done. return; @@ -268,9 +266,6 @@ class ForwardingNode { bool isForwardingSemiStub = isForwardingStub && !procedure.isSynthetic; bool needsSignatureType = false; Expression superCall; - // ignore: unnecessary_null_comparison - assert(superTarget != null, - "No super target found for '${name}' in ${enclosingClass}."); assert( !superTarget.isAbstract, "Abstract super target $superTarget found for '${name}' in " diff --git a/pkg/front_end/lib/src/fasta/kernel/hierarchy/class_member.dart b/pkg/front_end/lib/src/fasta/kernel/hierarchy/class_member.dart index f4fb62073cf..8c55f436de0 100644 --- a/pkg/front_end/lib/src/fasta/kernel/hierarchy/class_member.dart +++ b/pkg/front_end/lib/src/fasta/kernel/hierarchy/class_member.dart @@ -152,11 +152,7 @@ abstract class SynthesizedMember extends ClassMember { final bool isProperty; SynthesizedMember(this.classBuilder, this.name, - {required this.forSetter, required this.isProperty}) - // ignore: unnecessary_null_comparison - : assert(forSetter != null), - // ignore: unnecessary_null_comparison - assert(isProperty != null); + {required this.forSetter, required this.isProperty}); @override List get declarations => throw new UnimplementedError(); @@ -508,11 +504,7 @@ class InheritedClassMemberImplementsInterface extends SynthesizedMember { required this.implementedInterfaceMember, required bool isProperty, required bool forSetter}) - // ignore: unnecessary_null_comparison - : assert(inheritedClassMember != null), - // ignore: unnecessary_null_comparison - assert(implementedInterfaceMember != null), - super(classBuilder, name, isProperty: isProperty, forSetter: forSetter); + : super(classBuilder, name, isProperty: isProperty, forSetter: forSetter); void _ensureMemberAndCovariance(ClassMembersBuilder membersBuilder) { if (_member == null) { diff --git a/pkg/front_end/lib/src/fasta/kernel/hierarchy/hierarchy_builder.dart b/pkg/front_end/lib/src/fasta/kernel/hierarchy/hierarchy_builder.dart index 0ada782ae7b..2b918b4546e 100644 --- a/pkg/front_end/lib/src/fasta/kernel/hierarchy/hierarchy_builder.dart +++ b/pkg/front_end/lib/src/fasta/kernel/hierarchy/hierarchy_builder.dart @@ -150,8 +150,6 @@ class ClassHierarchyBuilder for (int i = 0; i < nodes2.length; i++) { ClassHierarchyNode node = nodes2[i]; - // ignore: unnecessary_null_comparison - if (node == null) continue; if (node.classBuilder.cls.isAnonymousMixin) { // Never find unnamed mixin application in least upper bound. continue; diff --git a/pkg/front_end/lib/src/fasta/kernel/hierarchy/hierarchy_node.dart b/pkg/front_end/lib/src/fasta/kernel/hierarchy/hierarchy_node.dart index 5d3408dea8a..9c153f0d4c3 100644 --- a/pkg/front_end/lib/src/fasta/kernel/hierarchy/hierarchy_node.dart +++ b/pkg/front_end/lib/src/fasta/kernel/hierarchy/hierarchy_node.dart @@ -43,8 +43,6 @@ class ClassHierarchyNodeBuilder { if (supernode == null) { supernode = hierarchy.getNodeFromClassBuilder(objectClass); } - // ignore: unnecessary_null_comparison - assert(supernode != null); } List superclasses; @@ -157,11 +155,8 @@ class ClassHierarchyNodeBuilder { for (Supertype superclass in superclasses) { recordSupertype(superclass); } - // ignore: unnecessary_null_comparison - if (interfacesList != null) { - for (Supertype superinterface in interfacesList) { - recordSupertype(superinterface); - } + for (Supertype superinterface in interfacesList) { + recordSupertype(superinterface); } return new ClassHierarchyNode(classBuilder, supernode, mixedInNode, @@ -224,14 +219,10 @@ class ClassHierarchyNodeBuilder { void addInterface(Map interfaces, List superclasses, Supertype type) { - // ignore: unnecessary_null_comparison - if (type == null) return null; if (!classBuilder.libraryBuilder.isNonNullableByDefault) { type = legacyErasureSupertype(type); } ClassHierarchyNode node = hierarchy.getNodeFromClass(type.classNode); - // ignore: unnecessary_null_comparison - if (node == null) return null; int depth = node.depth; int myDepth = superclasses.length; Supertype? superclass = depth < myDepth ? superclasses[depth] : null; diff --git a/pkg/front_end/lib/src/fasta/kernel/hierarchy/members_node.dart b/pkg/front_end/lib/src/fasta/kernel/hierarchy/members_node.dart index eec08e4f451..540058c878d 100644 --- a/pkg/front_end/lib/src/fasta/kernel/hierarchy/members_node.dart +++ b/pkg/front_end/lib/src/fasta/kernel/hierarchy/members_node.dart @@ -252,8 +252,6 @@ class ClassMembersNodeBuilder { } void inferFrom(List members, {required bool forSetter}) { - // ignore: unnecessary_null_comparison - assert(forSetter != null); CombinedClassMemberSignature combinedMemberSignature = new CombinedClassMemberSignature( membersBuilder, classBuilder, members, @@ -317,8 +315,6 @@ class ClassMembersNodeBuilder { } void inferFrom(List members, {required bool forSetter}) { - // ignore: unnecessary_null_comparison - assert(forSetter != null); CombinedClassMemberSignature combinedMemberSignature = new CombinedClassMemberSignature( membersBuilder, classBuilder, members, @@ -418,8 +414,6 @@ class ClassMembersNodeBuilder { DartType? inferFrom(List members, {required bool forSetter}) { - // ignore: unnecessary_null_comparison - assert(forSetter != null); CombinedClassMemberSignature combinedMemberSignature = new CombinedClassMemberSignature( membersBuilder, classBuilder, members, @@ -917,8 +911,7 @@ class ClassMembersNodeBuilder { "Only inherited members can implement by inheritance: " "${inheritedMember}"); inheritedImplementsMap[inheritedMember] = overrides; - // ignore: unnecessary_null_comparison - if (dataForTesting != null && aliasForTesting != null) { + if (dataForTesting != null) { dataForTesting.aliasMap[aliasForTesting] = inheritedMember; } } diff --git a/pkg/front_end/lib/src/fasta/kernel/internal_ast.dart b/pkg/front_end/lib/src/fasta/kernel/internal_ast.dart index 393bc2ed1a3..6e8f107de6b 100644 --- a/pkg/front_end/lib/src/fasta/kernel/internal_ast.dart +++ b/pkg/front_end/lib/src/fasta/kernel/internal_ast.dart @@ -253,11 +253,7 @@ class ForInStatementWithSynthesizedVariable extends InternalStatement { ForInStatementWithSynthesizedVariable(this.variable, this.iterable, this.syntheticAssignment, this.expressionEffects, this.body, - {required this.isAsync, required this.hasProblem}) - // ignore: unnecessary_null_comparison - : assert(isAsync != null), - // ignore: unnecessary_null_comparison - assert(hasProblem != null) { + {required this.isAsync, required this.hasProblem}) { variable?.parent = this; iterable.parent = this; syntheticAssignment?.parent = this; @@ -286,11 +282,7 @@ class TryStatement extends InternalStatement { List catchBlocks; Statement? finallyBlock; - TryStatement(this.tryBlock, this.catchBlocks, this.finallyBlock) - // ignore: unnecessary_null_comparison - : assert(tryBlock != null), - // ignore: unnecessary_null_comparison - assert(catchBlocks != null) { + TryStatement(this.tryBlock, this.catchBlocks, this.finallyBlock) { tryBlock.parent = this; setParents(catchBlocks, this); finallyBlock?.parent = this; @@ -328,9 +320,7 @@ class SwitchCaseImpl extends SwitchCase { SwitchCaseImpl(this.caseOffsets, List expressions, List expressionOffsets, Statement body, {bool isDefault = false, required this.hasLabel}) - // ignore: unnecessary_null_comparison - : assert(hasLabel != null), - super(expressions, expressionOffsets, body, isDefault: isDefault); + : super(expressions, expressionOffsets, body, isDefault: isDefault); @override String toString() { @@ -342,10 +332,7 @@ class BreakStatementImpl extends BreakStatement { Statement? targetStatement; final bool isContinue; - BreakStatementImpl({required this.isContinue}) - // ignore: unnecessary_null_comparison - : assert(isContinue != null), - super(dummyLabeledStatement); + BreakStatementImpl({required this.isContinue}) : super(dummyLabeledStatement); @override String toString() { @@ -599,11 +586,7 @@ class Cascade extends InternalExpression { /// variable. Caller is responsible for ensuring that [variable]'s /// initializer is the expression preceding the first `..` of the cascade /// expression. - Cascade(this.variable, {required this.isNullAware}) - // ignore: unnecessary_null_comparison - : assert(variable != null), - // ignore: unnecessary_null_comparison - assert(isNullAware != null) { + Cascade(this.variable, {required this.isNullAware}) { variable.parent = this; } @@ -651,11 +634,7 @@ class DeferredCheck extends InternalExpression { VariableDeclaration variable; Expression expression; - DeferredCheck(this.variable, this.expression) - // ignore: unnecessary_null_comparison - : assert(variable != null), - // ignore: unnecessary_null_comparison - assert(expression != null) { + DeferredCheck(this.variable, this.expression) { variable.parent = this; expression.parent = this; } @@ -856,11 +835,7 @@ class IfNullExpression extends InternalExpression { Expression left; Expression right; - IfNullExpression(this.left, this.right) - // ignore: unnecessary_null_comparison - : assert(left != null), - // ignore: unnecessary_null_comparison - assert(right != null) { + IfNullExpression(this.left, this.right) { left.parent = this; right.parent = this; } @@ -995,9 +970,7 @@ class ShadowInvalidFieldInitializer extends LocalInitializer ShadowInvalidFieldInitializer( this.field, this.value, VariableDeclaration variable) - // ignore: unnecessary_null_comparison - : assert(value != null), - super(variable) { + : super(variable) { value.parent = this; } @@ -1016,11 +989,7 @@ class ExpressionInvocation extends InternalExpression { Expression expression; Arguments arguments; - ExpressionInvocation(this.expression, this.arguments) - // ignore: unnecessary_null_comparison - : assert(expression != null), - // ignore: unnecessary_null_comparison - assert(arguments != null) { + ExpressionInvocation(this.expression, this.arguments) { expression.parent = this; arguments.parent = this; } @@ -1056,11 +1025,7 @@ class NullAwareMethodInvocation extends InternalExpression { /// The expression that invokes the method on [variable]. Expression invocation; - NullAwareMethodInvocation(this.variable, this.invocation) - // ignore: unnecessary_null_comparison - : assert(variable != null), - // ignore: unnecessary_null_comparison - assert(invocation != null) { + NullAwareMethodInvocation(this.variable, this.invocation) { variable.parent = this; invocation.parent = this; } @@ -1121,11 +1086,7 @@ class NullAwarePropertyGet extends InternalExpression { /// The expression that reads the property from [variable]. Expression read; - NullAwarePropertyGet(this.variable, this.read) - // ignore: unnecessary_null_comparison - : assert(variable != null), - // ignore: unnecessary_null_comparison - assert(read != null) { + NullAwarePropertyGet(this.variable, this.read) { variable.parent = this; read.parent = this; } @@ -1174,11 +1135,7 @@ class NullAwarePropertySet extends InternalExpression { /// The expression that writes the value to the property in [variable]. Expression write; - NullAwarePropertySet(this.variable, this.write) - // ignore: unnecessary_null_comparison - : assert(variable != null), - // ignore: unnecessary_null_comparison - assert(write != null) { + NullAwarePropertySet(this.variable, this.write) { variable.parent = this; write.parent = this; } @@ -1390,9 +1347,7 @@ class VariableGetImpl extends VariableGet { VariableGetImpl(VariableDeclaration variable, {required this.forNullGuardedAccess}) - // ignore: unnecessary_null_comparison - : assert(forNullGuardedAccess != null), - super(variable); + : super(variable); @override String toString() { @@ -1481,17 +1436,7 @@ class IfNullPropertySet extends InternalExpression { IfNullPropertySet(this.receiver, this.propertyName, this.rhs, {required this.forEffect, required this.readOffset, - required this.writeOffset}) - // ignore: unnecessary_null_comparison - : assert(receiver != null), - // ignore: unnecessary_null_comparison - assert(rhs != null), - // ignore: unnecessary_null_comparison - assert(forEffect != null), - // ignore: unnecessary_null_comparison - assert(readOffset != null), - // ignore: unnecessary_null_comparison - assert(writeOffset != null) { + required this.writeOffset}) { receiver.parent = this; rhs.parent = this; } @@ -1538,13 +1483,7 @@ class IfNullSet extends InternalExpression { /// If `true`, the expression is only need for effect and not for its value. final bool forEffect; - IfNullSet(this.read, this.write, {required this.forEffect}) - // ignore: unnecessary_null_comparison - : assert(read != null), - // ignore: unnecessary_null_comparison - assert(write != null), - // ignore: unnecessary_null_comparison - assert(forEffect != null) { + IfNullSet(this.read, this.write, {required this.forEffect}) { read.parent = this; write.parent = this; } @@ -1641,19 +1580,7 @@ class CompoundExtensionSet extends InternalExpression { {required this.forEffect, required this.readOffset, required this.binaryOffset, - required this.writeOffset}) - // ignore: unnecessary_null_comparison - : assert(receiver != null), - // ignore: unnecessary_null_comparison - assert(rhs != null), - // ignore: unnecessary_null_comparison - assert(forEffect != null), - // ignore: unnecessary_null_comparison - assert(readOffset != null), - // ignore: unnecessary_null_comparison - assert(binaryOffset != null), - // ignore: unnecessary_null_comparison - assert(writeOffset != null) { + required this.writeOffset}) { receiver.parent = this; rhs.parent = this; } @@ -1711,19 +1638,7 @@ class CompoundPropertySet extends InternalExpression { {required this.forEffect, required this.readOffset, required this.binaryOffset, - required this.writeOffset}) - // ignore: unnecessary_null_comparison - : assert(receiver != null), - // ignore: unnecessary_null_comparison - assert(rhs != null), - // ignore: unnecessary_null_comparison - assert(forEffect != null), - // ignore: unnecessary_null_comparison - assert(readOffset != null), - // ignore: unnecessary_null_comparison - assert(binaryOffset != null), - // ignore: unnecessary_null_comparison - assert(writeOffset != null) { + required this.writeOffset}) { receiver.parent = this; rhs.parent = this; } @@ -1772,11 +1687,7 @@ class PropertyPostIncDec extends InternalExpression { /// property on [variable]. VariableDeclarationImpl write; - PropertyPostIncDec(this.variable, this.read, this.write) - // ignore: unnecessary_null_comparison - : assert(read != null), - // ignore: unnecessary_null_comparison - assert(write != null) { + PropertyPostIncDec(this.variable, this.read, this.write) { variable?.parent = this; read.parent = this; write.parent = this; @@ -1813,11 +1724,7 @@ class LocalPostIncDec extends InternalExpression { /// local variable. VariableDeclarationImpl write; - LocalPostIncDec(this.read, this.write) - // ignore: unnecessary_null_comparison - : assert(read != null), - // ignore: unnecessary_null_comparison - assert(write != null) { + LocalPostIncDec(this.read, this.write) { read.parent = this; write.parent = this; } @@ -1849,11 +1756,7 @@ class StaticPostIncDec extends InternalExpression { /// static member. VariableDeclarationImpl write; - StaticPostIncDec(this.read, this.write) - // ignore: unnecessary_null_comparison - : assert(read != null), - // ignore: unnecessary_null_comparison - assert(write != null) { + StaticPostIncDec(this.read, this.write) { read.parent = this; write.parent = this; } @@ -1885,11 +1788,7 @@ class SuperPostIncDec extends InternalExpression { /// static member. VariableDeclarationImpl write; - SuperPostIncDec(this.read, this.write) - // ignore: unnecessary_null_comparison - : assert(read != null), - // ignore: unnecessary_null_comparison - assert(write != null) { + SuperPostIncDec(this.read, this.write) { read.parent = this; write.parent = this; } @@ -1914,11 +1813,7 @@ class IndexGet extends InternalExpression { /// The index expression of the operation. Expression index; - IndexGet(this.receiver, this.index) - // ignore: unnecessary_null_comparison - : assert(receiver != null), - // ignore: unnecessary_null_comparison - assert(index != null) { + IndexGet(this.receiver, this.index) { receiver.parent = this; index.parent = this; } @@ -1968,15 +1863,7 @@ class IndexSet extends InternalExpression { final bool forEffect; - IndexSet(this.receiver, this.index, this.value, {required this.forEffect}) - // ignore: unnecessary_null_comparison - : assert(receiver != null), - // ignore: unnecessary_null_comparison - assert(index != null), - // ignore: unnecessary_null_comparison - assert(value != null), - // ignore: unnecessary_null_comparison - assert(forEffect != null) { + IndexSet(this.receiver, this.index, this.value, {required this.forEffect}) { receiver.parent = this; index.parent = this; value.parent = this; @@ -2026,11 +1913,7 @@ class SuperIndexSet extends InternalExpression { /// The value expression of the operation. Expression value; - SuperIndexSet(this.setter, this.index, this.value) - // ignore: unnecessary_null_comparison - : assert(index != null), - // ignore: unnecessary_null_comparison - assert(value != null) { + SuperIndexSet(this.setter, this.index, this.value) { index.parent = this; value.parent = this; } @@ -2088,13 +1971,7 @@ class ExtensionIndexSet extends InternalExpression { ExtensionIndexSet(this.extension, this.explicitTypeArguments, this.receiver, this.setter, this.index, this.value) : assert(explicitTypeArguments == null || - explicitTypeArguments.length == extension.typeParameters.length), - // ignore: unnecessary_null_comparison - assert(receiver != null), - // ignore: unnecessary_null_comparison - assert(index != null), - // ignore: unnecessary_null_comparison - assert(value != null) { + explicitTypeArguments.length == extension.typeParameters.length) { receiver.parent = this; index.parent = this; value.parent = this; @@ -2175,21 +2052,7 @@ class IfNullIndexSet extends InternalExpression { {required this.readOffset, required this.testOffset, required this.writeOffset, - required this.forEffect}) - // ignore: unnecessary_null_comparison - : assert(receiver != null), - // ignore: unnecessary_null_comparison - assert(index != null), - // ignore: unnecessary_null_comparison - assert(value != null), - // ignore: unnecessary_null_comparison - assert(readOffset != null), - // ignore: unnecessary_null_comparison - assert(testOffset != null), - // ignore: unnecessary_null_comparison - assert(writeOffset != null), - // ignore: unnecessary_null_comparison - assert(forEffect != null) { + required this.forEffect}) { receiver.parent = this; index.parent = this; value.parent = this; @@ -2255,19 +2118,7 @@ class IfNullSuperIndexSet extends InternalExpression { {required this.readOffset, required this.testOffset, required this.writeOffset, - required this.forEffect}) - // ignore: unnecessary_null_comparison - : assert(index != null), - // ignore: unnecessary_null_comparison - assert(value != null), - // ignore: unnecessary_null_comparison - assert(readOffset != null), - // ignore: unnecessary_null_comparison - assert(testOffset != null), - // ignore: unnecessary_null_comparison - assert(writeOffset != null), - // ignore: unnecessary_null_comparison - assert(forEffect != null) { + required this.forEffect}) { index.parent = this; value.parent = this; } @@ -2342,21 +2193,7 @@ class IfNullExtensionIndexSet extends InternalExpression { required this.writeOffset, required this.forEffect}) : assert(explicitTypeArguments == null || - explicitTypeArguments.length == extension.typeParameters.length), - // ignore: unnecessary_null_comparison - assert(receiver != null), - // ignore: unnecessary_null_comparison - assert(index != null), - // ignore: unnecessary_null_comparison - assert(value != null), - // ignore: unnecessary_null_comparison - assert(readOffset != null), - // ignore: unnecessary_null_comparison - assert(testOffset != null), - // ignore: unnecessary_null_comparison - assert(writeOffset != null), - // ignore: unnecessary_null_comparison - assert(forEffect != null) { + explicitTypeArguments.length == extension.typeParameters.length) { receiver.parent = this; index.parent = this; value.parent = this; @@ -2421,23 +2258,7 @@ class CompoundIndexSet extends InternalExpression { required this.binaryOffset, required this.writeOffset, required this.forEffect, - required this.forPostIncDec}) - // ignore: unnecessary_null_comparison - : assert(receiver != null), - // ignore: unnecessary_null_comparison - assert(index != null), - // ignore: unnecessary_null_comparison - assert(rhs != null), - // ignore: unnecessary_null_comparison - assert(readOffset != null), - // ignore: unnecessary_null_comparison - assert(binaryOffset != null), - // ignore: unnecessary_null_comparison - assert(writeOffset != null), - // ignore: unnecessary_null_comparison - assert(forEffect != null), - // ignore: unnecessary_null_comparison - assert(forPostIncDec != null) { + required this.forPostIncDec}) { receiver.parent = this; index.parent = this; rhs.parent = this; @@ -2546,21 +2367,7 @@ class NullAwareCompoundSet extends InternalExpression { required this.binaryOffset, required this.writeOffset, required this.forEffect, - required this.forPostIncDec}) - // ignore: unnecessary_null_comparison - : assert(receiver != null), - // ignore: unnecessary_null_comparison - assert(rhs != null), - // ignore: unnecessary_null_comparison - assert(readOffset != null), - // ignore: unnecessary_null_comparison - assert(binaryOffset != null), - // ignore: unnecessary_null_comparison - assert(writeOffset != null), - // ignore: unnecessary_null_comparison - assert(forEffect != null), - // ignore: unnecessary_null_comparison - assert(forPostIncDec != null) { + required this.forPostIncDec}) { receiver.parent = this; rhs.parent = this; fileOffset = binaryOffset; @@ -2648,19 +2455,7 @@ class NullAwareIfNullSet extends InternalExpression { {required this.readOffset, required this.writeOffset, required this.testOffset, - required this.forEffect}) - // ignore: unnecessary_null_comparison - : assert(receiver != null), - // ignore: unnecessary_null_comparison - assert(value != null), - // ignore: unnecessary_null_comparison - assert(readOffset != null), - // ignore: unnecessary_null_comparison - assert(writeOffset != null), - // ignore: unnecessary_null_comparison - assert(testOffset != null), - // ignore: unnecessary_null_comparison - assert(forEffect != null) { + required this.forEffect}) { receiver.parent = this; value.parent = this; } @@ -2736,21 +2531,7 @@ class CompoundSuperIndexSet extends InternalExpression { required this.binaryOffset, required this.writeOffset, required this.forEffect, - required this.forPostIncDec}) - // ignore: unnecessary_null_comparison - : assert(index != null), - // ignore: unnecessary_null_comparison - assert(rhs != null), - // ignore: unnecessary_null_comparison - assert(readOffset != null), - // ignore: unnecessary_null_comparison - assert(binaryOffset != null), - // ignore: unnecessary_null_comparison - assert(writeOffset != null), - // ignore: unnecessary_null_comparison - assert(forEffect != null), - // ignore: unnecessary_null_comparison - assert(forPostIncDec != null) { + required this.forPostIncDec}) { index.parent = this; rhs.parent = this; fileOffset = binaryOffset; @@ -2839,23 +2620,7 @@ class CompoundExtensionIndexSet extends InternalExpression { required this.forEffect, required this.forPostIncDec}) : assert(explicitTypeArguments == null || - explicitTypeArguments.length == extension.typeParameters.length), - // ignore: unnecessary_null_comparison - assert(receiver != null), - // ignore: unnecessary_null_comparison - assert(index != null), - // ignore: unnecessary_null_comparison - assert(rhs != null), - // ignore: unnecessary_null_comparison - assert(readOffset != null), - // ignore: unnecessary_null_comparison - assert(binaryOffset != null), - // ignore: unnecessary_null_comparison - assert(writeOffset != null), - // ignore: unnecessary_null_comparison - assert(forEffect != null), - // ignore: unnecessary_null_comparison - assert(forPostIncDec != null) { + explicitTypeArguments.length == extension.typeParameters.length) { receiver.parent = this; index.parent = this; rhs.parent = this; @@ -2914,16 +2679,9 @@ class ExtensionSet extends InternalExpression { final bool forEffect; ExtensionSet(this.extension, this.explicitTypeArguments, this.receiver, - this.target, this.value, - {required this.forEffect}) + this.target, this.value, {required this.forEffect}) : assert(explicitTypeArguments == null || - explicitTypeArguments.length == extension.typeParameters.length), - // ignore: unnecessary_null_comparison - assert(receiver != null), - // ignore: unnecessary_null_comparison - assert(value != null), - // ignore: unnecessary_null_comparison - assert(forEffect != null) { + explicitTypeArguments.length == extension.typeParameters.length) { receiver.parent = this; value.parent = this; } @@ -2953,11 +2711,7 @@ class NullAwareExtension extends InternalExpression { VariableDeclarationImpl variable; Expression expression; - NullAwareExtension(this.variable, this.expression) - // ignore: unnecessary_null_comparison - : assert(variable != null), - // ignore: unnecessary_null_comparison - assert(expression != null) { + NullAwareExtension(this.variable, this.expression) { variable.parent = this; expression.parent = this; } @@ -2993,9 +2747,7 @@ class ExtensionTearOff extends InternalExpression { /// The arguments provided to the top-level method. Arguments arguments; - ExtensionTearOff(this.target, this.arguments) - // ignore: unnecessary_null_comparison - : assert(arguments != null) { + ExtensionTearOff(this.target, this.arguments) { arguments.parent = this; } @@ -3017,13 +2769,7 @@ class EqualsExpression extends InternalExpression { Expression right; bool isNot; - EqualsExpression(this.left, this.right, {required this.isNot}) - // ignore: unnecessary_null_comparison - : assert(left != null), - // ignore: unnecessary_null_comparison - assert(right != null), - // ignore: unnecessary_null_comparison - assert(isNot != null) { + EqualsExpression(this.left, this.right, {required this.isNot}) { left.parent = this; right.parent = this; } @@ -3057,11 +2803,7 @@ class BinaryExpression extends InternalExpression { Name binaryName; Expression right; - BinaryExpression(this.left, this.binaryName, this.right) - // ignore: unnecessary_null_comparison - : assert(left != null), - // ignore: unnecessary_null_comparison - assert(right != null) { + BinaryExpression(this.left, this.binaryName, this.right) { left.parent = this; right.parent = this; } @@ -3093,9 +2835,7 @@ class UnaryExpression extends InternalExpression { Name unaryName; Expression expression; - UnaryExpression(this.unaryName, this.expression) - // ignore: unnecessary_null_comparison - : assert(expression != null) { + UnaryExpression(this.unaryName, this.expression) { expression.parent = this; } @@ -3128,9 +2868,7 @@ class UnaryExpression extends InternalExpression { class ParenthesizedExpression extends InternalExpression { Expression expression; - ParenthesizedExpression(this.expression) - // ignore: unnecessary_null_comparison - : assert(expression != null) { + ParenthesizedExpression(this.expression) { expression.parent = this; } @@ -3198,11 +2936,7 @@ class MethodInvocation extends InternalExpression { Arguments arguments; - MethodInvocation(this.receiver, this.name, this.arguments) - // ignore: unnecessary_null_comparison - : assert(receiver != null), - // ignore: unnecessary_null_comparison - assert(arguments != null) { + MethodInvocation(this.receiver, this.name, this.arguments) { receiver.parent = this; arguments.parent = this; } @@ -3240,9 +2974,7 @@ class PropertyGet extends InternalExpression { Name name; - PropertyGet(this.receiver, this.name) - // ignore: unnecessary_null_comparison - : assert(receiver != null) { + PropertyGet(this.receiver, this.name) { receiver.parent = this; } @@ -3286,15 +3018,7 @@ class PropertySet extends InternalExpression { final bool readOnlyReceiver; PropertySet(this.receiver, this.name, this.value, - {required this.forEffect, required this.readOnlyReceiver}) - // ignore: unnecessary_null_comparison - : assert(receiver != null), - // ignore: unnecessary_null_comparison - assert(value != null), - // ignore: unnecessary_null_comparison - assert(forEffect != null), - // ignore: unnecessary_null_comparison - assert(readOnlyReceiver != null) { + {required this.forEffect, required this.readOnlyReceiver}) { receiver.parent = this; value.parent = this; } diff --git a/pkg/front_end/lib/src/fasta/kernel/kernel_target.dart b/pkg/front_end/lib/src/fasta/kernel/kernel_target.dart index 4475119fb01..5daeeadec2a 100644 --- a/pkg/front_end/lib/src/fasta/kernel/kernel_target.dart +++ b/pkg/front_end/lib/src/fasta/kernel/kernel_target.dart @@ -259,14 +259,11 @@ class KernelTarget extends TargetImplementation { void _parseCurrentSdkVersion() { bool good = false; - // ignore: unnecessary_null_comparison - if (currentSdkVersionString != null) { - List dotSeparatedParts = currentSdkVersionString.split("."); - if (dotSeparatedParts.length >= 2) { - _currentSdkVersion = new Version(int.tryParse(dotSeparatedParts[0])!, - int.tryParse(dotSeparatedParts[1])!); - good = true; - } + List dotSeparatedParts = currentSdkVersionString.split("."); + if (dotSeparatedParts.length >= 2) { + _currentSdkVersion = new Version(int.tryParse(dotSeparatedParts[0])!, + int.tryParse(dotSeparatedParts[1])!); + good = true; } if (!good) { throw new StateError( @@ -1552,8 +1549,7 @@ class KernelTarget extends TargetImplementation { constants.ConstantCoverage coverage = constantEvaluationData.coverage; coverage.constructorCoverage.forEach((Uri fileUri, Set value) { Source? source = uriToSource[fileUri]; - // ignore: unnecessary_null_comparison - if (source != null && fileUri != null) { + if (source != null) { source.constantCoverageConstructors ??= new Set(); source.constantCoverageConstructors!.addAll(value); } diff --git a/pkg/front_end/lib/src/fasta/kernel/late_lowering.dart b/pkg/front_end/lib/src/fasta/kernel/late_lowering.dart index 4f1045cfcc1..ae79c732ac9 100644 --- a/pkg/front_end/lib/src/fasta/kernel/late_lowering.dart +++ b/pkg/front_end/lib/src/fasta/kernel/late_lowering.dart @@ -26,8 +26,6 @@ Statement createGetterWithInitializer(CoreTypes coreTypes, int fileOffset, required Expression createIsSetRead(), required Expression createIsSetWrite(Expression value), required IsSetEncoding isSetEncoding}) { - // ignore: unnecessary_null_comparison - assert(isSetEncoding != null); switch (isSetEncoding) { case IsSetEncoding.useIsSetField: // Generate: @@ -120,8 +118,6 @@ Statement createGetterWithInitializerWithRecheck(CoreTypes coreTypes, required Expression createIsSetWrite(Expression value), required IsSetEncoding isSetEncoding, required bool forField}) { - // ignore: unnecessary_null_comparison - assert(forField != null); Constructor constructor = forField ? coreTypes.lateInitializationFieldAssignedDuringInitializationConstructor : coreTypes @@ -271,10 +267,6 @@ Statement createGetterBodyWithoutInitializer( required Expression createIsSetRead(), required IsSetEncoding isSetEncoding, required bool forField}) { - // ignore: unnecessary_null_comparison - assert(forField != null); - // ignore: unnecessary_null_comparison - assert(isSetEncoding != null); Expression exception = new Throw( new ConstructorInvocation( forField @@ -356,8 +348,6 @@ Statement createSetterBody(CoreTypes coreTypes, int fileOffset, String name, required Expression createVariableWrite(Expression value), required Expression createIsSetWrite(Expression value), required IsSetEncoding isSetEncoding}) { - // ignore: unnecessary_null_comparison - assert(isSetEncoding != null); Statement createReturn(Expression value) { if (shouldReturnValue) { return new ReturnStatement(value)..fileOffset = fileOffset; @@ -406,10 +396,6 @@ Statement createSetterBodyFinal(CoreTypes coreTypes, int fileOffset, required Expression createIsSetWrite(Expression value), required IsSetEncoding isSetEncoding, required bool forField}) { - // ignore: unnecessary_null_comparison - assert(forField != null); - // ignore: unnecessary_null_comparison - assert(isSetEncoding != null); Expression exception = new Throw( new ConstructorInvocation( forField diff --git a/pkg/front_end/lib/src/fasta/kernel/member_covariance.dart b/pkg/front_end/lib/src/fasta/kernel/member_covariance.dart index 1e7600cf540..f87f1806c2a 100644 --- a/pkg/front_end/lib/src/fasta/kernel/member_covariance.dart +++ b/pkg/front_end/lib/src/fasta/kernel/member_covariance.dart @@ -155,8 +155,6 @@ class Covariance { /// aspect of [member]. Otherwise, the covariance for the getter/method aspect /// of [member] is computed. factory Covariance.fromMember(Member member, {required bool forSetter}) { - // ignore: unnecessary_null_comparison - assert(forSetter != null); if (member is Procedure) { if (member.kind == ProcedureKind.Getter) { return const Covariance.empty(); diff --git a/pkg/front_end/lib/src/fasta/kernel/type_algorithms.dart b/pkg/front_end/lib/src/fasta/kernel/type_algorithms.dart index 7d45ed025bb..e51e08e08cf 100644 --- a/pkg/front_end/lib/src/fasta/kernel/type_algorithms.dart +++ b/pkg/front_end/lib/src/fasta/kernel/type_algorithms.dart @@ -168,13 +168,6 @@ int computeTypeVariableBuilderVariance(TypeVariableBuilder variable, /// type parameter occurrence or on the type argument replacing it. NullabilityBuilder combineNullabilityBuildersForSubstitution( NullabilityBuilder a, NullabilityBuilder b) { - assert( - // ignore: unnecessary_null_comparison - a != null && b != null, - "Both arguments to combineNullabilityBuildersForSubstitution " - "should be identical to either 'const NullabilityBuilder.nullable()' or " - "'const NullabilityBuilder.omitted()'."); - if (identical(a, const NullabilityBuilder.inherent()) && identical(b, const NullabilityBuilder.inherent())) { return const NullabilityBuilder.inherent(); @@ -219,14 +212,6 @@ TypeBuilder substituteRange( List? arguments; TypeDeclarationBuilder? declaration = type.declaration; if (declaration == null) { - // ignore: unnecessary_null_comparison - assert(unboundTypes != null, - "Can not handle unbound named type builders without `unboundTypes`."); - assert( - // ignore: unnecessary_null_comparison - unboundTypeVariables != null, - "Can not handle unbound named type builders without " - "`unboundTypeVariables`."); assert( identical(upperSubstitution, lowerSubstitution), "Can only handle unbound named type builders identical " @@ -445,11 +430,6 @@ List calculateBounds(List variables, TypeBuilder dynamicType, TypeBuilder bottomType, {required List unboundTypes, required List unboundTypeVariables}) { - // ignore: unnecessary_null_comparison - assert(unboundTypes != null); - // ignore: unnecessary_null_comparison - assert(unboundTypeVariables != null); - List bounds = new List.generate( variables.length, (int i) => variables[i].bound ?? dynamicType, growable: false); @@ -1084,8 +1064,6 @@ void breakCycles(List> cycles) { /// Finds generic function type sub-terms in [type]. void findUnaliasedGenericFunctionTypes(TypeBuilder? type, {required List result}) { - // ignore: unnecessary_null_comparison - assert(result != null); if (type is FunctionTypeBuilder) { if (type.typeVariables != null && type.typeVariables!.length > 0) { result.add(type); @@ -1114,8 +1092,6 @@ void findUnaliasedGenericFunctionTypes(TypeBuilder? type, /// Finds generic function type sub-terms in [type] including the aliased ones. void findGenericFunctionTypes(TypeBuilder? type, {required List result}) { - // ignore: unnecessary_null_comparison - assert(result != null); if (type is FunctionTypeBuilder) { if (type.typeVariables != null && type.typeVariables!.length > 0) { result.add(type); diff --git a/pkg/front_end/lib/src/fasta/kernel/type_labeler.dart b/pkg/front_end/lib/src/fasta/kernel/type_labeler.dart index 421645acf45..35316ebcd13 100644 --- a/pkg/front_end/lib/src/fasta/kernel/type_labeler.dart +++ b/pkg/front_end/lib/src/fasta/kernel/type_labeler.dart @@ -31,9 +31,6 @@ class TypeLabeler implements DartTypeVisitor, ConstantVisitor { /// pretty-printed, the returned list can be converted to its string /// representation (with labels on duplicated names) by the `join()` method. List labelType(DartType type) { - // TODO(askesc): Remove null check when we are completely null clean here. - // ignore: unnecessary_null_comparison - if (type == null) return ["null-type"]; result = []; type.accept(this); return result; @@ -44,9 +41,6 @@ class TypeLabeler implements DartTypeVisitor, ConstantVisitor { /// pretty-printed, the returned list can be converted to its string /// representation (with labels on duplicated names) by the `join()` method. List labelConstant(Constant constant) { - // TODO(askesc): Remove null check when we are completely null clean here. - // ignore: unnecessary_null_comparison - if (constant == null) return ["null-constant"]; result = []; constant.accept(this); return result; diff --git a/pkg/front_end/lib/src/fasta/library_graph.dart b/pkg/front_end/lib/src/fasta/library_graph.dart index 95a362738bf..42fe72272b4 100644 --- a/pkg/front_end/lib/src/fasta/library_graph.dart +++ b/pkg/front_end/lib/src/fasta/library_graph.dart @@ -32,8 +32,7 @@ class LibraryGraph implements Graph { Uri uri2 = dependency.targetLibrary.fileUri; if (libraries.containsKey(uri1)) { yield uri1; - // ignore: unnecessary_null_comparison - } else if (uri2 != null) { + } else { if (libraries.containsKey(uri2)) { yield uri2; } diff --git a/pkg/front_end/lib/src/fasta/scope.dart b/pkg/front_end/lib/src/fasta/scope.dart index 3a1ce6c3ffa..d8eb330c9b6 100644 --- a/pkg/front_end/lib/src/fasta/scope.dart +++ b/pkg/front_end/lib/src/fasta/scope.dart @@ -149,10 +149,7 @@ class MutableScope { final ScopeKind kind; MutableScope(this.kind, this._local, this._setters, this._extensions, - this._parent, this.classNameOrDebugName) { - // ignore: unnecessary_null_comparison - assert(classNameOrDebugName != null); - } + this._parent, this.classNameOrDebugName); Scope? get parent => _parent; 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 16a7d269491..7ca7acb431d 100644 --- a/pkg/front_end/lib/src/fasta/source/diet_listener.dart +++ b/pkg/front_end/lib/src/fasta/source/diet_listener.dart @@ -827,10 +827,6 @@ class DietListener extends StackListenerImpl { builder.computeTypeParameterScope(memberScope); final Scope formalParameterScope = builder.computeFormalParameterScope(typeParameterScope); - // ignore: unnecessary_null_comparison - assert(typeParameterScope != null); - // ignore: unnecessary_null_comparison - assert(formalParameterScope != null); return createListener( builder.bodyBuilderContext, builder, typeParameterScope, thisVariable: builder.thisVariable, diff --git a/pkg/front_end/lib/src/fasta/source/name_scheme.dart b/pkg/front_end/lib/src/fasta/source/name_scheme.dart index 5b5c0ac27ca..04e344b02dd 100644 --- a/pkg/front_end/lib/src/fasta/source/name_scheme.dart +++ b/pkg/front_end/lib/src/fasta/source/name_scheme.dart @@ -22,11 +22,7 @@ class NameScheme { required this.containerName, required this.containerType, required this.libraryName}) - // ignore: unnecessary_null_comparison - : assert(isInstanceMember != null), - // ignore: unnecessary_null_comparison - assert(libraryName != null), - assert((containerName == null) == + : assert((containerName == null) == (containerType == ContainerType.Library)); bool get isStatic => !isInstanceMember; diff --git a/pkg/front_end/lib/src/fasta/source/source_class_builder.dart b/pkg/front_end/lib/src/fasta/source/source_class_builder.dart index 7007a7a2843..17f8757ebf3 100644 --- a/pkg/front_end/lib/src/fasta/source/source_class_builder.dart +++ b/pkg/front_end/lib/src/fasta/source/source_class_builder.dart @@ -536,13 +536,10 @@ class SourceClassBuilder extends ClassBuilderImpl for (int i = 0; i < variables.length; i++) { DartType argument = i < arguments.length ? arguments[i] : const DynamicType(); - // ignore: unnecessary_null_comparison - if (substitutionMap != null) { - // TODO(ahe): Investigate if requiring the caller to use - // `substituteDeep` from `package:kernel/type_algebra.dart` instead - // of `substitute` is faster. If so, we can simply this code. - argument = substitute(argument, substitutionMap); - } + // TODO(ahe): Investigate if requiring the caller to use + // `substituteDeep` from `package:kernel/type_algebra.dart` instead + // of `substitute` is faster. If so, we can simply this code. + argument = substitute(argument, substitutionMap); directSubstitutionMap[variables[i]] = argument; } substitutionMap = directSubstitutionMap; @@ -1040,50 +1037,39 @@ class SourceClassBuilder extends ClassBuilderImpl procedure.function.namedParameters; DartType returnType = procedure.function.returnType; - // ignore: unnecessary_null_comparison - if (functionTypeParameters != null) { - for (TypeParameter functionParameter in functionTypeParameters) { - for (TypeParameter typeParameter in typeParameters) { - int typeVariance = Variance.combine(Variance.invariant, - computeVariance(typeParameter, functionParameter.bound)); - reportVariancePositionIfInvalid(typeVariance, typeParameter, fileUri, - functionParameter.fileOffset); - } - } - } - // ignore: unnecessary_null_comparison - if (positionalParameters != null) { - for (VariableDeclaration formal in positionalParameters) { - if (!formal.isCovariantByDeclaration) { - for (TypeParameter typeParameter in typeParameters) { - int formalVariance = Variance.combine(Variance.contravariant, - computeVariance(typeParameter, formal.type)); - reportVariancePositionIfInvalid( - formalVariance, typeParameter, fileUri, formal.fileOffset); - } - } - } - } - // ignore: unnecessary_null_comparison - if (namedParameters != null) { - for (VariableDeclaration named in namedParameters) { - for (TypeParameter typeParameter in typeParameters) { - int namedVariance = Variance.combine(Variance.contravariant, - computeVariance(typeParameter, named.type)); - reportVariancePositionIfInvalid( - namedVariance, typeParameter, fileUri, named.fileOffset); - } - } - } - // ignore: unnecessary_null_comparison - if (returnType != null) { + for (TypeParameter functionParameter in functionTypeParameters) { for (TypeParameter typeParameter in typeParameters) { - int returnTypeVariance = computeVariance(typeParameter, returnType); - reportVariancePositionIfInvalid(returnTypeVariance, typeParameter, - fileUri, procedure.function.fileOffset, - isReturnType: true); + int typeVariance = Variance.combine(Variance.invariant, + computeVariance(typeParameter, functionParameter.bound)); + reportVariancePositionIfInvalid( + typeVariance, typeParameter, fileUri, functionParameter.fileOffset); } } + for (VariableDeclaration formal in positionalParameters) { + if (!formal.isCovariantByDeclaration) { + for (TypeParameter typeParameter in typeParameters) { + int formalVariance = Variance.combine(Variance.contravariant, + computeVariance(typeParameter, formal.type)); + reportVariancePositionIfInvalid( + formalVariance, typeParameter, fileUri, formal.fileOffset); + } + } + } + for (VariableDeclaration named in namedParameters) { + for (TypeParameter typeParameter in typeParameters) { + int namedVariance = Variance.combine( + Variance.contravariant, computeVariance(typeParameter, named.type)); + reportVariancePositionIfInvalid( + namedVariance, typeParameter, fileUri, named.fileOffset); + } + } + + for (TypeParameter typeParameter in typeParameters) { + int returnTypeVariance = computeVariance(typeParameter, returnType); + reportVariancePositionIfInvalid(returnTypeVariance, typeParameter, + fileUri, procedure.function.fileOffset, + isReturnType: true); + } } void reportVariancePositionIfInvalid( @@ -1406,75 +1392,72 @@ class SourceClassBuilder extends ClassBuilderImpl } } - // ignore: unnecessary_null_comparison - if (redirectionTarget != null) { - Builder? targetBuilder = redirectionTarget.target; - if (declaration.next == null) { - // Only the first one (that is, the last on in the linked list) - // is actually in the kernel tree. This call creates a StaticGet - // to [declaration.target] in a field `_redirecting#` which is - // only legal to do to things in the kernel tree. - Reference? fieldReference; - Reference? getterReference; - if (referencesFromIndexed != null) { - Name name = - new Name(redirectingName, referencesFromIndexed!.library); - fieldReference = - referencesFromIndexed!.lookupFieldReference(name); - getterReference = - referencesFromIndexed!.lookupGetterReference(name); - } - _addRedirectingConstructor( - declaration, library, fieldReference, getterReference); - } - Member? targetNode; - if (targetBuilder is FunctionBuilder) { - targetNode = targetBuilder.member; - } else if (targetBuilder is DillMemberBuilder) { - targetNode = targetBuilder.member; - } else if (targetBuilder is AmbiguousBuilder) { - addProblemForRedirectingFactory( - declaration, - templateDuplicatedDeclarationUse - .withArguments(redirectionTarget.fullNameForErrors), - redirectionTarget.charOffset, - noLength); - } else { - addProblemForRedirectingFactory( - declaration, - templateRedirectionTargetNotFound - .withArguments(redirectionTarget.fullNameForErrors), - redirectionTarget.charOffset, - noLength); - } - if (targetNode != null && - targetNode is Constructor && - targetNode.enclosingClass.isAbstract) { - addProblemForRedirectingFactory( - declaration, - templateAbstractRedirectedClassInstantiation - .withArguments(redirectionTarget.fullNameForErrors), - redirectionTarget.charOffset, - noLength); - targetNode = null; - } - if (targetNode != null && - targetNode is Constructor && - targetNode.enclosingClass.isEnum) { - addProblemForRedirectingFactory( - declaration, - messageEnumFactoryRedirectsToConstructor, - redirectionTarget.charOffset, - noLength); - targetNode = null; - } - if (targetNode != null) { - List typeArguments = declaration.typeArguments ?? - new List.filled( - targetNode.enclosingClass!.typeParameters.length, - const UnknownType()); - declaration.setRedirectingFactoryBody(targetNode, typeArguments); + Builder? targetBuilder = redirectionTarget.target; + if (declaration.next == null) { + // Only the first one (that is, the last on in the linked list) + // is actually in the kernel tree. This call creates a StaticGet + // to [declaration.target] in a field `_redirecting#` which is + // only legal to do to things in the kernel tree. + Reference? fieldReference; + Reference? getterReference; + if (referencesFromIndexed != null) { + Name name = + new Name(redirectingName, referencesFromIndexed!.library); + fieldReference = + referencesFromIndexed!.lookupFieldReference(name); + getterReference = + referencesFromIndexed!.lookupGetterReference(name); } + _addRedirectingConstructor( + declaration, library, fieldReference, getterReference); + } + Member? targetNode; + if (targetBuilder is FunctionBuilder) { + targetNode = targetBuilder.member; + } else if (targetBuilder is DillMemberBuilder) { + targetNode = targetBuilder.member; + } else if (targetBuilder is AmbiguousBuilder) { + addProblemForRedirectingFactory( + declaration, + templateDuplicatedDeclarationUse + .withArguments(redirectionTarget.fullNameForErrors), + redirectionTarget.charOffset, + noLength); + } else { + addProblemForRedirectingFactory( + declaration, + templateRedirectionTargetNotFound + .withArguments(redirectionTarget.fullNameForErrors), + redirectionTarget.charOffset, + noLength); + } + if (targetNode != null && + targetNode is Constructor && + targetNode.enclosingClass.isAbstract) { + addProblemForRedirectingFactory( + declaration, + templateAbstractRedirectedClassInstantiation + .withArguments(redirectionTarget.fullNameForErrors), + redirectionTarget.charOffset, + noLength); + targetNode = null; + } + if (targetNode != null && + targetNode is Constructor && + targetNode.enclosingClass.isEnum) { + addProblemForRedirectingFactory( + declaration, + messageEnumFactoryRedirectsToConstructor, + redirectionTarget.charOffset, + noLength); + targetNode = null; + } + if (targetNode != null) { + List typeArguments = declaration.typeArguments ?? + new List.filled( + targetNode.enclosingClass!.typeParameters.length, + const UnknownType()); + declaration.setRedirectingFactoryBody(targetNode, typeArguments); } } } @@ -1508,10 +1491,6 @@ class SourceClassBuilder extends ClassBuilderImpl callback(Member interfaceMember, bool isSetter), {required bool isInterfaceCheck, required bool declaredNeedsLegacyErasure}) { - // ignore: unnecessary_null_comparison - assert(isInterfaceCheck != null); - // ignore: unnecessary_null_comparison - assert(declaredNeedsLegacyErasure != null); if (declaredMember == interfaceMember) { return; } diff --git a/pkg/front_end/lib/src/fasta/source/source_extension_builder.dart b/pkg/front_end/lib/src/fasta/source/source_extension_builder.dart index 7881669a163..12a56a600d1 100644 --- a/pkg/front_end/lib/src/fasta/source/source_extension_builder.dart +++ b/pkg/front_end/lib/src/fasta/source/source_extension_builder.dart @@ -157,8 +157,6 @@ class SourceExtensionBuilder extends ExtensionBuilderImpl kind = ExtensionMemberKind.TearOff; break; } - // ignore: unnecessary_null_comparison - assert(kind != null); extension.members.add(new ExtensionMemberDescriptor( name: new Name(name, libraryBuilder.library), member: memberReference, diff --git a/pkg/front_end/lib/src/fasta/source/source_field_builder.dart b/pkg/front_end/lib/src/fasta/source/source_field_builder.dart index 11f05d30c1b..d398742a12c 100644 --- a/pkg/front_end/lib/src/fasta/source/source_field_builder.dart +++ b/pkg/front_end/lib/src/fasta/source/source_field_builder.dart @@ -623,14 +623,6 @@ class RegularFieldEncoding implements FieldEncoding { required Reference? getterReference, required Reference? setterReference, required bool isEnumElement}) { - // ignore: unnecessary_null_comparison - assert(isFinal != null); - // ignore: unnecessary_null_comparison - assert(isConst != null); - // ignore: unnecessary_null_comparison - assert(isLate != null); - // ignore: unnecessary_null_comparison - assert(hasInitializer != null); bool isImmutable = isLate ? (isFinal && hasInitializer) : (isFinal || isConst); _field = isImmutable @@ -759,9 +751,7 @@ class SourceFieldMember extends BuilderClassMember { @override final bool forSetter; - SourceFieldMember(this.memberBuilder, {required this.forSetter}) - // ignore: unnecessary_null_comparison - : assert(forSetter != null); + SourceFieldMember(this.memberBuilder, {required this.forSetter}); @override void inferType(ClassMembersBuilder membersBuilder) { @@ -1011,8 +1001,6 @@ abstract class AbstractLateFieldEncoding implements FieldEncoding { Procedure? _createSetter(Uri fileUri, int charOffset, Reference? reference, {required bool isCovariantByDeclaration}) { - // ignore: unnecessary_null_comparison - assert(isCovariantByDeclaration != null); VariableDeclaration parameter = new VariableDeclaration("${name}#param") ..isCovariantByDeclaration = isCovariantByDeclaration ..fileOffset = fileOffset; @@ -1433,9 +1421,7 @@ class _SynthesizedFieldClassMember implements ClassMember { final bool isInternalImplementation; _SynthesizedFieldClassMember(this.fieldBuilder, this._member, this._kind, - {this.forSetter = false, required this.isInternalImplementation}) - // ignore: unnecessary_null_comparison - : assert(isInternalImplementation != null); + {this.forSetter = false, required this.isInternalImplementation}); @override Member getMember(ClassMembersBuilder membersBuilder) { @@ -1519,10 +1505,7 @@ class _SynthesizedFieldClassMember implements ClassMember { String get fullName { String suffix = isSetter ? "=" : ""; String className = classBuilder.fullNameForErrors; - // ignore: unnecessary_null_comparison - return className == null - ? "${fullNameForErrors}$suffix" - : "${className}.${fullNameForErrors}$suffix"; + return "${className}.${fullNameForErrors}$suffix"; } @override @@ -1591,17 +1574,7 @@ class AbstractOrExternalFieldEncoding implements FieldEncoding { required bool isFinal, required bool isCovariantByDeclaration, required bool isNonNullableByDefault}) - // ignore: unnecessary_null_comparison - : assert(isAbstract != null), - // ignore: unnecessary_null_comparison - assert(isExternal != null), - // ignore: unnecessary_null_comparison - assert(isFinal != null), - // ignore: unnecessary_null_comparison - assert(isCovariantByDeclaration != null), - // ignore: unnecessary_null_comparison - assert(isNonNullableByDefault != null), - _isExtensionInstanceMember = isExternal && + : _isExtensionInstanceMember = isExternal && nameScheme.isExtensionMember && nameScheme.isInstanceMember, _isInlineClassInstanceMember = isExternal && diff --git a/pkg/front_end/lib/src/fasta/source/source_inline_class_builder.dart b/pkg/front_end/lib/src/fasta/source/source_inline_class_builder.dart index c4a59cc1ce4..66f74e44fae 100644 --- a/pkg/front_end/lib/src/fasta/source/source_inline_class_builder.dart +++ b/pkg/front_end/lib/src/fasta/source/source_inline_class_builder.dart @@ -195,8 +195,6 @@ class SourceInlineClassBuilder extends InlineClassBuilderImpl kind = InlineClassMemberKind.TearOff; break; } - // ignore: unnecessary_null_comparison - assert(kind != null); inlineClass.members.add(new InlineClassMemberDescriptor( name: new Name(name, libraryBuilder.library), member: memberReference, diff --git a/pkg/front_end/lib/src/fasta/source/source_library_builder.dart b/pkg/front_end/lib/src/fasta/source/source_library_builder.dart index 63b555051ca..ccd307688a5 100644 --- a/pkg/front_end/lib/src/fasta/source/source_library_builder.dart +++ b/pkg/front_end/lib/src/fasta/source/source_library_builder.dart @@ -1024,11 +1024,6 @@ class SourceLibraryBuilder extends LibraryBuilderImpl { SourceLibraryBuilder sourceLibraryBuilder, Scope scope, {required bool checkForInstanceVsStaticConflict, required bool checkForMethodVsSetterConflict}) { - // ignore: unnecessary_null_comparison - assert(checkForInstanceVsStaticConflict != null); - // ignore: unnecessary_null_comparison - assert(checkForMethodVsSetterConflict != null); - scope.forEachLocalSetter((String name, MemberBuilder setter) { Builder? getable = scope.lookupLocalMember(name, setter: false); if (getable == null) { @@ -2907,10 +2902,6 @@ class SourceLibraryBuilder extends LibraryBuilderImpl { AsyncMarker asyncModifier, {required bool isInstanceMember, required bool isExtensionMember}) { - // ignore: unnecessary_null_comparison - assert(isInstanceMember != null); - // ignore: unnecessary_null_comparison - assert(isExtensionMember != null); assert(!isExtensionMember || currentTypeParameterScopeBuilder.kind == TypeParameterScopeKind.extensionDeclaration); @@ -4337,8 +4328,6 @@ class SourceLibraryBuilder extends LibraryBuilderImpl { String enclosingName = issue.enclosingType == null ? targetName! : getGenericTypeName(issue.enclosingType!); - // ignore: unnecessary_null_comparison - assert(enclosingName != null); if (issueInferred) { message = templateIncorrectTypeArgumentInferred.withArguments( argument, @@ -4577,7 +4566,6 @@ class SourceLibraryBuilder extends LibraryBuilderImpl { // TODO(cstefantsova): Find a better way than relying on [interfaceTarget]. Member? method = membersHierarchy.getDispatchTarget(klass, name) ?? interfaceTarget; - // ignore: unnecessary_null_comparison if (method == null || method is! Procedure) { return; } @@ -4669,8 +4657,6 @@ class SourceLibraryBuilder extends LibraryBuilderImpl { Uri fileUri, int offset, {required bool inferred}) { - // ignore: unnecessary_null_comparison - assert(inferred != null); if (typeArguments.isEmpty) return; List functionTypeParameters = functionType.typeParameters; @@ -5276,10 +5262,7 @@ class TypeParameterScopeBuilder { this.extensions, this._name, this._charOffset, - this.parent) { - // ignore: unnecessary_null_comparison - assert(_name != null); - } + this.parent); TypeParameterScopeBuilder.library() : this( @@ -5687,9 +5670,6 @@ List _sortTypeVariablesTopologically( void _sortTypeVariablesTopologicallyFromRoot(TypeBuilder root, Set unhandled, List result) { - // ignore: unnecessary_null_comparison - assert(root != null); - List? typeVariables; List? internalDependents; diff --git a/pkg/front_end/lib/src/fasta/source/source_loader.dart b/pkg/front_end/lib/src/fasta/source/source_loader.dart index 2a67951690e..bf937b0beff 100644 --- a/pkg/front_end/lib/src/fasta/source/source_loader.dart +++ b/pkg/front_end/lib/src/fasta/source/source_loader.dart @@ -412,10 +412,7 @@ class SourceLoader extends Loader { Message? packageLanguageVersionProblem; if (packageForLanguageVersion != null) { Uri importUri = origin?.importUri ?? uri; - if (!importUri.isScheme('dart') && - !importUri.isScheme('package') && - // ignore: unnecessary_null_comparison - packageForLanguageVersion.name != null) { + if (!importUri.isScheme('dart') && !importUri.isScheme('package')) { packageUri = new Uri(scheme: 'package', path: packageForLanguageVersion.name); } @@ -1205,8 +1202,6 @@ severity: $severity Future buildOutline(SourceLibraryBuilder library) async { Token tokens = await tokenize(library); - // ignore: unnecessary_null_comparison - if (tokens == null) return; OutlineBuilder listener = new OutlineBuilder(library); new ClassMemberParser(listener, allowPatterns: library.libraryFeatures.patterns.isEnabled) @@ -1229,10 +1224,6 @@ severity: $severity // second time, and the first time was in [buildOutline] above. So this // time we suppress lexical errors. Token tokens = await tokenize(library, suppressLexicalErrors: true); - // ignore: unnecessary_null_comparison - if (tokens == null) { - return; - } if (target.benchmarker != null) { // When benchmarking we do extra parsing on it's own to get a timing of @@ -1271,11 +1262,8 @@ severity: $severity } Token tokens = await tokenize(part as SourceLibraryBuilder, suppressLexicalErrors: true); - // ignore: unnecessary_null_comparison - if (tokens != null) { - listener.uri = part.fileUri; - parser.parseUnit(tokens); - } + listener.uri = part.fileUri; + parser.parseUnit(tokens); } } diff --git a/pkg/front_end/lib/src/fasta/source/source_type_alias_builder.dart b/pkg/front_end/lib/src/fasta/source/source_type_alias_builder.dart index 73d3614fa1d..21627522660 100644 --- a/pkg/front_end/lib/src/fasta/source/source_type_alias_builder.dart +++ b/pkg/front_end/lib/src/fasta/source/source_type_alias_builder.dart @@ -107,28 +107,16 @@ class SourceTypeAliasBuilder extends TypeAliasBuilderImpl { // detect cycles by detecting recursive calls to this method using an // instance of InvalidType that isn't identical to `const InvalidType()`. thisType = pendingTypeAliasMarker; - DartType builtType = const InvalidType(); - TypeBuilder type = this.type; - // ignore: unnecessary_null_comparison - if (type != null) { - builtType = type.build(libraryBuilder, TypeUse.typedefAlias); - // ignore: unnecessary_null_comparison - if (builtType != null) { - if (typeVariables != null) { - for (TypeVariableBuilder tv in typeVariables!) { - // Follow bound in order to find all cycles - tv.bound?.build(libraryBuilder, TypeUse.typeParameterBound); - } - } - if (identical(thisType, cyclicTypeAliasMarker)) { - builtType = const InvalidType(); - } else { - builtType = builtType; - } - } else { - builtType = const InvalidType(); + DartType builtType = type.build(libraryBuilder, TypeUse.typedefAlias); + if (typeVariables != null) { + for (TypeVariableBuilder tv in typeVariables!) { + // Follow bound in order to find all cycles + tv.bound?.build(libraryBuilder, TypeUse.typeParameterBound); } } + if (identical(thisType, cyclicTypeAliasMarker)) { + builtType = const InvalidType(); + } return thisType = typedef.type ??= builtType; } diff --git a/pkg/front_end/lib/src/fasta/source/stack_listener_impl.dart b/pkg/front_end/lib/src/fasta/source/stack_listener_impl.dart index e0803318595..e9939a8a60b 100644 --- a/pkg/front_end/lib/src/fasta/source/stack_listener_impl.dart +++ b/pkg/front_end/lib/src/fasta/source/stack_listener_impl.dart @@ -89,8 +89,6 @@ abstract class StackListenerImpl extends StackListener { void reportMissingNonNullableSupport(Token token) { assert(!libraryBuilder.isNonNullableByDefault); - // ignore: unnecessary_null_comparison - assert(token != null); if (libraryFeatures.nonNullable.isSupported) { if (libraryBuilder.languageVersion.isExplicit) { addProblem( diff --git a/pkg/front_end/lib/src/fasta/type_inference/closure_context.dart b/pkg/front_end/lib/src/fasta/type_inference/closure_context.dart index afb1e5b6595..6c4ea11f3dd 100644 --- a/pkg/front_end/lib/src/fasta/type_inference/closure_context.dart +++ b/pkg/front_end/lib/src/fasta/type_inference/closure_context.dart @@ -44,8 +44,6 @@ abstract class ClosureContext { factory ClosureContext(InferenceVisitorBase inferrer, AsyncMarker asyncMarker, DartType returnContext, bool needToInferReturnType) { - // ignore: unnecessary_null_comparison - assert(returnContext != null); DartType declaredReturnType = inferrer.computeGreatestClosure(returnContext); bool isAsync = asyncMarker == AsyncMarker.Async || @@ -326,8 +324,6 @@ class _SyncClosureContext implements ClosureContext { DartType inferReturnType(InferenceVisitorBase inferrer, {required bool hasImplicitReturn}) { assert(_needToInferReturnType); - // ignore: unnecessary_null_comparison - assert(hasImplicitReturn != null); DartType? actualReturnedType; DartType inferredReturnType; if (inferrer.isNonNullableByDefault) { @@ -737,8 +733,6 @@ class _AsyncClosureContext implements ClosureContext { DartType inferReturnType(InferenceVisitorBase inferrer, {required bool hasImplicitReturn}) { assert(_needToInferReturnType); - // ignore: unnecessary_null_comparison - assert(hasImplicitReturn != null); DartType? inferredType; if (inferrer.isNonNullableByDefault) { @@ -973,8 +967,6 @@ class _SyncStarClosureContext implements ClosureContext { DartType inferReturnType(InferenceVisitorBase inferrer, {required bool hasImplicitReturn}) { assert(_needToInferReturnType); - // ignore: unnecessary_null_comparison - assert(hasImplicitReturn != null); DartType? inferredElementType; if (_yieldElementTypes!.isNotEmpty) { // Use the types seen from the explicit return statements. @@ -1109,8 +1101,6 @@ class _AsyncStarClosureContext implements ClosureContext { DartType inferReturnType(InferenceVisitorBase inferrer, {required bool hasImplicitReturn}) { assert(_needToInferReturnType); - // ignore: unnecessary_null_comparison - assert(hasImplicitReturn != null); DartType? inferredElementType; if (_yieldElementTypes!.isNotEmpty) { // Use the types seen from the explicit return statements. diff --git a/pkg/front_end/lib/src/fasta/type_inference/inference_results.dart b/pkg/front_end/lib/src/fasta/type_inference/inference_results.dart index 008e6f24945..3552ae1ad9c 100644 --- a/pkg/front_end/lib/src/fasta/type_inference/inference_results.dart +++ b/pkg/front_end/lib/src/fasta/type_inference/inference_results.dart @@ -222,9 +222,7 @@ class WrapInProblemInferenceResult implements InvocationInferenceResult { WrapInProblemInferenceResult(this.inferredType, this.functionType, this.message, this.fileOffset, this.length, this.helper, - {required this.isInapplicable, required this.hoistedArguments}) - // ignore: unnecessary_null_comparison - : assert(isInapplicable != null); + {required this.isInapplicable, required this.hoistedArguments}); @override Expression applyResult(Expression expression) { @@ -345,9 +343,7 @@ class ExpressionInferenceResult { ExpressionInferenceResult(this.inferredType, this.expression, {this.postCoercionType = null}) - // ignore: unnecessary_null_comparison - : assert(expression != null), - assert(isKnown(inferredType)); + : assert(isKnown(inferredType)); /// The guards used for null-aware access if the expression is part of a /// null-shorting. @@ -377,13 +373,7 @@ class NullAwareGuard { final InferenceVisitorBase _inferrer; NullAwareGuard( - this._nullAwareVariable, this._nullAwareFileOffset, this._inferrer) - // ignore: unnecessary_null_comparison - : assert(_nullAwareVariable != null), - // ignore: unnecessary_null_comparison - assert(_nullAwareFileOffset != null), - // ignore: unnecessary_null_comparison - assert(_inferrer != null) { + this._nullAwareVariable, this._nullAwareFileOffset, this._inferrer) { // Ensure the initializer of [_nullAwareVariable] is promoted to // non-nullable. _inferrer.flowAnalysis.nullAwareAccess_rightBegin( @@ -447,9 +437,7 @@ class NullAwareExpressionInferenceResult implements ExpressionInferenceResult { NullAwareExpressionInferenceResult(this.inferredType, this.nullAwareActionType, this.nullAwareGuards, this.nullAwareAction) - : assert(nullAwareGuards.isNotEmpty), - // ignore: unnecessary_null_comparison - assert(nullAwareAction != null); + : assert(nullAwareGuards.isNotEmpty); @override Expression get expression { diff --git a/pkg/front_end/lib/src/fasta/type_inference/inference_visitor.dart b/pkg/front_end/lib/src/fasta/type_inference/inference_visitor.dart index b34620d9bf1..360ba835109 100644 --- a/pkg/front_end/lib/src/fasta/type_inference/inference_visitor.dart +++ b/pkg/front_end/lib/src/fasta/type_inference/inference_visitor.dart @@ -246,11 +246,6 @@ class InferenceVisitorImpl extends InferenceVisitorBase {bool isVoidAllowed = false, bool forEffect = false}) { registerIfUnreachableForTesting(expression); - // `null` should never be used as the type context. An instance of - // `UnknownType` should be used instead. - // ignore: unnecessary_null_comparison - assert(typeContext != null); - ExpressionInferenceResult result; if (expression is ExpressionJudgment) { result = expression.acceptInference(this, typeContext); @@ -260,9 +255,6 @@ class InferenceVisitorImpl extends InferenceVisitorBase result = expression.accept1(this, typeContext); } DartType inferredType = result.inferredType; - // ignore: unnecessary_null_comparison - assert(inferredType != null, - "No type inferred for $expression (${expression.runtimeType})."); if (inferredType is VoidType && !isVoidAllowed) { if (expression.parent is! ArgumentsImpl) { helper.addProblem( @@ -943,15 +935,11 @@ class InferenceVisitorImpl extends InferenceVisitorBase BlockExpression _createBlockExpression( int fileOffset, Block body, Expression value) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); assert(fileOffset != TreeNode.noOffset); return new BlockExpression(body, value)..fileOffset = fileOffset; } ExpressionStatement _createExpressionStatement(Expression expression) { - // ignore: unnecessary_null_comparison - assert(expression != null); assert(expression.fileOffset != TreeNode.noOffset); return new ExpressionStatement(expression) ..fileOffset = expression.fileOffset; @@ -1019,21 +1007,16 @@ class InferenceVisitorImpl extends InferenceVisitorBase ExpressionInferenceResult visitExtensionTearOff( ExtensionTearOff node, DartType typeContext) { - // ignore: unnecessary_null_comparison - FunctionType calleeType = node.target != null - ? node.target.function.computeFunctionType(libraryBuilder.nonNullable) - : new FunctionType([], const DynamicType(), libraryBuilder.nonNullable); + FunctionType calleeType = + node.target.function.computeFunctionType(libraryBuilder.nonNullable); TypeArgumentsInfo typeArgumentsInfo = getTypeArgumentsInfo(node.arguments); InvocationInferenceResult result = inferInvocation(this, typeContext, node.fileOffset, calleeType, node.arguments as ArgumentsImpl, staticTarget: node.target); StaticInvocation replacement = new StaticInvocation(node.target, node.arguments); - // ignore: unnecessary_null_comparison - if (node.target != null) { - libraryBuilder.checkBoundsInStaticInvocation( - replacement, typeSchemaEnvironment, helper.uri, typeArgumentsInfo); - } + libraryBuilder.checkBoundsInStaticInvocation( + replacement, typeSchemaEnvironment, helper.uri, typeArgumentsInfo); return instantiateTearOff( result.inferredType, typeContext, result.applyResult(replacement)); } @@ -1550,9 +1533,6 @@ class InferenceVisitorImpl extends InferenceVisitorBase Statement? expressionEffects, {bool isAsync = false, required bool hasProblem}) { - // ignore: unnecessary_null_comparison - assert(hasProblem != null); - ForInVariable forInVariable = computeForInVariable(syntheticAssignment, hasProblem); DartType elementType = forInVariable.computeElementType(this); @@ -3545,8 +3525,6 @@ class InferenceVisitorImpl extends InferenceVisitorBase } VariableDeclaration _createVariable(Expression expression, DartType type) { - // ignore: unnecessary_null_comparison - assert(expression != null); assert(expression.fileOffset != TreeNode.noOffset); return new VariableDeclaration.forValue(expression, type: type) ..fileOffset = expression.fileOffset; @@ -3559,15 +3537,11 @@ class InferenceVisitorImpl extends InferenceVisitorBase } VariableGet _createVariableGet(VariableDeclaration variable) { - // ignore: unnecessary_null_comparison - assert(variable != null); assert(variable.fileOffset != TreeNode.noOffset); return new VariableGet(variable)..fileOffset = variable.fileOffset; } VariableGet _createNullCheckedVariableGet(VariableDeclaration variable) { - // ignore: unnecessary_null_comparison - assert(variable != null); assert(variable.fileOffset != TreeNode.noOffset); DartType promotedType = variable.type.withDeclaredNullability(libraryBuilder.nonNullable); @@ -3581,8 +3555,6 @@ class InferenceVisitorImpl extends InferenceVisitorBase MapLiteral _createMapLiteral(int fileOffset, DartType keyType, DartType valueType, List entries, {bool isConst = false}) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); assert(fileOffset != TreeNode.noOffset); return new MapLiteral(entries, keyType: keyType, valueType: valueType, isConst: isConst) @@ -3592,8 +3564,6 @@ class InferenceVisitorImpl extends InferenceVisitorBase ListLiteral _createListLiteral( int fileOffset, DartType elementType, List elements, {bool isConst = false}) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); assert(fileOffset != TreeNode.noOffset); return new ListLiteral(elements, typeArgument: elementType, isConst: isConst) @@ -3603,8 +3573,6 @@ class InferenceVisitorImpl extends InferenceVisitorBase SetLiteral _createSetLiteral( int fileOffset, DartType elementType, List elements, {bool isConst = false}) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); assert(fileOffset != TreeNode.noOffset); return new SetLiteral(elements, typeArgument: elementType, isConst: isConst) ..fileOffset = fileOffset; @@ -3613,10 +3581,6 @@ class InferenceVisitorImpl extends InferenceVisitorBase Expression _createAdd( Expression receiver, InterfaceType receiverType, Expression argument, {required bool isSet}) { - // ignore: unnecessary_null_comparison - assert(receiver != null); - // ignore: unnecessary_null_comparison - assert(argument != null); assert(argument.fileOffset != TreeNode.noOffset, "No fileOffset on ${argument}."); DartType functionType = Substitution.fromInterfaceType(receiverType) @@ -3635,10 +3599,6 @@ class InferenceVisitorImpl extends InferenceVisitorBase Expression _createAddAll(Expression receiver, InterfaceType receiverType, Expression argument, bool isSet) { - // ignore: unnecessary_null_comparison - assert(receiver != null); - // ignore: unnecessary_null_comparison - assert(argument != null); assert(argument.fileOffset != TreeNode.noOffset, "No fileOffset on ${argument}."); DartType functionType = Substitution.fromInterfaceType(receiverType) @@ -3658,10 +3618,6 @@ class InferenceVisitorImpl extends InferenceVisitorBase Expression _createMapAddAll( Expression receiver, InterfaceType receiverType, Expression argument) { - // ignore: unnecessary_null_comparison - assert(receiver != null); - // ignore: unnecessary_null_comparison - assert(argument != null); assert(argument.fileOffset != TreeNode.noOffset, "No fileOffset on ${argument}."); DartType functionType = Substitution.fromInterfaceType(receiverType) @@ -3679,8 +3635,6 @@ class InferenceVisitorImpl extends InferenceVisitorBase Expression _createEqualsNull(Expression expression, {bool notEquals = false}) { - // ignore: unnecessary_null_comparison - assert(expression != null); assert(expression.fileOffset != TreeNode.noOffset); Expression check = new EqualsNull(expression) ..fileOffset = expression.fileOffset; @@ -3692,8 +3646,6 @@ class InferenceVisitorImpl extends InferenceVisitorBase Expression _createIndexSet(int fileOffset, Expression receiver, InterfaceType receiverType, Expression key, Expression value) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); assert(fileOffset != TreeNode.noOffset); DartType functionType = Substitution.fromInterfaceType(receiverType) .substituteType(engine.mapPutFunctionType); @@ -3710,8 +3662,6 @@ class InferenceVisitorImpl extends InferenceVisitorBase AsExpression _createImplicitAs( int fileOffset, Expression expression, DartType type) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); assert(fileOffset != TreeNode.noOffset); return new AsExpression(expression, type) ..isTypeError = true @@ -3721,8 +3671,6 @@ class InferenceVisitorImpl extends InferenceVisitorBase IfStatement _createIf(int fileOffset, Expression condition, Statement then, [Statement? otherwise]) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); assert(fileOffset != TreeNode.noOffset); return new IfStatement(condition, then, otherwise)..fileOffset = fileOffset; } @@ -3730,8 +3678,6 @@ class InferenceVisitorImpl extends InferenceVisitorBase IfCaseStatement _createIfCase(int fileOffset, Expression condition, DartType matchedValueType, PatternGuard patternGuard, Statement then, [Statement? otherwise]) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); assert(fileOffset != TreeNode.noOffset); return new IfCaseStatement(condition, patternGuard, then, otherwise) ..matchedValueType = matchedValueType @@ -3740,8 +3686,6 @@ class InferenceVisitorImpl extends InferenceVisitorBase Expression _createGetKey( int fileOffset, Expression receiver, InterfaceType entryType) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); assert(fileOffset != TreeNode.noOffset); DartType resultType = Substitution.fromInterfaceType(entryType) .substituteType(engine.mapEntryKey.type); @@ -3753,8 +3697,6 @@ class InferenceVisitorImpl extends InferenceVisitorBase Expression _createGetValue( int fileOffset, Expression receiver, InterfaceType entryType) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); assert(fileOffset != TreeNode.noOffset); DartType resultType = Substitution.fromInterfaceType(entryType) .substituteType(engine.mapEntryValue.type); @@ -3766,8 +3708,6 @@ class InferenceVisitorImpl extends InferenceVisitorBase Expression _createGetEntries( int fileOffset, Expression receiver, InterfaceType mapType) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); assert(fileOffset != TreeNode.noOffset); DartType resultType = Substitution.fromInterfaceType(mapType) .substituteType(engine.mapEntries.getterType); @@ -3783,8 +3723,6 @@ class InferenceVisitorImpl extends InferenceVisitorBase Expression? condition, List updates, Statement body) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); assert(fileOffset != TreeNode.noOffset); return new ForStatement(variables, condition, updates, body) ..fileOffset = fileOffset; @@ -3793,8 +3731,6 @@ class InferenceVisitorImpl extends InferenceVisitorBase ForInStatement _createForInStatement(int fileOffset, VariableDeclaration variable, Expression iterable, Statement body, {bool isAsync = false}) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); assert(fileOffset != TreeNode.noOffset); return new ForInStatement(variable, iterable, body, isAsync: isAsync) ..fileOffset = fileOffset; @@ -3819,8 +3755,6 @@ class InferenceVisitorImpl extends InferenceVisitorBase Expression then, Expression otherwise, DartType type) { - // ignore: unnecessary_null_comparison - assert(fileOffset != null); assert(fileOffset != TreeNode.noOffset); return new ConditionalExpression(condition, then, otherwise, type) ..fileOffset = fileOffset; @@ -6023,8 +5957,6 @@ class InferenceVisitorImpl extends InferenceVisitorBase ExpressionInferenceResult _computeEqualsExpression( int fileOffset, Expression left, DartType leftType, Expression right, {required bool isNot}) { - // ignore: unnecessary_null_comparison - assert(isNot != null); ExpressionInfo? equalityInfo = flowAnalysis.equalityOperand_end(left, leftType); @@ -6693,8 +6625,6 @@ class InferenceVisitorImpl extends InferenceVisitorBase {required bool isThisReceiver, ObjectAccessTarget? readTarget, Expression? propertyGetNode}) { - // ignore: unnecessary_null_comparison - assert(isThisReceiver != null); Map Function() whyNotPromoted = flowAnalysis.whyNotPromoted(receiver); @@ -6747,8 +6677,6 @@ class InferenceVisitorImpl extends InferenceVisitorBase Expression value, {required DartType valueType, required bool forEffect}) { - // ignore: unnecessary_null_comparison - assert(forEffect != null); Expression write; DartType writeType = valueType; switch (writeTarget.kind) { @@ -8103,19 +8031,14 @@ class InferenceVisitorImpl extends InferenceVisitorBase @override ExpressionInferenceResult visitStaticInvocation( StaticInvocation node, DartType typeContext) { - // ignore: unnecessary_null_comparison - FunctionType calleeType = node.target != null - ? node.target.function.computeFunctionType(libraryBuilder.nonNullable) - : new FunctionType([], const DynamicType(), libraryBuilder.nonNullable); + FunctionType calleeType = + node.target.function.computeFunctionType(libraryBuilder.nonNullable); TypeArgumentsInfo typeArgumentsInfo = getTypeArgumentsInfo(node.arguments); InvocationInferenceResult result = inferInvocation(this, typeContext, node.fileOffset, calleeType, node.arguments as ArgumentsImpl, staticTarget: node.target); - // ignore: unnecessary_null_comparison - if (node.target != null) { - libraryBuilder.checkBoundsInStaticInvocation( - node, typeSchemaEnvironment, helper.uri, typeArgumentsInfo); - } + libraryBuilder.checkBoundsInStaticInvocation( + node, typeSchemaEnvironment, helper.uri, typeArgumentsInfo); return new ExpressionInferenceResult( result.inferredType, result.applyResult(node)); } @@ -9138,18 +9061,15 @@ class InferenceVisitorImpl extends InferenceVisitorBase receiver.literal.length); return new ExpressionInferenceResult(const DynamicType(), error); } - // ignore: unnecessary_null_comparison - if (intValue != null) { - Expression? error = checkWebIntLiteralsErrorIfUnexact( - intValue, receiver.literal, receiver.fileOffset); - if (error != null) { - return new ExpressionInferenceResult(const DynamicType(), error); - } - expressionResult = new ExpressionInferenceResult( - coreTypes.intRawType(libraryBuilder.nonNullable), - new IntLiteral(-intValue) - ..fileOffset = node.expression.fileOffset); + Expression? error = checkWebIntLiteralsErrorIfUnexact( + intValue, receiver.literal, receiver.fileOffset); + if (error != null) { + return new ExpressionInferenceResult(const DynamicType(), error); } + expressionResult = new ExpressionInferenceResult( + coreTypes.intRawType(libraryBuilder.nonNullable), + new IntLiteral(-intValue) + ..fileOffset = node.expression.fileOffset); } } } diff --git a/pkg/front_end/lib/src/fasta/type_inference/inference_visitor_base.dart b/pkg/front_end/lib/src/fasta/type_inference/inference_visitor_base.dart index d00caff94c2..fd2c88ea10f 100644 --- a/pkg/front_end/lib/src/fasta/type_inference/inference_visitor_base.dart +++ b/pkg/front_end/lib/src/fasta/type_inference/inference_visitor_base.dart @@ -237,23 +237,13 @@ abstract class InferenceVisitorBase implements InferenceVisitor { Expression createReachabilityError( int fileOffset, Message errorMessage, Message warningMessage) { - if (libraryBuilder.loader.target.context.options.warnOnReachabilityCheck && - // ignore: unnecessary_null_comparison - warningMessage != null) { + if (libraryBuilder.loader.target.context.options.warnOnReachabilityCheck) { helper.addProblem(warningMessage, fileOffset, noLength); } - Arguments arguments; - // ignore: unnecessary_null_comparison - if (errorMessage != null) { - arguments = new Arguments([ - new StringLiteral(errorMessage.problemMessage)..fileOffset = fileOffset - ]) - ..fileOffset = fileOffset; - } else { - arguments = new Arguments([])..fileOffset = fileOffset; - } - // ignore: unnecessary_null_comparison - assert(coreTypes.reachabilityErrorConstructor != null); + Arguments arguments = new Arguments([ + new StringLiteral(errorMessage.problemMessage)..fileOffset = fileOffset + ]) + ..fileOffset = fileOffset; return new Throw( new ConstructorInvocation( coreTypes.reachabilityErrorConstructor, arguments) @@ -461,9 +451,6 @@ abstract class InferenceVisitorBase implements InferenceVisitor { DartType? runtimeCheckedType, bool isVoidAllowed = false, bool coerceExpression = true}) { - // ignore: unnecessary_null_comparison - assert(contextType != null); - fileOffset ??= inferenceResult.expression.fileOffset; contextType = computeGreatestClosure(contextType); @@ -554,9 +541,6 @@ abstract class InferenceVisitorBase implements InferenceVisitor { Template? nullabilityPartErrorTemplate, Map Function()? whyNotPromoted}) { - // ignore: unnecessary_null_comparison - assert(contextType != null); - // [errorTemplate], [nullabilityErrorTemplate], and // [nullabilityPartErrorTemplate] should be provided together. assert((errorTemplate == null) == (nullabilityErrorTemplate == null) && @@ -723,9 +707,6 @@ abstract class InferenceVisitorBase implements InferenceVisitor { Template? nullabilityPartErrorTemplate, Map Function()? whyNotPromoted}) { - // ignore: unnecessary_null_comparison - assert(contextType != null); - if (coerceExpression) { ExpressionInferenceResult? coercionResult = coerceExpressionForAssignment( contextType, inferenceResult, @@ -757,8 +738,6 @@ abstract class InferenceVisitorBase implements InferenceVisitor { Expression _wrapTearoffErrorExpression(Expression expression, DartType contextType, Template template) { - // ignore: unnecessary_null_comparison - assert(template != null); Expression errorNode = new AsExpression( expression, // TODO(ahe): The outline phase doesn't correctly remove invalid @@ -842,13 +821,6 @@ abstract class InferenceVisitorBase implements InferenceVisitor { required bool isVoidAllowed, required bool isExpressionTypePrecise, required bool coerceExpression}) { - // ignore: unnecessary_null_comparison - assert(isNonNullableByDefault != null); - // ignore: unnecessary_null_comparison - assert(isVoidAllowed != null); - // ignore: unnecessary_null_comparison - assert(isExpressionTypePrecise != null); - // If an interface type is being assigned to a function type, see if we // should tear off `.call`. // TODO(paulberry): use resolveTypeParameter. See findInterfaceMember. @@ -1315,8 +1287,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { {required CallSiteAccessKind callSiteAccessKind, bool instrumented = true, bool includeExtensionMethods = false}) { - // ignore: unnecessary_null_comparison - assert(receiverType != null && isKnown(receiverType)); + assert(isKnown(receiverType)); bool isSetter = callSiteAccessKind == CallSiteAccessKind.setterInvocation; @@ -1415,10 +1386,8 @@ abstract class InferenceVisitorBase implements InferenceVisitor { Name name, int fileOffset, Template errorTemplate) { - // ignore: unnecessary_null_comparison - assert(receiverType != null && isKnown(receiverType)); - // ignore: unnecessary_null_comparison - if (target.isMissing && errorTemplate != null) { + assert(isKnown(receiverType)); + if (target.isMissing) { int length = name.text.length; if (identical(name.text, callName.text) || identical(name.text, unaryMinusName.text)) { @@ -1806,8 +1775,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { TypeConstraintGatherer? gatherer; if (inferenceNeeded) { - // ignore: unnecessary_null_comparison - if (isConst && typeContext != null) { + if (isConst) { typeContext = new TypeVariableEliminator( bottomType, isNonNullableByDefault @@ -2450,8 +2418,6 @@ abstract class InferenceVisitorBase implements InferenceVisitor { DartType typeContext, List? hoistedExpressions, {required bool isImplicitCall}) { - // ignore: unnecessary_null_comparison - assert(isImplicitCall != null); InvocationInferenceResult result = inferInvocation( visitor, typeContext, fileOffset, unknownFunction, arguments, hoistedExpressions: hoistedExpressions, @@ -2476,8 +2442,6 @@ abstract class InferenceVisitorBase implements InferenceVisitor { DartType typeContext, List? hoistedExpressions, {required bool isImplicitCall}) { - // ignore: unnecessary_null_comparison - assert(isImplicitCall != null); InvocationInferenceResult result = inferInvocation( visitor, typeContext, fileOffset, unknownFunction, arguments, hoistedExpressions: hoistedExpressions, @@ -2508,10 +2472,6 @@ abstract class InferenceVisitorBase implements InferenceVisitor { required bool isImplicitCall, Name? implicitInvocationPropertyName}) { assert(target.isMissing || target.isAmbiguous); - // ignore: unnecessary_null_comparison - assert(isExpressionInvocation != null); - // ignore: unnecessary_null_comparison - assert(isImplicitCall != null); Expression error = createMissingMethodInvocation( fileOffset, receiverType, name, receiver: receiver, @@ -2544,8 +2504,6 @@ abstract class InferenceVisitorBase implements InferenceVisitor { DartType typeContext, List? hoistedExpressions, {required bool isImplicitCall}) { - // ignore: unnecessary_null_comparison - assert(isImplicitCall != null); assert(target.isExtensionMember || target.isNullableExtensionMember || target.isInlineClassMember || @@ -2659,8 +2617,6 @@ abstract class InferenceVisitorBase implements InferenceVisitor { DartType typeContext, List? hoistedExpressions, {required bool isImplicitCall}) { - // ignore: unnecessary_null_comparison - assert(isImplicitCall != null); assert(target.isCallFunction || target.isNullableCallFunction); FunctionType declaredFunctionType = target.getFunctionType(this); InvocationInferenceResult result = inferInvocation( @@ -2765,12 +2721,6 @@ abstract class InferenceVisitorBase implements InferenceVisitor { {required bool isImplicitCall, required bool isSpecialCasedBinaryOperator, required bool isSpecialCasedTernaryOperator}) { - // ignore: unnecessary_null_comparison - assert(isImplicitCall != null); - // ignore: unnecessary_null_comparison - assert(isSpecialCasedBinaryOperator != null); - // ignore: unnecessary_null_comparison - assert(isSpecialCasedTernaryOperator != null); assert(target.isInstanceMember || target.isObjectMember || target.isNullableInstanceMember); @@ -2932,8 +2882,6 @@ abstract class InferenceVisitorBase implements InferenceVisitor { DartType typeContext, List? hoistedExpressions, {required bool isExpressionInvocation}) { - // ignore: unnecessary_null_comparison - assert(isExpressionInvocation != null); assert(target.isInstanceMember || target.isObjectMember || target.isNullableInstanceMember); @@ -3134,8 +3082,6 @@ abstract class InferenceVisitorBase implements InferenceVisitor { DartType typeContext, List? hoistedExpressions, {required bool isExpressionInvocation}) { - // ignore: unnecessary_null_comparison - assert(isExpressionInvocation != null); assert(target.isInstanceMember || target.isObjectMember || target.isNullableInstanceMember); @@ -3310,11 +3256,6 @@ abstract class InferenceVisitorBase implements InferenceVisitor { Name? implicitInvocationPropertyName, List? hoistedExpressions, ObjectAccessTarget? target}) { - // ignore: unnecessary_null_comparison - assert(isExpressionInvocation != null); - // ignore: unnecessary_null_comparison - assert(isImplicitCall != null); - target ??= findInterfaceMember(receiverType, name, fileOffset, instrumented: true, includeExtensionMethods: true, @@ -3593,8 +3534,6 @@ abstract class InferenceVisitorBase implements InferenceVisitor { void checkBoundsInInstantiation( FunctionType functionType, List arguments, int fileOffset, {required bool inferred}) { - // ignore: unnecessary_null_comparison - assert(inferred != null); // If [arguments] were inferred, check them. libraryBuilder.checkBoundsInInstantiation( @@ -3805,8 +3744,6 @@ abstract class InferenceVisitorBase implements InferenceVisitor { MethodContravarianceCheckKind preCheckInvocationContravariance( DartType receiverType, ObjectAccessTarget target, {required bool isThisReceiver}) { - // ignore: unnecessary_null_comparison - assert(isThisReceiver != null); if (target.isInstanceMember || target.isObjectMember) { Member interfaceMember = target.member!; if (interfaceMember is Field || @@ -3888,10 +3825,6 @@ abstract class InferenceVisitorBase implements InferenceVisitor { } // TODO(paulberry): If [type] is a subtype of `Future`, should we just // return it unmodified? - // ignore: unnecessary_null_comparison - if (type == null) { - return coreTypes.futureRawType(libraryBuilder.nullable); - } return new FutureOrType(type, libraryBuilder.nonNullable); } @@ -4117,8 +4050,6 @@ abstract class InferenceVisitorBase implements InferenceVisitor { required bool isExpressionInvocation, Name? implicitInvocationPropertyName, List? extensionAccessCandidates}) { - // ignore: unnecessary_null_comparison - assert(isExpressionInvocation != null); assert((receiver == null) == (arguments == null), "Receiver and arguments must be supplied together."); if (implicitInvocationPropertyName != null) { @@ -4369,8 +4300,6 @@ abstract class InferenceVisitorBase implements InferenceVisitor { DartType receiverType, Name propertyName, Expression value, {required bool forEffect, List? extensionAccessCandidates}) { - // ignore: unnecessary_null_comparison - assert(forEffect != null); Template templateMissing; if (receiverType is ExtensionType) { templateMissing = templateUndefinedExtensionSetter; @@ -4413,8 +4342,6 @@ abstract class InferenceVisitorBase implements InferenceVisitor { DartType receiverType, Expression index, Expression value, {required bool forEffect, List? extensionAccessCandidates}) { - // ignore: unnecessary_null_comparison - assert(forEffect != null); Template templateMissing; if (receiverType is ExtensionType) { templateMissing = templateUndefinedExtensionOperator; diff --git a/pkg/front_end/lib/src/fasta/type_inference/object_access_target.dart b/pkg/front_end/lib/src/fasta/type_inference/object_access_target.dart index 141831d8a98..6844faf94a1 100644 --- a/pkg/front_end/lib/src/fasta/type_inference/object_access_target.dart +++ b/pkg/front_end/lib/src/fasta/type_inference/object_access_target.dart @@ -102,10 +102,6 @@ abstract class ObjectAccessTarget { factory ObjectAccessTarget.interfaceMember( DartType receiverType, Member member, {required bool isPotentiallyNullable}) { - // ignore: unnecessary_null_comparison - assert(member != null); - // ignore: unnecessary_null_comparison - assert(isPotentiallyNullable != null); return isPotentiallyNullable ? new InstanceAccessTarget.nullable(receiverType, member) : new InstanceAccessTarget.nonNullable(receiverType, member); @@ -980,9 +976,7 @@ class ExtensionAccessCandidate { ExtensionAccessCandidate(this.memberBuilder, this.onType, this.onTypeInstantiateToBounds, this.target, - {required this.isPlatform}) - // ignore: unnecessary_null_comparison - : assert(isPlatform != null); + {required this.isPlatform}); bool? isMoreSpecificThan(TypeSchemaEnvironment typeSchemaEnvironment, ExtensionAccessCandidate other) { diff --git a/pkg/front_end/lib/src/fasta/type_inference/type_constraint_gatherer.dart b/pkg/front_end/lib/src/fasta/type_inference/type_constraint_gatherer.dart index ccb9dd9e360..840f0acfe15 100644 --- a/pkg/front_end/lib/src/fasta/type_inference/type_constraint_gatherer.dart +++ b/pkg/front_end/lib/src/fasta/type_inference/type_constraint_gatherer.dart @@ -151,8 +151,6 @@ abstract class TypeConstraintGatherer { /// type schema. bool _tryNullabilityAwareSubtypeMatch(DartType subtype, DartType supertype, {required bool constrainSupertype}) { - // ignore: unnecessary_null_comparison - assert(constrainSupertype != null); int baseConstraintCount = _protoConstraints.length; bool isMatch = _isNullabilityAwareSubtypeMatch(subtype, supertype, constrainSupertype: constrainSupertype); @@ -327,13 +325,6 @@ abstract class TypeConstraintGatherer { /// [UnknownType], that is, to be a type schema. bool _isNullabilityAwareSubtypeMatch(DartType p, DartType q, {required bool constrainSupertype}) { - // ignore: unnecessary_null_comparison - assert(p != null); - // ignore: unnecessary_null_comparison - assert(q != null); - // ignore: unnecessary_null_comparison - assert(constrainSupertype != null); - // If the type parameters being constrained occur in the supertype (that is, // [q]), the subtype (that is, [p]) is not allowed to contain them. To // check that, the assert below uses the equivalence of the following: X -> @@ -1066,18 +1057,15 @@ abstract class TypeConstraintGatherer { Member? callMember = getInterfaceMember(subtype.classNode, callName); if (callMember is Procedure && !callMember.isGetter) { DartType callType = callMember.getterType; - // ignore: unnecessary_null_comparison - if (callType != null) { - callType = - Substitution.fromInterfaceType(subtype).substituteType(callType); - // TODO(kmillikin): The subtype check will fail if the type of a - // generic call method is a subtype of a non-generic function type. - // For example, if `T call(T arg)` is a subtype of `S->S` for some - // S. However, explicitly tearing off that call method will work and - // insert an explicit instantiation, so the implicit tear off should - // work as well. Figure out how to support this case. - return _isNullabilityObliviousSubtypeMatch(callType, supertype); - } + callType = + Substitution.fromInterfaceType(subtype).substituteType(callType); + // TODO(kmillikin): The subtype check will fail if the type of a + // generic call method is a subtype of a non-generic function type. + // For example, if `T call(T arg)` is a subtype of `S->S` for some + // S. However, explicitly tearing off that call method will work and + // insert an explicit instantiation, so the implicit tear off should + // work as well. Figure out how to support this case. + return _isNullabilityObliviousSubtypeMatch(callType, supertype); } } return false; diff --git a/pkg/front_end/lib/src/fasta/type_inference/type_demotion.dart b/pkg/front_end/lib/src/fasta/type_inference/type_demotion.dart index 3c6f0ba6289..e2e0472ead7 100644 --- a/pkg/front_end/lib/src/fasta/type_inference/type_demotion.dart +++ b/pkg/front_end/lib/src/fasta/type_inference/type_demotion.dart @@ -104,11 +104,7 @@ class _DemotionNullabilityNormalization extends ReplacementVisitor { const _DemotionNullabilityNormalization( {required this.demoteTypeVariables, - required this.forNonNullableByDefault}) - // ignore: unnecessary_null_comparison - : assert(demoteTypeVariables != null), - // ignore: unnecessary_null_comparison - assert(forNonNullableByDefault != null); + required this.forNonNullableByDefault}); @override Nullability? visitNullability(DartType node) { diff --git a/pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart b/pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart index a984932f4fd..5d520a4994e 100644 --- a/pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart +++ b/pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart @@ -142,9 +142,7 @@ class TypeInferrerImpl implements TypeInferrer { this.dataForTesting, FunctionType unknownFunctionNonNullable, FunctionType unknownFunctionLegacy) - // ignore: unnecessary_null_comparison - : assert(libraryBuilder != null), - unknownFunction = libraryBuilder.isNonNullableByDefault + : unknownFunction = libraryBuilder.isNonNullableByDefault ? unknownFunctionNonNullable : unknownFunctionLegacy, instrumentation = isTopLevel ? null : engine.instrumentation, @@ -193,8 +191,6 @@ class TypeInferrerImpl implements TypeInferrer { @override InferredFunctionBody inferFunctionBody(InferenceHelper helper, int fileOffset, DartType returnType, AsyncMarker asyncMarker, Statement body) { - // ignore: unnecessary_null_comparison - assert(body != null); InferenceVisitorBase visitor = _createInferenceVisitor(helper); ClosureContext closureContext = new ClosureContext(visitor, asyncMarker, returnType, false); @@ -292,8 +288,6 @@ class TypeInferrerImpl implements TypeInferrer { Expression initializer, DartType declaredType, bool hasDeclaredInitializer) { - // ignore: unnecessary_null_comparison - assert(declaredType != null); InferenceVisitorBase visitor = _createInferenceVisitor(helper); ExpressionInferenceResult result = visitor.inferExpression(initializer, declaredType); diff --git a/pkg/front_end/lib/src/fasta/type_inference/type_schema_environment.dart b/pkg/front_end/lib/src/fasta/type_inference/type_schema_environment.dart index 928976286d6..a075686a067 100644 --- a/pkg/front_end/lib/src/fasta/type_inference/type_schema_environment.dart +++ b/pkg/front_end/lib/src/fasta/type_inference/type_schema_environment.dart @@ -370,8 +370,6 @@ class TypeSchemaEnvironment extends HierarchyBasedTypeEnvironment bool isSpecialCasesBinaryForReceiverType( Procedure member, DartType receiverType, {required bool isNonNullableByDefault}) { - // ignore: unnecessary_null_comparison - assert(isNonNullableByDefault != null); if (!isNonNullableByDefault) { // TODO(paulberry): this matches what is defined in the spec. It would be // nice if we could change kernel to match the spec and not have to diff --git a/pkg/front_end/lib/src/fasta/uri_translator.dart b/pkg/front_end/lib/src/fasta/uri_translator.dart index e4df37bf839..48e866e40a7 100644 --- a/pkg/front_end/lib/src/fasta/uri_translator.dart +++ b/pkg/front_end/lib/src/fasta/uri_translator.dart @@ -40,8 +40,6 @@ class UriTranslator { /// For a package uri, get the corresponding [Package]. Package? getPackage(Uri uri) { - // ignore: unnecessary_null_comparison - if (packages == null) return null; if (!uri.isScheme("package")) return null; int firstSlash = uri.path.indexOf('/'); if (firstSlash == -1) return null; diff --git a/pkg/front_end/lib/src/fasta/util/parser_ast.dart b/pkg/front_end/lib/src/fasta/util/parser_ast.dart index 63b71e1b022..f0712bb56d4 100644 --- a/pkg/front_end/lib/src/fasta/util/parser_ast.dart +++ b/pkg/front_end/lib/src/fasta/util/parser_ast.dart @@ -55,11 +55,6 @@ CompilationUnitEnd getAST(List rawBytes, }, ); Token firstToken = scanner.tokenize(); - // ignore: unnecessary_null_comparison - if (firstToken == null) { - throw "firstToken is null"; - } - ParserASTListener listener = new ParserASTListener(); Parser parser; if (includeBody) { diff --git a/pkg/front_end/lib/src/fasta/util/textual_outline.dart b/pkg/front_end/lib/src/fasta/util/textual_outline.dart index de83f42c662..b7c8036ed28 100644 --- a/pkg/front_end/lib/src/fasta/util/textual_outline.dart +++ b/pkg/front_end/lib/src/fasta/util/textual_outline.dart @@ -450,12 +450,6 @@ String? textualOutline( ..originalPosition = originalPosition.value++); }); Token firstToken = scanner.tokenize(); - // ignore: unnecessary_null_comparison - if (firstToken == null) { - if (throwOnUnexpected) throw "firstToken is null"; - return null; - } - TextualOutlineListener listener = new TextualOutlineListener(); ClassMemberParser classMemberParser = new ClassMemberParser(listener); classMemberParser.parseUnit(firstToken); @@ -866,8 +860,7 @@ class TextualOutlineListener extends Listener { @override void endImport(Token importKeyword, Token? augmentToken, Token? semicolon) { - // ignore: unnecessary_null_comparison - if (importKeyword != null && semicolon != null) { + if (semicolon != null) { importExportsStartToChunk[importKeyword] = new _ImportChunk( importKeyword, semicolon, firstShowOrHide, _combinators); } diff --git a/pkg/front_end/lib/src/testing/id_extractor.dart b/pkg/front_end/lib/src/testing/id_extractor.dart index 0e1bc8ee7ab..9c52b7e17c9 100644 --- a/pkg/front_end/lib/src/testing/id_extractor.dart +++ b/pkg/front_end/lib/src/testing/id_extractor.dart @@ -83,8 +83,6 @@ abstract class DataExtractor extends Visitor void computeForMember(Member member) { MemberId id = computeMemberId(member); - // ignore: unnecessary_null_comparison - if (id == null) return; T? value = computeMemberValue(id, member); registerValue(member.fileUri, member.fileOffset, id, value, member); } diff --git a/pkg/front_end/lib/src/testing/id_testing_helper.dart b/pkg/front_end/lib/src/testing/id_testing_helper.dart index 00afda9ac8c..42ead6501d6 100644 --- a/pkg/front_end/lib/src/testing/id_testing_helper.dart +++ b/pkg/front_end/lib/src/testing/id_testing_helper.dart @@ -413,8 +413,7 @@ Future> runTestForConfig(MarkerOptions markerOptions, errorMap.forEach((Uri uri, Map> map) { map.forEach((int offset, List list) { - // ignore: unnecessary_null_comparison - if (offset == null || offset < 0) { + if (offset < 0) { // Position errors without offset in the begin of the file. offset = 0; } @@ -578,8 +577,7 @@ void printMessageInLocation( if (source == null) { print('$uri@$offset: $message'); } else { - // ignore: unnecessary_null_comparison - if (offset != null && offset >= 1) { + if (offset >= 1) { Location location = source.getLocation(uri, offset); print('$location: $message'); if (!succinct) { diff --git a/pkg/front_end/lib/widget_cache.dart b/pkg/front_end/lib/widget_cache.dart index 752b96995a9..258f0ebe98d 100644 --- a/pkg/front_end/lib/widget_cache.dart +++ b/pkg/front_end/lib/widget_cache.dart @@ -80,11 +80,7 @@ class WidgetCache { List oldSource = lastGoodComponent.uriToSource[library.fileUri]!.source; List newSource = partialComponent.uriToSource[library.fileUri]!.source; - // Library was added and does not exist in the old component. - // ignore: unnecessary_null_comparison - if (oldSource == null) { - return null; - } + int newStartIndex = 0; int newEndIndex = newSource.length - 1; int oldStartIndex = 0; diff --git a/pkg/front_end/test/crashing_test_case_minimizer_impl.dart b/pkg/front_end/test/crashing_test_case_minimizer_impl.dart index 5bba43537f4..e088d805ee2 100644 --- a/pkg/front_end/test/crashing_test_case_minimizer_impl.dart +++ b/pkg/front_end/test/crashing_test_case_minimizer_impl.dart @@ -1106,12 +1106,6 @@ worlds: _isUriNnbd(uri) ? _scannerConfiguration : _scannerConfigurationNonNNBD, lineStarts); - // ignore: unnecessary_null_comparison - if (firstToken == null) { - print("Got null token from scanner for $uri"); - return; - } - int compileTry = 0; Token? token = firstToken; while (token is ErrorToken) { @@ -1897,8 +1891,6 @@ worlds: } } - // ignore: unnecessary_null_comparison - if (foundLine == null) throw "Unexpected crash without stacktrace: $e"; if (_expectedCrashLine == null) { print("Got '$foundLine'"); _expectedCrashLine = foundLine; @@ -2016,11 +2008,6 @@ worlds: nnbd ? _scannerConfiguration : _scannerConfigurationNonNNBD, lineStarts); - // ignore: unnecessary_null_comparison - if (firstToken == null) { - throw "Got null token from scanner"; - } - ParserTestListener parserTestListener = new ParserTestListener(false); Parser parser = new Parser(parserTestListener, useImplicitCreationExpression: useImplicitCreationExpressionInCfe); @@ -2034,11 +2021,6 @@ worlds: Token firstToken = parser_suite.scanRawBytes(rawBytes, nnbd ? _scannerConfiguration : _scannerConfigurationNonNNBD, null); - // ignore: unnecessary_null_comparison - if (firstToken == null) { - return false; - } - ParserErrorListener parserErrorListener = new ParserErrorListener(); Parser parser = new Parser(parserErrorListener, useImplicitCreationExpression: useImplicitCreationExpressionInCfe); diff --git a/pkg/front_end/test/fasta/testing/suite.dart b/pkg/front_end/test/fasta/testing/suite.dart index c226d969ffc..a00c492b4aa 100644 --- a/pkg/front_end/test/fasta/testing/suite.dart +++ b/pkg/front_end/test/fasta/testing/suite.dart @@ -278,16 +278,10 @@ class FolderOptions { // can be null this.overwriteCurrentSdkVersion, this.showOffsets = false}) - // ignore: unnecessary_null_comparison - : assert(nnbdAgnosticMode != null), - assert( + : assert( // no this doesn't make any sense but left to underline // that this is allowed to be null! - defines != null || defines == null), - // ignore: unnecessary_null_comparison - assert(noVerify != null), - // ignore: unnecessary_null_comparison - assert(target != null); + defines != null || defines == null); Map computeExplicitExperimentalFlags( Map forcedExperimentalFlags) { @@ -315,9 +309,7 @@ class TestOptions { {required this.nnbdMode, required this.allowedExperimentalFlags, required this.experimentEnabledVersion, - required this.experimentReleasedVersion}) - // ignore: unnecessary_null_comparison - : assert(linkDependencies != null); + required this.experimentReleasedVersion}); } class FastaContext extends ChainContext with MatchContext { @@ -2335,10 +2327,7 @@ class Outline extends Step { backendTarget.performModularTransformations = true; } try { - // ignore: unnecessary_null_comparison - if (sourceTarget.loader.coreTypes != null) { - sourceTarget.runBuildTransformations(); - } + sourceTarget.runBuildTransformations(); } finally { if (backendTarget is TestTarget) { backendTarget.performModularTransformations = false; @@ -2463,10 +2452,7 @@ class Transform extends Step { backendTarget.performModularTransformations = true; } try { - // ignore: unnecessary_null_comparison - if (sourceTarget.loader.coreTypes != null) { - sourceTarget.runBuildTransformations(); - } + sourceTarget.runBuildTransformations(); } finally { if (backendTarget is TestTarget) { backendTarget.performModularTransformations = false; diff --git a/pkg/front_end/test/incremental_suite.dart b/pkg/front_end/test/incremental_suite.dart index bdf1eea77d7..dc33e6b30c1 100644 --- a/pkg/front_end/test/incremental_suite.dart +++ b/pkg/front_end/test/incremental_suite.dart @@ -1475,8 +1475,7 @@ class NewWorldTest { for (Uri uri in component!.uriToSource.keys) { // null is always there, so allow it implicitly. // Dart scheme uris too. - // ignore: unnecessary_null_comparison - if (uri == null || uri.isScheme("org-dartlang-sdk")) continue; + if (uri.isScheme("org-dartlang-sdk")) continue; if (!allowed.contains(uri)) { return new Result( data, diff --git a/pkg/front_end/test/incremental_utils.dart b/pkg/front_end/test/incremental_utils.dart index 7ad424cd1b2..28df52da565 100644 --- a/pkg/front_end/test/incremental_utils.dart +++ b/pkg/front_end/test/incremental_utils.dart @@ -78,8 +78,6 @@ Future throwOnInsufficientUriToSource(Component component, if (fileSystem != null) { uris = uriFinder.seenUris.toSet(); for (Uri uri in uris) { - // ignore: unnecessary_null_comparison - if (uri == null) continue; if (!uri.isScheme("org-dartlang-test")) continue; // The file system doesn't have the sources for any modules. // For now assume that that is always what's going on. diff --git a/pkg/front_end/test/parser_suite.dart b/pkg/front_end/test/parser_suite.dart index d3c5f4f8700..84fdd734959 100644 --- a/pkg/front_end/test/parser_suite.dart +++ b/pkg/front_end/test/parser_suite.dart @@ -197,11 +197,6 @@ class ListenerStep extends Step { List lineStarts = []; Token firstToken = scanUri(uri, shortName, lineStarts: lineStarts); - // ignore: unnecessary_null_comparison - if (firstToken == null) { - return null; - } - File f = new File.fromUri(uri); List rawBytes = f.readAsBytesSync(); Source source = new Source(lineStarts, rawBytes, uri, uri); @@ -261,11 +256,6 @@ class IntertwinedStep extends Step { Token firstToken = scanUri(description.uri, description.shortName, lineStarts: lineStarts); - // ignore: unnecessary_null_comparison - if (firstToken == null) { - return Future.value(crash(description, StackTrace.current)); - } - File f = new File.fromUri(description.uri); List rawBytes = f.readAsBytesSync(); Source source = @@ -301,11 +291,6 @@ class TokenStep extends Step { Token firstToken = scanUri(description.uri, description.shortName, lineStarts: lineStarts); - // ignore: unnecessary_null_comparison - if (firstToken == null) { - return Future.value(crash(description, StackTrace.current)); - } - StringBuffer beforeParser = tokenStreamToString(firstToken, lineStarts); StringBuffer beforeParserWithTypes = tokenStreamToString(firstToken, lineStarts, addTypes: true); diff --git a/pkg/front_end/test/utils/kernel_chain.dart b/pkg/front_end/test/utils/kernel_chain.dart index 174103d5874..871318ce64b 100644 --- a/pkg/front_end/test/utils/kernel_chain.dart +++ b/pkg/front_end/test/utils/kernel_chain.dart @@ -210,9 +210,7 @@ class MatchExpectation /// be serialized, deserialized, and the textual representation of that is /// compared. It is still the original component that is returned though. const MatchExpectation(this.suffix, - {this.serializeFirst = false, required this.isLastMatchStep}) - // ignore: unnecessary_null_comparison - : assert(isLastMatchStep != null); + {this.serializeFirst = false, required this.isLastMatchStep}); @override String get name => "match expectations"; diff --git a/pkg/front_end/tool/_fasta/entry_points.dart b/pkg/front_end/tool/_fasta/entry_points.dart index 85c19838432..84caca0c415 100644 --- a/pkg/front_end/tool/_fasta/entry_points.dart +++ b/pkg/front_end/tool/_fasta/entry_points.dart @@ -5,7 +5,7 @@ library fasta.tool.entry_points; import 'dart:convert' show JsonEncoder, LineSplitter, jsonDecode, utf8; -import 'dart:io' show File, Platform, exitCode, stderr, stdin, stdout; +import 'dart:io' show File, Platform, stderr, stdin, stdout; import 'dart:typed_data' show Uint8List; import 'package:_fe_analyzer_shared/src/util/relativize.dart' @@ -508,13 +508,6 @@ Future compilePlatformInternal(CompilerContext c, Uri fullOutput, CompilerResult result = await generateKernelInternal(buildSummary: true, buildComponent: true); - // ignore: unnecessary_null_comparison - if (result == null) { - exitCode = 1; - // Note: an error should have been reported by now. - print('The platform .dill files were not created.'); - return; - } new File.fromUri(outlineOutput).writeAsBytesSync(result.summary!); c.options.ticker.logMs("Wrote outline to ${outlineOutput.toFilePath()}"); diff --git a/pkg/front_end/tool/_fasta/generate_messages.dart b/pkg/front_end/tool/_fasta/generate_messages.dart index f75d37ed846..bc0f10b1c5e 100644 --- a/pkg/front_end/tool/_fasta/generate_messages.dart +++ b/pkg/front_end/tool/_fasta/generate_messages.dart @@ -175,7 +175,6 @@ Template compileTemplate(String name, int? index, String? problemMessage, // `|` (verbatim) as they always contain a trailing newline that we don't // want. problemMessage = problemMessage.trimRight(); - const String ignoreNotNull = "// ignore: unnecessary_null_comparison"; var parameters = new Set(); var conversions = new Set(); var conversions2 = new Set(); @@ -261,8 +260,7 @@ Template compileTemplate(String name, int? index, String? problemMessage, case "nameOKEmpty": parameters.add("String nameOKEmpty"); - conversions.add("$ignoreNotNull\n" - "if (nameOKEmpty == null || nameOKEmpty.isEmpty) " + conversions.add("if (nameOKEmpty.isEmpty) " "nameOKEmpty = '(unnamed)';"); arguments.add("'nameOKEmpty': nameOKEmpty"); break; @@ -306,8 +304,7 @@ Template compileTemplate(String name, int? index, String? problemMessage, case "stringOKEmpty": parameters.add("String stringOKEmpty"); - conversions.add("$ignoreNotNull\n" - "if (stringOKEmpty == null || stringOKEmpty.isEmpty) " + conversions.add("if (stringOKEmpty.isEmpty) " "stringOKEmpty = '(empty)';"); arguments.add("'$name': stringOKEmpty"); break; @@ -344,15 +341,11 @@ Template compileTemplate(String name, int? index, String? problemMessage, case "count": parameters.add("int count"); - conversions.add( - "$ignoreNotNull\n" "if (count == null) throw 'No count provided';"); arguments.add("'$name': count"); break; case "count2": parameters.add("int count2"); - conversions.add("$ignoreNotNull\n" - "if (count2 == null) throw 'No count provided';"); arguments.add("'$name': count2"); break; @@ -367,24 +360,18 @@ Template compileTemplate(String name, int? index, String? problemMessage, case "num1": parameters.add("num _num1"); - conversions.add("$ignoreNotNull\n" - "if (_num1 == null) throw 'No number provided';"); conversions.add("String num1 = ${format('_num1')};"); arguments.add("'$name': _num1"); break; case "num2": parameters.add("num _num2"); - conversions.add("$ignoreNotNull\n" - "if (_num2 == null) throw 'No number provided';"); conversions.add("String num2 = ${format('_num2')};"); arguments.add("'$name': _num2"); break; case "num3": parameters.add("num _num3"); - conversions.add("$ignoreNotNull\n" - "if (_num3 == null) throw 'No number provided';"); conversions.add("String num3 = ${format('_num3')};"); arguments.add("'$name': _num3"); break; @@ -428,10 +415,7 @@ Template compileTemplate(String name, int? index, String? problemMessage, } if (parameters.isEmpty && conversions.isEmpty && arguments.isEmpty) { - // ignore: unnecessary_null_comparison - if (problemMessage != null) { - codeArguments.add('problemMessage: r"""$problemMessage"""'); - } + codeArguments.add('problemMessage: r"""$problemMessage"""'); if (correctionMessage != null) { codeArguments.add('correctionMessage: r"""$correctionMessage"""'); } @@ -447,10 +431,7 @@ const MessageCode message$name = } List templateArguments = []; - // ignore: unnecessary_null_comparison - if (problemMessage != null) { - templateArguments.add('problemMessageTemplate: r"""$problemMessage"""'); - } + templateArguments.add('problemMessageTemplate: r"""$problemMessage"""'); if (correctionMessage != null) { templateArguments .add('correctionMessageTemplate: r"""$correctionMessage"""'); diff --git a/pkg/front_end/tool/fasta_perf.dart b/pkg/front_end/tool/fasta_perf.dart index 2b0c14472c6..1629df34adc 100644 --- a/pkg/front_end/tool/fasta_perf.dart +++ b/pkg/front_end/tool/fasta_perf.dart @@ -155,8 +155,6 @@ Map> scanReachableFiles(Uri entryUri) { void collectSources(Uri start, Map> files) { void helper(Uri uri) { uri = uriResolver.translate(uri) ?? uri; - // ignore: unnecessary_null_comparison - if (uri == null) return; if (files.containsKey(uri)) return; var contents = readBytesFromFileSync(uri); files[uri] = contents; diff --git a/pkg/front_end/tool/kernel_ast_file_rewriter.dart b/pkg/front_end/tool/kernel_ast_file_rewriter.dart index 313f714a12d..95f806030f2 100644 --- a/pkg/front_end/tool/kernel_ast_file_rewriter.dart +++ b/pkg/front_end/tool/kernel_ast_file_rewriter.dart @@ -188,10 +188,6 @@ void processField( Token beginToken = classFields.beginToken; Token endToken = classFields.endToken; - // ignore: unnecessary_null_comparison - assert(beginToken != null); - // ignore: unnecessary_null_comparison - assert(endToken != null); String frozenCheckCode = """if (frozen) throw "Trying to modify frozen node!";"""; diff --git a/pkg/frontend_server/lib/frontend_server.dart b/pkg/frontend_server/lib/frontend_server.dart index 0726deb9d8b..7fd2c6d5808 100644 --- a/pkg/frontend_server/lib/frontend_server.dart +++ b/pkg/frontend_server/lib/frontend_server.dart @@ -736,8 +736,6 @@ class FrontendCompiler implements CompilerInterface { Future writeJavaScriptBundle(KernelCompilationResults results, String filename, String fileSystemScheme, String moduleFormat, {required bool fullComponent}) async { - // ignore: unnecessary_null_comparison - assert(fullComponent != null); var packageConfig = await loadPackageConfigUri( _compilerOptions.packagesFileUri ?? File('.dart_tool/package_config.json').absolute.uri); diff --git a/pkg/kernel/lib/ast.dart b/pkg/kernel/lib/ast.dart index 1a70e0ba267..9b6e78ec5bc 100644 --- a/pkg/kernel/lib/ast.dart +++ b/pkg/kernel/lib/ast.dart @@ -172,8 +172,6 @@ abstract class TreeNode extends Node { /// /// [replacement] must be non-null. void replaceChild(TreeNode child, TreeNode replacement) { - // ignore: unnecessary_null_comparison - assert(replacement != null); transformChildren(new _ChildReplacer(child, replacement)); } @@ -185,8 +183,6 @@ abstract class TreeNode extends Node { /// /// [replacement] must be non-null. void replaceWith(TreeNode replacement) { - // ignore: unnecessary_null_comparison - assert(replacement != null); parent!.replaceChild(this, replacement); parent = null; } @@ -268,10 +264,6 @@ class Library extends NamedNode Version get languageVersion => _languageVersion ?? defaultLanguageVersion; void setLanguageVersion(Version languageVersion) { - // ignore: unnecessary_null_comparison - if (languageVersion == null) { - throw new StateError("Trying to set language version 'null'"); - } _languageVersion = languageVersion; } @@ -377,9 +369,7 @@ class Library extends NamedNode List? fields, required this.fileUri, Reference? reference}) - // ignore: unnecessary_null_comparison - : assert(fileUri != null), - this.annotations = annotations ?? [], + : this.annotations = annotations ?? [], this.dependencies = dependencies ?? [], this.parts = parts ?? [], this._typedefs = typedefs ?? [], @@ -872,9 +862,7 @@ class Typedef extends NamedNode implements FileUriNode, Annotatable { List? typeParametersOfFunctionType, List? positionalParameters, List? namedParameters}) - // ignore: unnecessary_null_comparison - : assert(fileUri != null), - this.typeParameters = typeParameters ?? [], + : this.typeParameters = typeParameters ?? [], super(reference) { setParents(this.typeParameters, this); } @@ -1307,11 +1295,7 @@ class Class extends NamedNode implements Annotatable, FileUriNode { List? redirectingFactoryConstructors, required this.fileUri, Reference? reference}) - // ignore: unnecessary_null_comparison - : assert(name != null), - // ignore: unnecessary_null_comparison - assert(fileUri != null), - this.typeParameters = typeParameters ?? [], + : this.typeParameters = typeParameters ?? [], this.implementedTypes = implementedTypes ?? [], this._fieldsInternal = fields ?? [], this._constructorsInternal = constructors ?? [], @@ -1637,11 +1621,7 @@ class Extension extends NamedNode implements Annotatable, FileUriNode { List? members, required this.fileUri, Reference? reference}) - // ignore: unnecessary_null_comparison - : assert(name != null), - // ignore: unnecessary_null_comparison - assert(fileUri != null), - this.typeParameters = typeParameters ?? [], + : this.typeParameters = typeParameters ?? [], this.members = members ?? [], super(reference) { setParents(this.typeParameters, this); @@ -1700,10 +1680,7 @@ class Extension extends NamedNode implements Annotatable, FileUriNode { void transformChildren(Transformer v) { v.transformList(annotations, this); v.transformList(typeParameters, this); - // ignore: unnecessary_null_comparison - if (onType != null) { - onType = v.visitDartType(onType); - } + onType = v.visitDartType(onType); if (showHideClause != null) { v.transformSupertypeList(showHideClause!.shownSupertypes); v.transformSupertypeList(showHideClause!.hiddenSupertypes); @@ -1714,10 +1691,7 @@ class Extension extends NamedNode implements Annotatable, FileUriNode { void transformOrRemoveChildren(RemovingTransformer v) { v.transformExpressionList(annotations, this); v.transformTypeParameterList(typeParameters, this); - // ignore: unnecessary_null_comparison - if (onType != null) { - onType = v.visitDartType(onType, cannotRemoveSentinel); - } + onType = v.visitDartType(onType, cannotRemoveSentinel); if (showHideClause != null) { v.transformSupertypeList(showHideClause!.shownSupertypes); v.transformSupertypeList(showHideClause!.hiddenSupertypes); @@ -2055,11 +2029,7 @@ class InlineClass extends NamedNode implements Annotatable, FileUriNode { List? implements, required this.fileUri, Reference? reference}) - // ignore: unnecessary_null_comparison - : assert(name != null), - // ignore: unnecessary_null_comparison - assert(fileUri != null), - this.typeParameters = typeParameters ?? [], + : this.typeParameters = typeParameters ?? [], this.members = members ?? [], this.implements = implements ?? [], super(reference) { @@ -2095,21 +2065,15 @@ class InlineClass extends NamedNode implements Annotatable, FileUriNode { void transformChildren(Transformer v) { v.transformList(annotations, this); v.transformList(typeParameters, this); - // ignore: unnecessary_null_comparison - if (declaredRepresentationType != null) { - declaredRepresentationType = v.visitDartType(declaredRepresentationType); - } + declaredRepresentationType = v.visitDartType(declaredRepresentationType); } @override void transformOrRemoveChildren(RemovingTransformer v) { v.transformExpressionList(annotations, this); v.transformTypeParameterList(typeParameters, this); - // ignore: unnecessary_null_comparison - if (declaredRepresentationType != null) { - declaredRepresentationType = - v.visitDartType(declaredRepresentationType, cannotRemoveSentinel); - } + declaredRepresentationType = + v.visitDartType(declaredRepresentationType, cannotRemoveSentinel); } @override @@ -2243,12 +2207,7 @@ abstract class Member extends NamedNode implements Annotatable, FileUriNode { // TODO(asgerf): It might be worthwhile to put this on classes as well. int transformerFlags = 0; - Member(this.name, this.fileUri, Reference? reference) - // ignore: unnecessary_null_comparison - : assert(name != null), - // ignore: unnecessary_null_comparison - assert(fileUri != null), - super(reference); + Member(this.name, this.fileUri, Reference? reference) : super(reference); Class? get enclosingClass => parent is Class ? parent as Class : null; Library get enclosingLibrary => @@ -2485,8 +2444,6 @@ class Field extends Member { super(name, fileUri, fieldReference) { this.getterReference.node = this; this.setterReference!.node = this; - // ignore: unnecessary_null_comparison - assert(type != null); initializer?.parent = this; this.isCovariantByDeclaration = isCovariantByDeclaration; this.isFinal = isFinal; @@ -2512,8 +2469,6 @@ class Field extends Member { this.setterReference = null, super(name, fileUri, fieldReference) { this.getterReference.node = this; - // ignore: unnecessary_null_comparison - assert(type != null); initializer?.parent = this; this.isCovariantByDeclaration = isCovariantByDeclaration; this.isFinal = isFinal; @@ -2763,8 +2718,6 @@ class Constructor extends Member { required Uri fileUri, Reference? reference}) : this.initializers = initializers ?? [], - // ignore: unnecessary_null_comparison - assert(function != null), super(name, fileUri, reference) { function.parent = this; setParents(this.initializers, this); @@ -2858,22 +2811,16 @@ class Constructor extends Member { void transformChildren(Transformer v) { v.transformList(annotations, this); v.transformList(initializers, this); - // ignore: unnecessary_null_comparison - if (function != null) { - function = v.transform(function); - function.parent = this; - } + function = v.transform(function); + function.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { v.transformExpressionList(annotations, this); v.transformInitializerList(initializers, this); - // ignore: unnecessary_null_comparison - if (function != null) { - function = v.transform(function); - function.parent = this; - } + function = v.transform(function); + function.parent = this; } // TODO(johnniwinther): Provide the tear off type here. @@ -3345,11 +3292,7 @@ class Procedure extends Member { Reference? reference, this.stubKind = ProcedureStubKind.Regular, this.stubTargetReference}) - // ignore: unnecessary_null_comparison - : assert(kind != null), - // ignore: unnecessary_null_comparison - assert(function != null), - super(name, fileUri, reference) { + : super(name, fileUri, reference) { function.parent = this; this.isAbstract = isAbstract; this.isStatic = isStatic; @@ -3606,11 +3549,8 @@ class Procedure extends Member { @override void transformChildren(Transformer v) { v.transformList(annotations, this); - // ignore: unnecessary_null_comparison - if (function != null) { - function = v.transform(function); - function.parent = this; - } + function = v.transform(function); + function.parent = this; if (signatureType != null) { signatureType = v.visitDartType(signatureType!) as FunctionType; } @@ -3619,11 +3559,8 @@ class Procedure extends Member { @override void transformOrRemoveChildren(RemovingTransformer v) { v.transformExpressionList(annotations, this); - // ignore: unnecessary_null_comparison - if (function != null) { - function = v.transform(function); - function.parent = this; - } + function = v.transform(function); + function.parent = this; if (signatureType != null) { DartType newSignatureType = v.visitDartType(signatureType!, dummyDartType); @@ -3771,20 +3708,14 @@ class FieldInitializer extends Initializer { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (value != null) { - value = v.transform(value); - value.parent = this; - } + value = v.transform(value); + value.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (value != null) { - value = v.transform(value); - value.parent = this; - } + value = v.transform(value); + value.parent = this; } @override @@ -3844,20 +3775,14 @@ class SuperInitializer extends Initializer { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (arguments != null) { - arguments = v.transform(arguments); - arguments.parent = this; - } + arguments = v.transform(arguments); + arguments.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (arguments != null) { - arguments = v.transform(arguments); - arguments.parent = this; - } + arguments = v.transform(arguments); + arguments.parent = this; } @override @@ -3918,20 +3843,14 @@ class RedirectingInitializer extends Initializer { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (arguments != null) { - arguments = v.transform(arguments); - arguments.parent = this; - } + arguments = v.transform(arguments); + arguments.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (arguments != null) { - arguments = v.transform(arguments); - arguments.parent = this; - } + arguments = v.transform(arguments); + arguments.parent = this; } @override @@ -3975,20 +3894,14 @@ class LocalInitializer extends Initializer { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (variable != null) { - variable = v.transform(variable); - variable.parent = this; - } + variable = v.transform(variable); + variable.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (variable != null) { - variable = v.transform(variable); - variable.parent = this; - } + variable = v.transform(variable); + variable.parent = this; } @override @@ -4138,8 +4051,6 @@ class FunctionNode extends TreeNode { this.namedParameters = namedParameters ?? [], this.typeParameters = typeParameters ?? [], this.dartAsyncMarker = dartAsyncMarker ?? asyncMarker { - // ignore: unnecessary_null_comparison - assert(returnType != null); setParents(this.typeParameters, this); setParents(this.positionalParameters, this); setParents(this.namedParameters, this); @@ -4507,9 +4418,7 @@ class VariableGet extends Expression { VariableDeclaration variable; DartType? promotedType; // Null if not promoted. - VariableGet(this.variable, [this.promotedType]) - // ignore: unnecessary_null_comparison - : assert(variable != null); + VariableGet(this.variable, [this.promotedType]); @override DartType getStaticType(StaticTypeContext context) => @@ -4574,9 +4483,7 @@ class VariableSet extends Expression { VariableDeclaration variable; Expression value; - VariableSet(this.variable, this.value) - // ignore: unnecessary_null_comparison - : assert(variable != null) { + VariableSet(this.variable, this.value) { value.parent = this; } @@ -4602,20 +4509,14 @@ class VariableSet extends Expression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (value != null) { - value = v.transform(value); - value.parent = this; - } + value = v.transform(value); + value.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (value != null) { - value = v.transform(value); - value.parent = this; - } + value = v.transform(value); + value.parent = this; } @override @@ -4818,20 +4719,14 @@ class DynamicGet extends Expression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (receiver != null) { - receiver = v.transform(receiver); - receiver.parent = this; - } + receiver = v.transform(receiver); + receiver.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (receiver != null) { - receiver = v.transform(receiver); - receiver.parent = this; - } + receiver = v.transform(receiver); + receiver.parent = this; } @override @@ -4882,11 +4777,7 @@ class InstanceGet extends Expression { resultType: resultType); InstanceGet.byReference(this.kind, this.receiver, this.name, - {required this.interfaceTargetReference, required this.resultType}) - // ignore: unnecessary_null_comparison - : assert(interfaceTargetReference != null), - // ignore: unnecessary_null_comparison - assert(resultType != null) { + {required this.interfaceTargetReference, required this.resultType}) { receiver.parent = this; } @@ -4916,28 +4807,16 @@ class InstanceGet extends Expression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (receiver != null) { - receiver = v.transform(receiver); - receiver.parent = this; - } - // ignore: unnecessary_null_comparison - if (resultType != null) { - resultType = v.visitDartType(resultType); - } + receiver = v.transform(receiver); + receiver.parent = this; + resultType = v.visitDartType(resultType); } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (receiver != null) { - receiver = v.transform(receiver); - receiver.parent = this; - } - // ignore: unnecessary_null_comparison - if (resultType != null) { - resultType = v.visitDartType(resultType, cannotRemoveSentinel); - } + receiver = v.transform(receiver); + receiver.parent = this; + resultType = v.visitDartType(resultType, cannotRemoveSentinel); } @override @@ -4981,20 +4860,14 @@ class FunctionTearOff extends Expression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (receiver != null) { - receiver = v.transform(receiver); - receiver.parent = this; - } + receiver = v.transform(receiver); + receiver.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (receiver != null) { - receiver = v.transform(receiver); - receiver.parent = this; - } + receiver = v.transform(receiver); + receiver.parent = this; } @override @@ -5074,28 +4947,16 @@ class InstanceTearOff extends Expression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (receiver != null) { - receiver = v.transform(receiver); - receiver.parent = this; - } - // ignore: unnecessary_null_comparison - if (resultType != null) { - resultType = v.visitDartType(resultType); - } + receiver = v.transform(receiver); + receiver.parent = this; + resultType = v.visitDartType(resultType); } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (receiver != null) { - receiver = v.transform(receiver); - receiver.parent = this; - } - // ignore: unnecessary_null_comparison - if (resultType != null) { - resultType = v.visitDartType(resultType, cannotRemoveSentinel); - } + receiver = v.transform(receiver); + receiver.parent = this; + resultType = v.visitDartType(resultType, cannotRemoveSentinel); } @override @@ -5143,30 +5004,18 @@ class DynamicSet extends Expression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (receiver != null) { - receiver = v.transform(receiver); - receiver.parent = this; - } - // ignore: unnecessary_null_comparison - if (value != null) { - value = v.transform(value); - value.parent = this; - } + receiver = v.transform(receiver); + receiver.parent = this; + value = v.transform(value); + value.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (receiver != null) { - receiver = v.transform(receiver); - receiver.parent = this; - } - // ignore: unnecessary_null_comparison - if (value != null) { - value = v.transform(value); - value.parent = this; - } + receiver = v.transform(receiver); + receiver.parent = this; + value = v.transform(value); + value.parent = this; } @override @@ -5205,9 +5054,7 @@ class InstanceSet extends Expression { getNonNullableMemberReferenceSetter(interfaceTarget)); InstanceSet.byReference(this.kind, this.receiver, this.name, this.value, - {required this.interfaceTargetReference}) - // ignore: unnecessary_null_comparison - : assert(interfaceTargetReference != null) { + {required this.interfaceTargetReference}) { receiver.parent = this; value.parent = this; } @@ -5239,30 +5086,18 @@ class InstanceSet extends Expression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (receiver != null) { - receiver = v.transform(receiver); - receiver.parent = this; - } - // ignore: unnecessary_null_comparison - if (value != null) { - value = v.transform(value); - value.parent = this; - } + receiver = v.transform(receiver); + receiver.parent = this; + value = v.transform(value); + value.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (receiver != null) { - receiver = v.transform(receiver); - receiver.parent = this; - } - // ignore: unnecessary_null_comparison - if (value != null) { - value = v.transform(value); - value.parent = this; - } + receiver = v.transform(receiver); + receiver.parent = this; + value = v.transform(value); + value.parent = this; } @override @@ -5500,20 +5335,14 @@ class AbstractSuperPropertySet extends Expression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (value != null) { - value = v.transform(value); - value.parent = this; - } + value = v.transform(value); + value.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (value != null) { - value = v.transform(value); - value.parent = this; - } + value = v.transform(value); + value.parent = this; } @override @@ -5576,20 +5405,14 @@ class SuperPropertySet extends Expression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (value != null) { - value = v.transform(value); - value.parent = this; - } + value = v.transform(value); + value.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (value != null) { - value = v.transform(value); - value.parent = this; - } + value = v.transform(value); + value.parent = this; } @override @@ -5747,20 +5570,14 @@ class StaticSet extends Expression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (value != null) { - value = v.transform(value); - value.parent = this; - } + value = v.transform(value); + value.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (value != null) { - value = v.transform(value); - value.parent = this; - } + value = v.transform(value); + value.parent = this; } @override @@ -5900,20 +5717,14 @@ class NamedExpression extends TreeNode { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (value != null) { - value = v.transform(value); - value.parent = this; - } + value = v.transform(value); + value.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (value != null) { - value = v.transform(value); - value.parent = this; - } + value = v.transform(value); + value.parent = this; } @override @@ -5996,30 +5807,18 @@ class DynamicInvocation extends InstanceInvocationExpression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (receiver != null) { - receiver = v.transform(receiver); - receiver.parent = this; - } - // ignore: unnecessary_null_comparison - if (arguments != null) { - arguments = v.transform(arguments); - arguments.parent = this; - } + receiver = v.transform(receiver); + receiver.parent = this; + arguments = v.transform(arguments); + arguments.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (receiver != null) { - receiver = v.transform(receiver); - receiver.parent = this; - } - // ignore: unnecessary_null_comparison - if (arguments != null) { - arguments = v.transform(arguments); - arguments.parent = this; - } + receiver = v.transform(receiver); + receiver.parent = this; + arguments = v.transform(arguments); + arguments.parent = this; } @override @@ -6139,11 +5938,7 @@ class InstanceInvocation extends InstanceInvocationExpression { InstanceInvocation.byReference( this.kind, this.receiver, this.name, this.arguments, {required this.interfaceTargetReference, required this.functionType}) - // ignore: unnecessary_null_comparison - : assert(interfaceTargetReference != null), - // ignore: unnecessary_null_comparison - assert(functionType != null), - assert(functionType.typeParameters.isEmpty) { + : assert(functionType.typeParameters.isEmpty) { receiver.parent = this; arguments.parent = this; } @@ -6211,39 +6006,21 @@ class InstanceInvocation extends InstanceInvocationExpression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (receiver != null) { - receiver = v.transform(receiver); - receiver.parent = this; - } - // ignore: unnecessary_null_comparison - if (arguments != null) { - arguments = v.transform(arguments); - arguments.parent = this; - } - // ignore: unnecessary_null_comparison - if (functionType != null) { - functionType = v.visitDartType(functionType) as FunctionType; - } + receiver = v.transform(receiver); + receiver.parent = this; + arguments = v.transform(arguments); + arguments.parent = this; + functionType = v.visitDartType(functionType) as FunctionType; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (receiver != null) { - receiver = v.transform(receiver); - receiver.parent = this; - } - // ignore: unnecessary_null_comparison - if (arguments != null) { - arguments = v.transform(arguments); - arguments.parent = this; - } - // ignore: unnecessary_null_comparison - if (functionType != null) { - functionType = - v.visitDartType(functionType, cannotRemoveSentinel) as FunctionType; - } + receiver = v.transform(receiver); + receiver.parent = this; + arguments = v.transform(arguments); + arguments.parent = this; + functionType = + v.visitDartType(functionType, cannotRemoveSentinel) as FunctionType; } @override @@ -6315,9 +6092,7 @@ class InstanceGetterInvocation extends InstanceInvocationExpression { InstanceGetterInvocation.byReference( this.kind, this.receiver, this.name, this.arguments, {required this.interfaceTargetReference, required this.functionType}) - // ignore: unnecessary_null_comparison - : assert(interfaceTargetReference != null), - assert(functionType == null || functionType.typeParameters.isEmpty) { + : assert(functionType == null || functionType.typeParameters.isEmpty) { receiver.parent = this; arguments.parent = this; } @@ -6385,16 +6160,11 @@ class InstanceGetterInvocation extends InstanceInvocationExpression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (receiver != null) { - receiver = v.transform(receiver); - receiver.parent = this; - } - // ignore: unnecessary_null_comparison - if (arguments != null) { - arguments = v.transform(arguments); - arguments.parent = this; - } + receiver = v.transform(receiver); + receiver.parent = this; + arguments = v.transform(arguments); + arguments.parent = this; + if (functionType != null) { functionType = v.visitDartType(functionType!) as FunctionType; } @@ -6402,16 +6172,10 @@ class InstanceGetterInvocation extends InstanceInvocationExpression { @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (receiver != null) { - receiver = v.transform(receiver); - receiver.parent = this; - } - // ignore: unnecessary_null_comparison - if (arguments != null) { - arguments = v.transform(arguments); - arguments.parent = this; - } + receiver = v.transform(receiver); + receiver.parent = this; + arguments = v.transform(arguments); + arguments.parent = this; if (functionType != null) { functionType = v.visitDartType(functionType!, cannotRemoveSentinel) as FunctionType; @@ -6536,16 +6300,10 @@ class FunctionInvocation extends InstanceInvocationExpression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (receiver != null) { - receiver = v.transform(receiver); - receiver.parent = this; - } - // ignore: unnecessary_null_comparison - if (arguments != null) { - arguments = v.transform(arguments); - arguments.parent = this; - } + receiver = v.transform(receiver); + receiver.parent = this; + arguments = v.transform(arguments); + arguments.parent = this; FunctionType? type = functionType; if (type != null) { functionType = v.visitDartType(type) as FunctionType; @@ -6554,16 +6312,10 @@ class FunctionInvocation extends InstanceInvocationExpression { @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (receiver != null) { - receiver = v.transform(receiver); - receiver.parent = this; - } - // ignore: unnecessary_null_comparison - if (arguments != null) { - arguments = v.transform(arguments); - arguments.parent = this; - } + receiver = v.transform(receiver); + receiver.parent = this; + arguments = v.transform(arguments); + arguments.parent = this; FunctionType? type = functionType; if (type != null) { functionType = @@ -6607,9 +6359,7 @@ class LocalFunctionInvocation extends InvocationExpression { FunctionType functionType; LocalFunctionInvocation(this.variable, this.arguments, - {required this.functionType}) - // ignore: unnecessary_null_comparison - : assert(functionType != null) { + {required this.functionType}) { arguments.parent = this; } @@ -6639,29 +6389,17 @@ class LocalFunctionInvocation extends InvocationExpression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (arguments != null) { - arguments = v.transform(arguments); - arguments.parent = this; - } - // ignore: unnecessary_null_comparison - if (functionType != null) { - functionType = v.visitDartType(functionType) as FunctionType; - } + arguments = v.transform(arguments); + arguments.parent = this; + functionType = v.visitDartType(functionType) as FunctionType; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (arguments != null) { - arguments = v.transform(arguments); - arguments.parent = this; - } - // ignore: unnecessary_null_comparison - if (functionType != null) { - functionType = - v.visitDartType(functionType, cannotRemoveSentinel) as FunctionType; - } + arguments = v.transform(arguments); + arguments.parent = this; + functionType = + v.visitDartType(functionType, cannotRemoveSentinel) as FunctionType; } @override @@ -6705,20 +6443,14 @@ class EqualsNull extends Expression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (expression != null) { - expression = v.transform(expression); - expression.parent = this; - } + expression = v.transform(expression); + expression.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (expression != null) { - expression = v.transform(expression); - expression.parent = this; - } + expression = v.transform(expression); + expression.parent = this; } @override @@ -6799,39 +6531,21 @@ class EqualsCall extends Expression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (left != null) { - left = v.transform(left); - left.parent = this; - } - // ignore: unnecessary_null_comparison - if (right != null) { - right = v.transform(right); - right.parent = this; - } - // ignore: unnecessary_null_comparison - if (functionType != null) { - functionType = v.visitDartType(functionType) as FunctionType; - } + left = v.transform(left); + left.parent = this; + right = v.transform(right); + right.parent = this; + functionType = v.visitDartType(functionType) as FunctionType; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (left != null) { - left = v.transform(left); - left.parent = this; - } - // ignore: unnecessary_null_comparison - if (right != null) { - right = v.transform(right); - right.parent = this; - } - // ignore: unnecessary_null_comparison - if (functionType != null) { - functionType = - v.visitDartType(functionType, cannotRemoveSentinel) as FunctionType; - } + left = v.transform(left); + left.parent = this; + right = v.transform(right); + right.parent = this; + functionType = + v.visitDartType(functionType, cannotRemoveSentinel) as FunctionType; } @override @@ -6932,20 +6646,14 @@ class AbstractSuperMethodInvocation extends InvocationExpression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (arguments != null) { - arguments = v.transform(arguments); - arguments.parent = this; - } + arguments = v.transform(arguments); + arguments.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (arguments != null) { - arguments = v.transform(arguments); - arguments.parent = this; - } + arguments = v.transform(arguments); + arguments.parent = this; } @override @@ -7022,20 +6730,14 @@ class SuperMethodInvocation extends InvocationExpression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (arguments != null) { - arguments = v.transform(arguments); - arguments.parent = this; - } + arguments = v.transform(arguments); + arguments.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (arguments != null) { - arguments = v.transform(arguments); - arguments.parent = this; - } + arguments = v.transform(arguments); + arguments.parent = this; } @override @@ -7109,20 +6811,14 @@ class StaticInvocation extends InvocationExpression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (arguments != null) { - arguments = v.transform(arguments); - arguments.parent = this; - } + arguments = v.transform(arguments); + arguments.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (arguments != null) { - arguments = v.transform(arguments); - arguments.parent = this; - } + arguments = v.transform(arguments); + arguments.parent = this; } @override @@ -7199,20 +6895,14 @@ class ConstructorInvocation extends InvocationExpression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (arguments != null) { - arguments = v.transform(arguments); - arguments.parent = this; - } + arguments = v.transform(arguments); + arguments.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (arguments != null) { - arguments = v.transform(arguments); - arguments.parent = this; - } + arguments = v.transform(arguments); + arguments.parent = this; } // TODO(cstefantsova): Change the getter into a method that accepts a @@ -7286,21 +6976,17 @@ class Instantiation extends Expression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (expression != null) { - expression = v.transform(expression); - expression.parent = this; - } + expression = v.transform(expression); + expression.parent = this; + v.transformDartTypeList(typeArguments); } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (expression != null) { - expression = v.transform(expression); - expression.parent = this; - } + expression = v.transform(expression); + expression.parent = this; + v.transformDartTypeList(typeArguments); } @@ -7348,20 +7034,14 @@ class Not extends Expression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (operand != null) { - operand = v.transform(operand); - operand.parent = this; - } + operand = v.transform(operand); + operand.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (operand != null) { - operand = v.transform(operand); - operand.parent = this; - } + operand = v.transform(operand); + operand.parent = this; } @override @@ -7422,30 +7102,18 @@ class LogicalExpression extends Expression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (left != null) { - left = v.transform(left); - left.parent = this; - } - // ignore: unnecessary_null_comparison - if (right != null) { - right = v.transform(right); - right.parent = this; - } + left = v.transform(left); + left.parent = this; + right = v.transform(right); + right.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (left != null) { - left = v.transform(left); - left.parent = this; - } - // ignore: unnecessary_null_comparison - if (right != null) { - right = v.transform(right); - right.parent = this; - } + left = v.transform(left); + left.parent = this; + right = v.transform(right); + right.parent = this; } @override @@ -7502,48 +7170,24 @@ class ConditionalExpression extends Expression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (condition != null) { - condition = v.transform(condition); - condition.parent = this; - } - // ignore: unnecessary_null_comparison - if (then != null) { - then = v.transform(then); - then.parent = this; - } - // ignore: unnecessary_null_comparison - if (otherwise != null) { - otherwise = v.transform(otherwise); - otherwise.parent = this; - } - // ignore: unnecessary_null_comparison - if (staticType != null) { - staticType = v.visitDartType(staticType); - } + condition = v.transform(condition); + condition.parent = this; + then = v.transform(then); + then.parent = this; + otherwise = v.transform(otherwise); + otherwise.parent = this; + staticType = v.visitDartType(staticType); } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (condition != null) { - condition = v.transform(condition); - condition.parent = this; - } - // ignore: unnecessary_null_comparison - if (then != null) { - then = v.transform(then); - then.parent = this; - } - // ignore: unnecessary_null_comparison - if (otherwise != null) { - otherwise = v.transform(otherwise); - otherwise.parent = this; - } - // ignore: unnecessary_null_comparison - if (staticType != null) { - staticType = v.visitDartType(staticType, cannotRemoveSentinel); - } + condition = v.transform(condition); + condition.parent = this; + then = v.transform(then); + then.parent = this; + otherwise = v.transform(otherwise); + otherwise.parent = this; + staticType = v.visitDartType(staticType, cannotRemoveSentinel); } @override @@ -7556,12 +7200,9 @@ class ConditionalExpression extends Expression { printer.writeExpression(condition, minimumPrecedence: astToText.Precedence.LOGICAL_OR); printer.write(' ?'); - // ignore: unnecessary_null_comparison - if (staticType != null) { - printer.write('{'); - printer.writeType(staticType); - printer.write('}'); - } + printer.write('{'); + printer.writeType(staticType); + printer.write('}'); printer.write(' '); printer.writeExpression(then); printer.write(' : '); @@ -7907,8 +7548,7 @@ class InstanceCreation extends Expression { void transformChildren(Transformer v) { fieldValues.forEach((Reference fieldRef, Expression value) { Expression transformed = v.transform(value); - // ignore: unnecessary_null_comparison - if (transformed != null && !identical(value, transformed)) { + if (!identical(value, transformed)) { fieldValues[fieldRef] = transformed; transformed.parent = this; } @@ -8092,21 +7732,15 @@ class IsExpression extends Expression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (operand != null) { - operand = v.transform(operand); - operand.parent = this; - } + operand = v.transform(operand); + operand.parent = this; type = v.visitDartType(type); } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (operand != null) { - operand = v.transform(operand); - operand.parent = this; - } + operand = v.transform(operand); + operand.parent = this; type = v.visitDartType(type, cannotRemoveSentinel); } @@ -8235,21 +7869,15 @@ class AsExpression extends Expression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (operand != null) { - operand = v.transform(operand); - operand.parent = this; - } + operand = v.transform(operand); + operand.parent = this; type = v.visitDartType(type); } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (operand != null) { - operand = v.transform(operand); - operand.parent = this; - } + operand = v.transform(operand); + operand.parent = this; type = v.visitDartType(type, cannotRemoveSentinel); } @@ -8319,20 +7947,14 @@ class NullCheck extends Expression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (operand != null) { - operand = v.transform(operand); - operand.parent = this; - } + operand = v.transform(operand); + operand.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (operand != null) { - operand = v.transform(operand); - operand.parent = this; - } + operand = v.transform(operand); + operand.parent = this; } @override @@ -8716,20 +8338,14 @@ class Throw extends Expression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (expression != null) { - expression = v.transform(expression); - expression.parent = this; - } + expression = v.transform(expression); + expression.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (expression != null) { - expression = v.transform(expression); - expression.parent = this; - } + expression = v.transform(expression); + expression.parent = this; } @override @@ -8751,8 +8367,6 @@ class ListLiteral extends Expression { ListLiteral(this.expressions, {this.typeArgument = const DynamicType(), this.isConst = false}) { - // ignore: unnecessary_null_comparison - assert(typeArgument != null); setParents(expressions, this); } @@ -8815,8 +8429,6 @@ class SetLiteral extends Expression { SetLiteral(this.expressions, {this.typeArgument = const DynamicType(), this.isConst = false}) { - // ignore: unnecessary_null_comparison - assert(typeArgument != null); setParents(expressions, this); } @@ -8882,10 +8494,6 @@ class MapLiteral extends Expression { {this.keyType = const DynamicType(), this.valueType = const DynamicType(), this.isConst = false}) { - // ignore: unnecessary_null_comparison - assert(keyType != null); - // ignore: unnecessary_null_comparison - assert(valueType != null); setParents(entries, this); } @@ -8976,30 +8584,18 @@ class MapLiteralEntry extends TreeNode { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (key != null) { - key = v.transform(key); - key.parent = this; - } - // ignore: unnecessary_null_comparison - if (value != null) { - value = v.transform(value); - value.parent = this; - } + key = v.transform(key); + key.parent = this; + value = v.transform(value); + value.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (key != null) { - key = v.transform(key); - key.parent = this; - } - // ignore: unnecessary_null_comparison - if (value != null) { - value = v.transform(value); - value.parent = this; - } + key = v.transform(key); + key.parent = this; + value = v.transform(value); + value.parent = this; } @override @@ -9176,11 +8772,8 @@ class AwaitExpression extends Expression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (operand != null) { - operand = v.transform(operand); - operand.parent = this; - } + operand = v.transform(operand); + operand.parent = this; if (runtimeCheckType != null) { runtimeCheckType = v.visitDartType(runtimeCheckType!); } @@ -9188,11 +8781,8 @@ class AwaitExpression extends Expression { @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (operand != null) { - operand = v.transform(operand); - operand.parent = this; - } + operand = v.transform(operand); + operand.parent = this; if (runtimeCheckType != null) { runtimeCheckType = v.visitDartType(runtimeCheckType!, null); } @@ -9245,20 +8835,14 @@ class FunctionExpression extends Expression implements LocalFunction { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (function != null) { - function = v.transform(function); - function.parent = this; - } + function = v.transform(function); + function.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (function != null) { - function = v.transform(function); - function.parent = this; - } + function = v.transform(function); + function.parent = this; } @override @@ -9276,10 +8860,7 @@ class ConstantExpression extends Expression { Constant constant; DartType type; - ConstantExpression(this.constant, [this.type = const DynamicType()]) { - // ignore: unnecessary_null_comparison - assert(constant != null); - } + ConstantExpression(this.constant, [this.type = const DynamicType()]); @override DartType getStaticType(StaticTypeContext context) => @@ -9356,30 +8937,18 @@ class Let extends Expression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (variable != null) { - variable = v.transform(variable); - variable.parent = this; - } - // ignore: unnecessary_null_comparison - if (body != null) { - body = v.transform(body); - body.parent = this; - } + variable = v.transform(variable); + variable.parent = this; + body = v.transform(body); + body.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (variable != null) { - variable = v.transform(variable); - variable.parent = this; - } - // ignore: unnecessary_null_comparison - if (body != null) { - body = v.transform(body); - body.parent = this; - } + variable = v.transform(variable); + variable.parent = this; + body = v.transform(body); + body.parent = this; } @override @@ -9428,30 +8997,18 @@ class BlockExpression extends Expression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (body != null) { - body = v.transform(body); - body.parent = this; - } - // ignore: unnecessary_null_comparison - if (value != null) { - value = v.transform(value); - value.parent = this; - } + body = v.transform(body); + body.parent = this; + value = v.transform(value); + value.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (body != null) { - body = v.transform(body); - body.parent = this; - } - // ignore: unnecessary_null_comparison - if (value != null) { - value = v.transform(value); - value.parent = this; - } + body = v.transform(body); + body.parent = this; + value = v.transform(value); + value.parent = this; } @override @@ -9719,22 +9276,16 @@ class TypedefTearOff extends Expression { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (expression != null) { - expression = v.transform(expression); - expression.parent = this; - } + expression = v.transform(expression); + expression.parent = this; v.transformList(typeParameters, this); v.transformDartTypeList(typeArguments); } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (expression != null) { - expression = v.transform(expression); - expression.parent = this; - } + expression = v.transform(expression); + expression.parent = this; v.transformList(typeParameters, this, dummyTypeParameter); v.transformDartTypeList(typeArguments); } @@ -9794,20 +9345,14 @@ class ExpressionStatement extends Statement { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (expression != null) { - expression = v.transform(expression); - expression.parent = this; - } + expression = v.transform(expression); + expression.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (expression != null) { - expression = v.transform(expression); - expression.parent = this; - } + expression = v.transform(expression); + expression.parent = this; } @override @@ -9991,11 +9536,8 @@ class AssertStatement extends Statement { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (condition != null) { - condition = v.transform(condition); - condition.parent = this; - } + condition = v.transform(condition); + condition.parent = this; if (message != null) { message = v.transform(message!); message?.parent = this; @@ -10004,11 +9546,8 @@ class AssertStatement extends Statement { @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (condition != null) { - condition = v.transform(condition); - condition.parent = this; - } + condition = v.transform(condition); + condition.parent = this; if (message != null) { message = v.transformOrRemoveExpression(message!); message?.parent = this; @@ -10060,20 +9599,14 @@ class LabeledStatement extends Statement { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (body != null) { - body = v.transform(body); - body.parent = this; - } + body = v.transform(body); + body.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (body != null) { - body = v.transform(body); - body.parent = this; - } + body = v.transform(body); + body.parent = this; } @override @@ -10186,30 +9719,18 @@ class WhileStatement extends Statement { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (condition != null) { - condition = v.transform(condition); - condition.parent = this; - } - // ignore: unnecessary_null_comparison - if (body != null) { - body = v.transform(body); - body.parent = this; - } + condition = v.transform(condition); + condition.parent = this; + body = v.transform(body); + body.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (condition != null) { - condition = v.transform(condition); - condition.parent = this; - } - // ignore: unnecessary_null_comparison - if (body != null) { - body = v.transform(body); - body.parent = this; - } + condition = v.transform(condition); + condition.parent = this; + body = v.transform(body); + body.parent = this; } @override @@ -10250,30 +9771,18 @@ class DoStatement extends Statement { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (body != null) { - body = v.transform(body); - body.parent = this; - } - // ignore: unnecessary_null_comparison - if (condition != null) { - condition = v.transform(condition); - condition.parent = this; - } + body = v.transform(body); + body.parent = this; + condition = v.transform(condition); + condition.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (body != null) { - body = v.transform(body); - body.parent = this; - } - // ignore: unnecessary_null_comparison - if (condition != null) { - condition = v.transform(condition); - condition.parent = this; - } + body = v.transform(body); + body.parent = this; + condition = v.transform(condition); + condition.parent = this; } @override @@ -10327,11 +9836,8 @@ class ForStatement extends Statement { condition?.parent = this; } v.transformList(updates, this); - // ignore: unnecessary_null_comparison - if (body != null) { - body = v.transform(body); - body.parent = this; - } + body = v.transform(body); + body.parent = this; } @override @@ -10342,11 +9848,8 @@ class ForStatement extends Statement { condition?.parent = this; } v.transformExpressionList(updates, this); - // ignore: unnecessary_null_comparison - if (body != null) { - body = v.transform(body); - body.parent = this; - } + body = v.transform(body); + body.parent = this; } @override @@ -10410,40 +9913,22 @@ class ForInStatement extends Statement { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (variable != null) { - variable = v.transform(variable); - variable.parent = this; - } - // ignore: unnecessary_null_comparison - if (iterable != null) { - iterable = v.transform(iterable); - iterable.parent = this; - } - // ignore: unnecessary_null_comparison - if (body != null) { - body = v.transform(body); - body.parent = this; - } + variable = v.transform(variable); + variable.parent = this; + iterable = v.transform(iterable); + iterable.parent = this; + body = v.transform(body); + body.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (variable != null) { - variable = v.transform(variable); - variable.parent = this; - } - // ignore: unnecessary_null_comparison - if (iterable != null) { - iterable = v.transform(iterable); - iterable.parent = this; - } - // ignore: unnecessary_null_comparison - if (body != null) { - body = v.transform(body); - body.parent = this; - } + variable = v.transform(variable); + variable.parent = this; + iterable = v.transform(iterable); + iterable.parent = this; + body = v.transform(body); + body.parent = this; } /// Returns the type of the iterator in this for-in statement. @@ -10461,15 +9946,12 @@ class ForInStatement extends Statement { DartType getIteratorTypeInternal(StaticTypeContext context) { DartType? iteratorType; if (isAsync) { - InterfaceType? streamType = iterable.getStaticTypeAsInstanceOf( + InterfaceType streamType = iterable.getStaticTypeAsInstanceOf( context.typeEnvironment.coreTypes.streamClass, context); - // ignore: unnecessary_null_comparison - if (streamType != null) { - iteratorType = new InterfaceType( - context.typeEnvironment.coreTypes.streamIteratorClass, - context.nonNullable, - streamType.typeArguments); - } + iteratorType = new InterfaceType( + context.typeEnvironment.coreTypes.streamIteratorClass, + context.nonNullable, + streamType.typeArguments); } else { InterfaceType iterableType = iterable.getStaticTypeAsInstanceOf( context.typeEnvironment.coreTypes.iterableClass, context); @@ -10609,11 +10091,8 @@ class SwitchStatement extends Statement { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (expression != null) { - expression = v.transform(expression); - expression.parent = this; - } + expression = v.transform(expression); + expression.parent = this; v.transformList(cases, this); if (expressionTypeInternal != null) { expressionTypeInternal = v.visitDartType(expressionTypeInternal!); @@ -10622,11 +10101,8 @@ class SwitchStatement extends Statement { @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (expression != null) { - expression = v.transform(expression); - expression.parent = this; - } + expression = v.transform(expression); + expression.parent = this; v.transformSwitchCaseList(cases, this); if (expressionTypeInternal != null) { expressionTypeInternal = @@ -10696,21 +10172,15 @@ class SwitchCase extends TreeNode { @override void transformChildren(Transformer v) { v.transformList(expressions, this); - // ignore: unnecessary_null_comparison - if (body != null) { - body = v.transform(body); - body.parent = this; - } + body = v.transform(body); + body.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { v.transformExpressionList(expressions, this); - // ignore: unnecessary_null_comparison - if (body != null) { - body = v.transform(body); - body.parent = this; - } + body = v.transform(body); + body.parent = this; } @override @@ -10818,16 +10288,10 @@ class IfStatement extends Statement { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (condition != null) { - condition = v.transform(condition); - condition.parent = this; - } - // ignore: unnecessary_null_comparison - if (then != null) { - then = v.transform(then); - then.parent = this; - } + condition = v.transform(condition); + condition.parent = this; + then = v.transform(then); + then.parent = this; if (otherwise != null) { otherwise = v.transform(otherwise!); otherwise?.parent = this; @@ -10836,16 +10300,10 @@ class IfStatement extends Statement { @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (condition != null) { - condition = v.transform(condition); - condition.parent = this; - } - // ignore: unnecessary_null_comparison - if (then != null) { - then = v.transform(then); - then.parent = this; - } + condition = v.transform(condition); + condition.parent = this; + then = v.transform(then); + then.parent = this; if (otherwise != null) { otherwise = v.transformOrRemoveStatement(otherwise!); otherwise?.parent = this; @@ -10946,21 +10404,15 @@ class TryCatch extends Statement { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (body != null) { - body = v.transform(body); - body.parent = this; - } + body = v.transform(body); + body.parent = this; v.transformList(catches, this); } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (body != null) { - body = v.transform(body); - body.parent = this; - } + body = v.transform(body); + body.parent = this; v.transformCatchList(catches, this); } @@ -10988,8 +10440,6 @@ class Catch extends TreeNode { Catch(this.exception, this.body, {this.guard = const DynamicType(), this.stackTrace}) { - // ignore: unnecessary_null_comparison - assert(guard != null); exception?.parent = this; stackTrace?.parent = this; body.parent = this; @@ -11020,11 +10470,8 @@ class Catch extends TreeNode { stackTrace = v.transform(stackTrace!); stackTrace?.parent = this; } - // ignore: unnecessary_null_comparison - if (body != null) { - body = v.transform(body); - body.parent = this; - } + body = v.transform(body); + body.parent = this; } @override @@ -11038,11 +10485,8 @@ class Catch extends TreeNode { stackTrace = v.transformOrRemoveVariableDeclaration(stackTrace!); stackTrace?.parent = this; } - // ignore: unnecessary_null_comparison - if (body != null) { - body = v.transform(body); - body.parent = this; - } + body = v.transform(body); + body.parent = this; } @override @@ -11122,30 +10566,18 @@ class TryFinally extends Statement { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (body != null) { - body = v.transform(body); - body.parent = this; - } - // ignore: unnecessary_null_comparison - if (finalizer != null) { - finalizer = v.transform(finalizer); - finalizer.parent = this; - } + body = v.transform(body); + body.parent = this; + finalizer = v.transform(finalizer); + finalizer.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (body != null) { - body = v.transform(body); - body.parent = this; - } - // ignore: unnecessary_null_comparison - if (finalizer != null) { - finalizer = v.transform(finalizer); - finalizer.parent = this; - } + body = v.transform(body); + body.parent = this; + finalizer = v.transform(finalizer); + finalizer.parent = this; } @override @@ -11197,20 +10629,14 @@ class YieldStatement extends Statement { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (expression != null) { - expression = v.transform(expression); - expression.parent = this; - } + expression = v.transform(expression); + expression.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (expression != null) { - expression = v.transform(expression); - expression.parent = this; - } + expression = v.transform(expression); + expression.parent = this; } @override @@ -11284,8 +10710,6 @@ class VariableDeclaration extends Statement implements Annotatable { bool isSynthesized = false, bool isHoisted = false, bool hasDeclaredInitializer = false}) { - // ignore: unnecessary_null_comparison - assert(type != null); initializer?.parent = this; if (flags != -1) { this.flags = flags; @@ -11314,8 +10738,6 @@ class VariableDeclaration extends Statement implements Annotatable { bool isRequired = false, bool isLowered = false, this.type = const DynamicType()}) { - // ignore: unnecessary_null_comparison - assert(type != null); initializer?.parent = this; this.isFinal = isFinal; this.isConst = isConst; @@ -11559,9 +10981,7 @@ class FunctionDeclaration extends Statement implements LocalFunction { @override FunctionNode function; - FunctionDeclaration(this.variable, this.function) - // ignore: unnecessary_null_comparison - : assert(function != null) { + FunctionDeclaration(this.variable, this.function) { variable.parent = this; function.parent = this; } @@ -11581,30 +11001,18 @@ class FunctionDeclaration extends Statement implements LocalFunction { @override void transformChildren(Transformer v) { - // ignore: unnecessary_null_comparison - if (variable != null) { - variable = v.transform(variable); - variable.parent = this; - } - // ignore: unnecessary_null_comparison - if (function != null) { - function = v.transform(function); - function.parent = this; - } + variable = v.transform(variable); + variable.parent = this; + function = v.transform(function); + function.parent = this; } @override void transformOrRemoveChildren(RemovingTransformer v) { - // ignore: unnecessary_null_comparison - if (variable != null) { - variable = v.transform(variable); - variable.parent = this; - } - // ignore: unnecessary_null_comparison - if (function != null) { - function = v.transform(function); - function.parent = this; - } + variable = v.transform(variable); + variable.parent = this; + function = v.transform(function); + function.parent = this; } @override @@ -11614,12 +11022,9 @@ class FunctionDeclaration extends Statement implements LocalFunction { @override void toTextInternal(AstPrinter printer) { - // ignore: unnecessary_null_comparison - if (function != null) { - printer.writeFunctionNode(function, printer.getVariableName(variable)); - if (function.body is ReturnStatement) { - printer.write(';'); - } + printer.writeFunctionNode(function, printer.getVariableName(variable)); + if (function.body is ReturnStatement) { + printer.write(';'); } } } @@ -11713,9 +11118,7 @@ class _PrivateName extends Name { String toString() => toStringInternal(); @override - String toStringInternal() => - // ignore: unnecessary_null_comparison - library != null ? '$library::$text' : text; + String toStringInternal() => '$library::$text'; @override Library get library => libraryReference.asLibrary; @@ -12170,9 +11573,7 @@ class InterfaceType extends DartType { typeArguments ?? _defaultTypeArguments(classNode)); InterfaceType.byReference( - this.classReference, this.declaredNullability, this.typeArguments) - // ignore: unnecessary_null_comparison - : assert(declaredNullability != null); + this.classReference, this.declaredNullability, this.typeArguments); Class get classNode => classReference.asClass; @@ -12667,9 +12068,7 @@ class ExtensionType extends DartType { typeArguments ?? _defaultTypeArguments(extensionNode)); ExtensionType.byReference( - this.extensionReference, this.declaredNullability, this.typeArguments) - // ignore: unnecessary_null_comparison - : assert(declaredNullability != null); + this.extensionReference, this.declaredNullability, this.typeArguments); Extension get extension => extensionReference.asExtension; @@ -12790,9 +12189,7 @@ class InlineType extends DartType { InlineType.byReference( this.inlineClassReference, this.declaredNullability, this.typeArguments, - [this._instantiatedRepresentationType]) - // ignore: unnecessary_null_comparison - : assert(declaredNullability != null); + [this._instantiatedRepresentationType]); InlineClass get inlineClass => inlineClassReference.asInlineClass; @@ -13795,27 +13192,15 @@ class TypeParameter extends TreeNode implements Annotatable { @override void transformChildren(Transformer v) { v.transformList(annotations, this); - // ignore: unnecessary_null_comparison - if (bound != null) { - bound = v.visitDartType(bound); - } - // ignore: unnecessary_null_comparison - if (defaultType != null) { - defaultType = v.visitDartType(defaultType); - } + bound = v.visitDartType(bound); + defaultType = v.visitDartType(defaultType); } @override void transformOrRemoveChildren(RemovingTransformer v) { v.transformExpressionList(annotations, this); - // ignore: unnecessary_null_comparison - if (bound != null) { - bound = v.visitDartType(bound, cannotRemoveSentinel); - } - // ignore: unnecessary_null_comparison - if (defaultType != null) { - defaultType = v.visitDartType(defaultType, cannotRemoveSentinel); - } + bound = v.visitDartType(bound, cannotRemoveSentinel); + defaultType = v.visitDartType(defaultType, cannotRemoveSentinel); } /// Returns a possibly synthesized name for this type parameter, consistent @@ -14091,10 +13476,7 @@ class DoubleConstant extends PrimitiveConstant { } class StringConstant extends PrimitiveConstant { - StringConstant(String value) : super(value) { - // ignore: unnecessary_null_comparison - assert(value != null); - } + StringConstant(String value) : super(value); @override void visitChildren(Visitor v) {} @@ -15063,17 +14445,14 @@ class Component extends TreeNode { } void adoptChildren() { - // ignore: unnecessary_null_comparison - if (libraries != null) { - for (int i = 0; i < libraries.length; ++i) { - // The libraries are owned by this component, and so are their canonical - // names if they exist. - Library library = libraries[i]; - library.parent = this; - CanonicalName? name = library.reference.canonicalName; - if (name != null && name.parent != root) { - root.adoptChild(name); - } + for (int i = 0; i < libraries.length; ++i) { + // The libraries are owned by this component, and so are their canonical + // names if they exist. + Library library = libraries[i]; + library.parent = this; + CanonicalName? name = library.reference.canonicalName; + if (name != null && name.parent != root) { + root.adoptChild(name); } } } @@ -15661,11 +15040,7 @@ class Version extends Object { final int major; final int minor; - const Version(this.major, this.minor) - // ignore: unnecessary_null_comparison - : assert(major != null), - // ignore: unnecessary_null_comparison - assert(minor != null); + const Version(this.major, this.minor); bool operator <(Version other) { if (major < other.major) return true; diff --git a/pkg/kernel/lib/binary/ast_from_binary.dart b/pkg/kernel/lib/binary/ast_from_binary.dart index 8d8c3446e76..e986f580b71 100644 --- a/pkg/kernel/lib/binary/ast_from_binary.dart +++ b/pkg/kernel/lib/binary/ast_from_binary.dart @@ -120,6 +120,11 @@ abstract class StringInterner { String internString(String string); } +/// Helper used to trigger the read of a late variable in asserts. +bool _lateIsInitialized(dynamic value) { + return true; +} + class BinaryBuilder { final List variableStack = []; final List labelStack = []; @@ -945,8 +950,7 @@ class BinaryBuilder { /// if [readCoverage] is true, references are read and that the link table /// thus has to be read first. Map readUriToSource({required bool readCoverage}) { - // ignore: unnecessary_null_comparison - assert(!readCoverage || (readCoverage && _linkTable != null)); + assert(!readCoverage || (readCoverage && _lateIsInitialized(_linkTable))); int length = readUint32(); @@ -1508,8 +1512,10 @@ class BinaryBuilder { } typeParameterStack.length = 0; - // ignore: unnecessary_null_comparison - assert(debugPath.removeLast() != null); + assert(() { + debugPath.removeLast(); + return true; + }()); node.name = name; node.fileUri = fileUri; node.annotations = annotations; diff --git a/pkg/kernel/lib/binary/ast_to_binary.dart b/pkg/kernel/lib/binary/ast_to_binary.dart index 828cc4c9e93..ef11a7e0185 100644 --- a/pkg/kernel/lib/binary/ast_to_binary.dart +++ b/pkg/kernel/lib/binary/ast_to_binary.dart @@ -955,15 +955,10 @@ class BinaryPrinter implements Visitor, BinarySink { } void writeNonNullReference(Reference reference) { - // ignore: unnecessary_null_comparison - if (reference == null) { - throw new ArgumentError('Got null reference'); - } else { - assert(reference.isConsistent, reference.getInconsistency()); - CanonicalName name = _ensureCanonicalName(reference); - checkCanonicalName(name); - writeUInt30(name.index + 1); - } + assert(reference.isConsistent, reference.getInconsistency()); + CanonicalName name = _ensureCanonicalName(reference); + checkCanonicalName(name); + writeUInt30(name.index + 1); } /// Returns the canonical name for [reference]. @@ -1046,14 +1041,8 @@ class BinaryPrinter implements Visitor, BinarySink { void writeNonNullCanonicalNameReference(Reference reference) { CanonicalName name = _ensureCanonicalName(reference); - // ignore: unnecessary_null_comparison - if (name == null) { - throw new ArgumentError( - 'Expected a canonical name to be valid but was `null`.'); - } else { - checkCanonicalName(name); - writeUInt30(name.index + 1); - } + checkCanonicalName(name); + writeUInt30(name.index + 1); } void writeOffset(int offset) { @@ -1068,11 +1057,6 @@ class BinaryPrinter implements Visitor, BinarySink { } void writeClassReference(Class class_) { - // ignore: unnecessary_null_comparison - if (class_ == null) { - throw new ArgumentError( - 'Expected a class reference to be valid but was `null`.'); - } writeNonNullCanonicalNameReference(class_.reference); } diff --git a/pkg/kernel/lib/canonical_name.dart b/pkg/kernel/lib/canonical_name.dart index 0a85439ea32..2419d832461 100644 --- a/pkg/kernel/lib/canonical_name.dart +++ b/pkg/kernel/lib/canonical_name.dart @@ -94,10 +94,6 @@ class CanonicalName { int index = -1; CanonicalName._(CanonicalName parent, this.name) : _parent = parent { - // ignore: unnecessary_null_comparison - assert(name != null); - // ignore: unnecessary_null_comparison - assert(parent != null); _nonRootTop = parent.isRoot ? this : parent._nonRootTop; } @@ -215,10 +211,6 @@ class CanonicalName { } void bindTo(Reference target) { - // ignore: unnecessary_null_comparison - if (target == null) { - throw '$this cannot be bound to null'; - } if (_reference == target) return; if (_reference != null) { StringBuffer sb = new StringBuffer(); diff --git a/pkg/kernel/lib/class_hierarchy.dart b/pkg/kernel/lib/class_hierarchy.dart index 9e47f49530b..40eec1ffe25 100644 --- a/pkg/kernel/lib/class_hierarchy.dart +++ b/pkg/kernel/lib/class_hierarchy.dart @@ -1754,9 +1754,6 @@ class _ClassInfo { } else { canonical = type; } - // ignore: unnecessary_null_comparison - assert(canonical != null, - "No canonical instantiation computed for $cls in $classNode."); genericSuperType![cls] = canonical; genericSuperTypes![cls] = [type]; } else { diff --git a/pkg/kernel/lib/clone.dart b/pkg/kernel/lib/clone.dart index fd38853a62e..7c2747b0dc0 100644 --- a/pkg/kernel/lib/clone.dart +++ b/pkg/kernel/lib/clone.dart @@ -615,10 +615,7 @@ class CloneVisitorNotMembers implements TreeVisitor { TypeParameter visitTypeParameter(TypeParameter node) { TypeParameter newNode = typeParams[node]!; newNode.bound = visitType(node.bound); - // ignore: unnecessary_null_comparison - if (node.defaultType != null) { - newNode.defaultType = visitType(node.defaultType); - } + newNode.defaultType = visitType(node.defaultType); return newNode ..annotations = cloneAnnotations && !node.annotations.isEmpty ? node.annotations.map(clone).toList() @@ -1209,8 +1206,6 @@ class MixinApplicationCloner extends CloneVisitorWithMembers { cloneAnnotations: cloneAnnotations); Member? _findSuperMember(Name name, {required bool isSetter}) { - // ignore: unnecessary_null_comparison - assert(isSetter != null); Map cache; if (isSetter) { cache = _setterMap ??= {}; diff --git a/pkg/kernel/lib/import_table.dart b/pkg/kernel/lib/import_table.dart index eea2adbb569..272bb7ec21c 100644 --- a/pkg/kernel/lib/import_table.dart +++ b/pkg/kernel/lib/import_table.dart @@ -80,11 +80,7 @@ class _ImportTableBuilder extends RecursiveVisitor { if (target == referenceLibrary) return; // Self-reference is special. if (target == null) return; Uri referenceUri = referenceLibrary.importUri; - Uri? targetUri = target.importUri; - // ignore: unnecessary_null_comparison - if (targetUri == null) { - throw '$referenceUri cannot refer to library without an import URI'; - } + Uri targetUri = target.importUri; // To support using custom-uris in unit tests, we don't check directly // whether the scheme is 'file:', but instead we check that is not 'dart:' // or 'package:'. diff --git a/pkg/kernel/lib/src/bounds_checks.dart b/pkg/kernel/lib/src/bounds_checks.dart index 691cedfc9ae..1729827b613 100644 --- a/pkg/kernel/lib/src/bounds_checks.dart +++ b/pkg/kernel/lib/src/bounds_checks.dart @@ -210,9 +210,6 @@ List calculateBounds( List calculateBoundsInternal( List typeParameters, Class objectClass, {required bool isNonNullableByDefault}) { - // ignore: unnecessary_null_comparison - assert(isNonNullableByDefault != null); - List bounds = new List.filled(typeParameters.length, dummyDartType); for (int i = 0; i < typeParameters.length; i++) { @@ -342,11 +339,6 @@ List findTypeArgumentIssues(DartType type, {required bool allowSuperBounded, required bool isNonNullableByDefault, required bool areGenericArgumentsAllowed}) { - // ignore: unnecessary_null_comparison - assert(isNonNullableByDefault != null); - // ignore: unnecessary_null_comparison - assert(areGenericArgumentsAllowed != null); - List variables = const []; List arguments = const []; List typedefRhsResult = const []; @@ -498,11 +490,6 @@ List findTypeArgumentIssuesForInvocation( DartType bottomType, {required bool isNonNullableByDefault, required bool areGenericArgumentsAllowed}) { - // ignore: unnecessary_null_comparison - assert(isNonNullableByDefault != null); - // ignore: unnecessary_null_comparison - assert(areGenericArgumentsAllowed != null); - assert(arguments.length == parameters.length); assert(bottomType == const NeverType.nonNullable() || bottomType is NullType); @@ -550,9 +537,6 @@ String getGenericTypeName(DartType type) { DartType? convertSuperBoundedToRegularBounded( TypeEnvironment typeEnvironment, DartType type, {int variance = Variance.covariant, required bool isNonNullableByDefault}) { - // ignore: unnecessary_null_comparison - assert(isNonNullableByDefault != null); - return type.accept1( new _SuperBoundedTypeInverter(typeEnvironment, isNonNullableByDefault: isNonNullableByDefault), @@ -565,11 +549,7 @@ class _SuperBoundedTypeInverter extends ReplacementVisitor { bool isOutermost = true; _SuperBoundedTypeInverter(this.typeEnvironment, - {required this.isNonNullableByDefault}) - // ignore: unnecessary_null_comparison - : assert(typeEnvironment != null), - // ignore: unnecessary_null_comparison - assert(isNonNullableByDefault != null); + {required this.isNonNullableByDefault}); bool flipTop(int variance) { return isNonNullableByDefault diff --git a/pkg/kernel/lib/src/const_canonical_type.dart b/pkg/kernel/lib/src/const_canonical_type.dart index fe1e7c6f4ec..c294ecc04f7 100644 --- a/pkg/kernel/lib/src/const_canonical_type.dart +++ b/pkg/kernel/lib/src/const_canonical_type.dart @@ -53,9 +53,6 @@ class _ConstCanonicalTypeVisitor extends ReplacementVisitor { /// https://github.com/dart-lang/language/blob/master/accepted/future-releases/nnbd/feature-specification.md#constant-instances DartType? computeConstCanonicalType(DartType type, CoreTypes coreTypes, {required bool isNonNullableByDefault}) { - // ignore: unnecessary_null_comparison - assert(isNonNullableByDefault != null); - return type.accept1( new _ConstCanonicalTypeVisitor(coreTypes, isNonNullableByDefault: isNonNullableByDefault), diff --git a/pkg/kernel/lib/target/targets.dart b/pkg/kernel/lib/target/targets.dart index 49fbff79b38..1f1b3d23ffc 100644 --- a/pkg/kernel/lib/target/targets.dart +++ b/pkg/kernel/lib/target/targets.dart @@ -402,12 +402,6 @@ abstract class Target { {required bool hasInitializer, required bool isFinal, required bool isStatic}) { - // ignore: unnecessary_null_comparison - assert(hasInitializer != null); - // ignore: unnecessary_null_comparison - assert(isFinal != null); - // ignore: unnecessary_null_comparison - assert(isStatic != null); int mask = LateLowering.getFieldLowering( hasInitializer: hasInitializer, isFinal: isFinal, isStatic: isStatic); return enabledLateLowerings & mask != 0; @@ -461,12 +455,6 @@ abstract class Target { {required bool hasInitializer, required bool isFinal, required bool isPotentiallyNullable}) { - // ignore: unnecessary_null_comparison - assert(hasInitializer != null); - // ignore: unnecessary_null_comparison - assert(isFinal != null); - // ignore: unnecessary_null_comparison - assert(isPotentiallyNullable != null); int mask = LateLowering.getLocalLowering( hasInitializer: hasInitializer, isFinal: isFinal, @@ -656,12 +644,6 @@ class LateLowering { {required bool hasInitializer, required bool isFinal, required bool isPotentiallyNullable}) { - // ignore: unnecessary_null_comparison - assert(hasInitializer != null); - // ignore: unnecessary_null_comparison - assert(isFinal != null); - // ignore: unnecessary_null_comparison - assert(isPotentiallyNullable != null); if (hasInitializer) { if (isFinal) { if (isPotentiallyNullable) { @@ -697,12 +679,6 @@ class LateLowering { {required bool hasInitializer, required bool isFinal, required bool isStatic}) { - // ignore: unnecessary_null_comparison - assert(hasInitializer != null); - // ignore: unnecessary_null_comparison - assert(isFinal != null); - // ignore: unnecessary_null_comparison - assert(isStatic != null); if (hasInitializer) { if (isFinal) { if (isStatic) { diff --git a/pkg/kernel/lib/testing/type_parser_environment.dart b/pkg/kernel/lib/testing/type_parser_environment.dart index ebca635c077..df266bcb634 100644 --- a/pkg/kernel/lib/testing/type_parser_environment.dart +++ b/pkg/kernel/lib/testing/type_parser_environment.dart @@ -79,8 +79,6 @@ class Env { final bool isNonNullableByDefault; Env(String source, {required this.isNonNullableByDefault}) { - // ignore: unnecessary_null_comparison - assert(isNonNullableByDefault != null); Uri libraryUri = Uri.parse('memory:main.dart'); Uri coreUri = Uri.parse("dart:core"); TypeParserEnvironment coreEnvironment = @@ -211,8 +209,7 @@ class TypeParserEnvironment { } ParameterEnvironment extendToParameterEnvironment(String typeParameters) { - // ignore: unnecessary_null_comparison - assert(typeParameters != null && typeParameters.isNotEmpty); + assert(typeParameters.isNotEmpty); return const _KernelFromParsedType().computeTypeParameterEnvironment( parseTypeVariables("<${typeParameters}>"), this); } diff --git a/pkg/kernel/lib/text/ast_to_text.dart b/pkg/kernel/lib/text/ast_to_text.dart index d98ec6c45a1..04b536c6f28 100644 --- a/pkg/kernel/lib/text/ast_to_text.dart +++ b/pkg/kernel/lib/text/ast_to_text.dart @@ -191,7 +191,6 @@ String componentToString(Component node) { class NameSystem { final Namer variables = new NormalNamer('#t'); - final Namer members = new NormalNamer('#m'); final Namer classes = new NormalNamer('#class'); final Namer extensions = new NormalNamer('#extension'); final Namer libraries = new NormalNamer('#lib'); @@ -203,7 +202,6 @@ class NameSystem { new Disambiguator(); String nameVariable(VariableDeclaration node) => variables.getName(node); - String nameMember(Member node) => members.getName(node); String nameClass(Class node) => classes.getName(node); String nameExtension(Extension node) => extensions.getName(node); String nameLibrary(Library node) => libraries.getName(node); @@ -224,17 +222,13 @@ class NameSystem { if (name != null) { return abbreviateName(name); } - // ignore: unnecessary_null_comparison - if (node.importUri != null) { - String path = node.importUri.hasEmptyPath - ? '${node.importUri}' - : node.importUri.pathSegments.last; - if (path.endsWith('.dart')) { - path = path.substring(0, path.length - '.dart'.length); - } - return abbreviateName(path); + String path = node.importUri.hasEmptyPath + ? '${node.importUri}' + : node.importUri.pathSegments.last; + if (path.endsWith('.dart')) { + path = path.substring(0, path.length - '.dart'.length); } - return 'L'; + return abbreviateName(path); }); } @@ -327,8 +321,6 @@ class Printer extends Visitor with VisitorVoidMixin { } String getLibraryReference(Library node) { - // ignore: unnecessary_null_comparison - if (node == null) return ''; if (importTable != null && importTable?.getImportIndex(node) != -1) { return syntheticNames.nameLibraryPrefix(node); } @@ -348,32 +340,24 @@ class Printer extends Visitor with VisitorVoidMixin { } String getClassReference(Class node) { - // ignore: unnecessary_null_comparison - if (node == null) return ''; String name = getClassName(node); String library = getLibraryReference(node.enclosingLibrary); return '$library::$name'; } String getExtensionReference(Extension node) { - // ignore: unnecessary_null_comparison - if (node == null) return ''; String name = getExtensionName(node); String library = getLibraryReference(node.enclosingLibrary); return '$library::$name'; } String getInlineClassReference(InlineClass node) { - // ignore: unnecessary_null_comparison - if (node == null) return ''; String name = getInlineClassName(node); String library = getLibraryReference(node.enclosingLibrary); return '$library::$name'; } String getTypedefReference(Typedef node) { - // ignore: unnecessary_null_comparison - if (node == null) return ''; String library = getLibraryReference(node.enclosingLibrary); return '$library::${node.name}'; } @@ -383,14 +367,10 @@ class Printer extends Visitor with VisitorVoidMixin { Name getMemberName(Member node) { if (node.name.text == '') return emptyName; - // ignore: unnecessary_null_comparison - if (node.name != null) return node.name; - return new Name(syntheticNames.nameMember(node)); + return node.name; } String getMemberReference(Member node) { - // ignore: unnecessary_null_comparison - if (node == null) return ''; String name = getMemberName(node).text; Class? enclosingClass = node.enclosingClass; if (enclosingClass != null) { @@ -407,8 +387,6 @@ class Printer extends Visitor with VisitorVoidMixin { } String getVariableReference(VariableDeclaration node) { - // ignore: unnecessary_null_comparison - if (node == null) return ''; return getVariableName(node); } @@ -417,8 +395,6 @@ class Printer extends Visitor with VisitorVoidMixin { } String getTypeParameterReference(TypeParameter node) { - // ignore: unnecessary_null_comparison - if (node == null) return ''; String name = getTypeParameterName(node); TreeNode? parent = node.parent; if (parent is FunctionNode && parent.parent is Member) { @@ -587,11 +563,8 @@ class Printer extends Visitor with VisitorVoidMixin { if (name != null) { writeWord(name); } - // ignore: unnecessary_null_comparison - if (library.importUri != null) { - writeSpaced('from'); - writeWord('"${library.importUri}"'); - } + writeSpaced('from'); + writeWord('"${library.importUri}"'); String prefix = syntheticNames.nameLibraryPrefix(library); writeSpaced('as'); writeWord(prefix); @@ -716,33 +689,16 @@ class Printer extends Visitor with VisitorVoidMixin { } void writeType(DartType type) { - // ignore: unnecessary_null_comparison - if (type == null) { - write(''); - } else { - type.accept(this); - } - } - - void writeOptionalType(DartType type) { - // ignore: unnecessary_null_comparison - if (type != null) { - type.accept(this); - } + type.accept(this); } @override void visitSupertype(Supertype type) { - // ignore: unnecessary_null_comparison - if (type == null) { - write(''); - } else { - writeClassReferenceFromReference(type.className); - if (type.typeArguments.isNotEmpty) { - writeSymbol('<'); - writeList(type.typeArguments, writeType); - writeSymbol('>'); - } + writeClassReferenceFromReference(type.className); + if (type.typeArguments.isNotEmpty) { + writeSymbol('<'); + writeList(type.typeArguments, writeType); + writeSymbol('>'); } } @@ -919,8 +875,6 @@ class Printer extends Visitor with VisitorVoidMixin { } void writeReturnType(DartType type, String? annotation) { - // ignore: unnecessary_null_comparison - if (type == null) return; writeSpaced('→'); writeAnnotatedType(type, annotation); } @@ -976,8 +930,6 @@ class Printer extends Visitor with VisitorVoidMixin { } String getClassReferenceFromReference(Reference reference) { - // ignore: unnecessary_null_comparison - if (reference == null) return ''; if (reference.node != null) return getClassReference(reference.asClass); if (reference.canonicalName != null) { return getCanonicalNameString(reference.canonicalName!); @@ -990,8 +942,6 @@ class Printer extends Visitor with VisitorVoidMixin { } String getExtensionReferenceFromReference(Reference reference) { - // ignore: unnecessary_null_comparison - if (reference == null) return ''; if (reference.node != null) { return getExtensionReference(reference.asExtension); } @@ -1006,8 +956,6 @@ class Printer extends Visitor with VisitorVoidMixin { } String getInlineClassReferenceFromReference(Reference reference) { - // ignore: unnecessary_null_comparison - if (reference == null) return ''; if (reference.node != null) { return getInlineClassReference(reference.asInlineClass); } @@ -1932,12 +1880,9 @@ class Printer extends Visitor with VisitorVoidMixin { writeWord('const'); writeSpace(); } - // ignore: unnecessary_null_comparison - if (node.typeArgument != null) { - writeSymbol('<'); - writeType(node.typeArgument); - writeSymbol('>'); - } + writeSymbol('<'); + writeType(node.typeArgument); + writeSymbol('>'); writeSymbol('['); writeList(node.expressions, writeNode); writeSymbol(']'); @@ -1949,12 +1894,9 @@ class Printer extends Visitor with VisitorVoidMixin { writeWord('const'); writeSpace(); } - // ignore: unnecessary_null_comparison - if (node.typeArgument != null) { - writeSymbol('<'); - writeType(node.typeArgument); - writeSymbol('>'); - } + writeSymbol('<'); + writeType(node.typeArgument); + writeSymbol('>'); writeSymbol('{'); writeList(node.expressions, writeNode); writeSymbol('}'); @@ -1966,12 +1908,9 @@ class Printer extends Visitor with VisitorVoidMixin { writeWord('const'); writeSpace(); } - // ignore: unnecessary_null_comparison - if (node.keyType != null) { - writeSymbol('<'); - writeList([node.keyType, node.valueType], writeType); - writeSymbol('>'); - } + writeSymbol('<'); + writeList([node.keyType, node.valueType], writeType); + writeSymbol('>'); writeSymbol('{'); writeList(node.entries, writeNode); writeSymbol('}'); @@ -2172,12 +2111,9 @@ class Printer extends Visitor with VisitorVoidMixin { } void writeStaticType(DartType type) { - // ignore: unnecessary_null_comparison - if (type != null) { - writeSymbol('{'); - writeType(type); - writeSymbol('}'); - } + writeSymbol('{'); + writeType(type); + writeSymbol('}'); } @override @@ -2533,12 +2469,9 @@ class Printer extends Visitor with VisitorVoidMixin { @override void visitCatch(Catch node) { writeIndentation(); - // ignore: unnecessary_null_comparison - if (node.guard != null) { - writeWord('on'); - writeType(node.guard); - writeSpace(); - } + writeWord('on'); + writeType(node.guard); + writeSpace(); writeWord('catch'); writeSymbol('('); VariableDeclaration? exception = node.exception; @@ -2590,13 +2523,7 @@ class Printer extends Visitor with VisitorVoidMixin { writeAnnotationList(node.variable.annotations); writeIndentation(); writeWord('function'); - // ignore: unnecessary_null_comparison - if (node.function != null) { - writeFunction(node.function, name: getVariableName(node.variable)); - } else { - writeWord(getVariableName(node.variable)); - endLine('...;'); - } + writeFunction(node.function, name: getVariableName(node.variable)); } void writeVariableDeclaration(VariableDeclaration node, @@ -2624,14 +2551,7 @@ class Printer extends Visitor with VisitorVoidMixin { !node.hasDeclaredInitializer) { writeModifier(node.hasDeclaredInitializer, 'has-no-declared-initializer'); } - // ignore: unnecessary_null_comparison - if (node.type != null) { - writeAnnotatedType(node.type, annotator?.annotateVariable(this, node)); - } - // ignore: unnecessary_null_comparison - if (useVarKeyword && !node.isFinal && !node.isConst && node.type == null) { - writeWord('var'); - } + writeAnnotatedType(node.type, annotator?.annotateVariable(this, node)); writeWord(getVariableName(node)); Expression? initializer = node.initializer; if (initializer != null) { diff --git a/pkg/kernel/lib/transformations/track_widget_constructor_locations.dart b/pkg/kernel/lib/transformations/track_widget_constructor_locations.dart index cb3f426653f..ec3565f1467 100644 --- a/pkg/kernel/lib/transformations/track_widget_constructor_locations.dart +++ b/pkg/kernel/lib/transformations/track_widget_constructor_locations.dart @@ -368,8 +368,7 @@ class WidgetCreatorTracker { bool foundLocationClass = false; for (Library library in libraries) { final Uri importUri = library.importUri; - // ignore: unnecessary_null_comparison - if (importUri != null && importUri.isScheme('package')) { + if (importUri.isScheme('package')) { if (importUri.path == 'flutter/src/widgets/framework.dart') { for (Class class_ in library.classes) { if (class_.name == 'Widget') { diff --git a/pkg/kernel/lib/type_algebra.dart b/pkg/kernel/lib/type_algebra.dart index c816a925bb3..1add8ec904c 100644 --- a/pkg/kernel/lib/type_algebra.dart +++ b/pkg/kernel/lib/type_algebra.dart @@ -527,10 +527,7 @@ class _InnerTypeSubstitutor extends _TypeSubstitutor { TypeParameterType typeParameterType = substitution[node] = new TypeParameterType.forAlphaRenaming(node, fresh); fresh.bound = visit(node.bound); - // ignore: unnecessary_null_comparison - if (node.defaultType != null) { - fresh.defaultType = visit(node.defaultType); - } + fresh.defaultType = visit(node.defaultType); // If the bound was changed from substituting the bound we need to update // implicit nullability to be based on the new bound. If the bound wasn't // changed the computation below results in the same nullability. @@ -998,8 +995,6 @@ class _OccurrenceVisitor implements DartTypeVisitor { bool handleTypeParameter(TypeParameter node) { assert(!variables.contains(node)); if (node.bound.accept(this)) return true; - // ignore: unnecessary_null_comparison - if (node.defaultType == null) return false; return node.defaultType.accept(this); } } @@ -1085,8 +1080,6 @@ class _FreeFunctionTypeVariableVisitor implements DartTypeVisitor { bool handleTypeParameter(TypeParameter node) { assert(variables.contains(node)); if (node.bound.accept(this)) return true; - // ignore: unnecessary_null_comparison - if (node.defaultType == null) return false; return node.defaultType.accept(this); } } @@ -1173,8 +1166,6 @@ class _FreeTypeVariableVisitor implements DartTypeVisitor { bool handleTypeParameter(TypeParameter node) { assert(boundVariables.contains(node)); if (node.bound.accept(this)) return true; - // ignore: unnecessary_null_comparison - if (node.defaultType == null) return false; return node.defaultType.accept(this); } } @@ -1389,14 +1380,7 @@ abstract class NullabilityAwareTypeVariableEliminatorBase NullabilityAwareTypeVariableEliminatorBase( {required this.bottomType, required this.topType, - required this.topFunctionType}) - : - // ignore: unnecessary_null_comparison - assert(bottomType != null), - // ignore: unnecessary_null_comparison - assert(topType != null), - // ignore: unnecessary_null_comparison - assert(topFunctionType != null); + required this.topFunctionType}); bool containsTypeVariablesToEliminate(DartType type); @@ -1480,15 +1464,7 @@ class NullabilityAwareTypeVariableEliminator required DartType topType, required DartType topFunctionType, this.unhandledTypeHandler}) - // ignore: unnecessary_null_comparison - : assert(eliminationTargets != null), - // ignore: unnecessary_null_comparison - assert(bottomType != null), - // ignore: unnecessary_null_comparison - assert(topType != null), - // ignore: unnecessary_null_comparison - assert(topFunctionType != null), - super( + : super( bottomType: bottomType, topType: topType, topFunctionType: topFunctionType); @@ -1523,14 +1499,7 @@ class NullabilityAwareFreeTypeVariableEliminator {required DartType bottomType, required DartType topType, required DartType topFunctionType}) - : - // ignore: unnecessary_null_comparison - assert(bottomType != null), - // ignore: unnecessary_null_comparison - assert(topType != null), - // ignore: unnecessary_null_comparison - assert(topFunctionType != null), - super( + : super( bottomType: bottomType, topType: topType, topFunctionType: topFunctionType); @@ -1568,9 +1537,6 @@ class NullabilityAwareFreeTypeVariableEliminator /// [Nullability.undetermined], depending on the bound. DartType computeTypeWithoutNullabilityMarker(DartType type, {required bool isNonNullableByDefault}) { - // ignore: unnecessary_null_comparison - assert(isNonNullableByDefault != null); - if (type is TypeParameterType) { // The default nullability for library is used when there are no // nullability markers on the type. @@ -1599,9 +1565,6 @@ DartType computeTypeWithoutNullabilityMarker(DartType type, /// and S extends Object. bool isTypeParameterTypeWithoutNullabilityMarker(TypeParameterType type, {required bool isNonNullableByDefault}) { - // ignore: unnecessary_null_comparison - assert(isNonNullableByDefault != null); - // The default nullability for library is used when there are no nullability // markers on the type. return type.declaredNullability == @@ -1611,8 +1574,6 @@ bool isTypeParameterTypeWithoutNullabilityMarker(TypeParameterType type, bool isTypeWithoutNullabilityMarker(DartType type, {required bool isNonNullableByDefault}) { - // ignore: unnecessary_null_comparison - assert(isNonNullableByDefault != null); return !type.accept(new _NullabilityMarkerDetector(isNonNullableByDefault)); } @@ -1732,9 +1693,6 @@ bool isNullableTypeConstructorApplication(DartType type) { /// dynamic or void. bool isLegacyTypeConstructorApplication(DartType type, {required bool isNonNullableByDefault}) { - // ignore: unnecessary_null_comparison - assert(isNonNullableByDefault != null); - if (type is TypeParameterType) { // The legacy nullability is considered an application of the legacy // nullability constructor if it doesn't match the default nullability @@ -1751,8 +1709,6 @@ bool isLegacyTypeConstructorApplication(DartType type, Nullability _defaultNullabilityForTypeParameterType(TypeParameter parameter, {required bool isNonNullableByDefault}) { - // ignore: unnecessary_null_comparison - assert(isNonNullableByDefault != null); return isNonNullableByDefault ? TypeParameterType.computeNullabilityFromBound(parameter) : Nullability.legacy; diff --git a/pkg/kernel/lib/verifier.dart b/pkg/kernel/lib/verifier.dart index dd3f119a03a..b7a0f8edfaa 100644 --- a/pkg/kernel/lib/verifier.dart +++ b/pkg/kernel/lib/verifier.dart @@ -822,10 +822,6 @@ class VerifyingVisitor extends RecursiveResultVisitor { void visitStaticGet(StaticGet node) { enterTreeNode(node); visitChildren(node); - // ignore: unnecessary_null_comparison - if (node.target == null) { - problem(node, "StaticGet without target."); - } // Currently Constructor.hasGetter returns `false` even though fasta uses it // as a getter for internal purposes: // @@ -853,10 +849,6 @@ class VerifyingVisitor extends RecursiveResultVisitor { void visitStaticSet(StaticSet node) { enterTreeNode(node); visitChildren(node); - // ignore: unnecessary_null_comparison - if (node.target == null) { - problem(node, "StaticSet without target."); - } if (!node.target.hasSetter) { problem(node, "StaticSet to '${node.target}' without setter."); } @@ -899,10 +891,6 @@ class VerifyingVisitor extends RecursiveResultVisitor { void checkTargetedInvocation(Member target, InvocationExpression node) { visitChildren(node); - // ignore: unnecessary_null_comparison - if (target == null) { - problem(node, "${node.runtimeType} without target."); - } if (target.function == null) { problem(node, "${node.runtimeType} without function."); } @@ -1001,10 +989,7 @@ class VerifyingVisitor extends RecursiveResultVisitor { @override void visitContinueSwitchStatement(ContinueSwitchStatement node) { enterTreeNode(node); - // ignore: unnecessary_null_comparison - if (node.target == null) { - problem(node, "No target."); - } else if (node.target.parent == null) { + if (node.target.parent == null) { problem(node, "Target has no parent."); } else { SwitchStatement statement = node.target.parent as SwitchStatement; @@ -1259,8 +1244,7 @@ class VerifyingVisitor extends RecursiveResultVisitor { TreeNode? getSameLibraryLastSeenTreeNode({bool withLocation = false}) { if (treeNodeStack.isEmpty) return null; - // ignore: unnecessary_null_comparison - if (currentLibrary == null || currentLibrary!.fileUri == null) return null; + if (currentLibrary == null) return null; for (int i = treeNodeStack.length - 1; i >= 0; --i) { TreeNode node = treeNodeStack[i]; @@ -1334,11 +1318,6 @@ class VerifyingVisitor extends RecursiveResultVisitor { // } return fileUri; } else { - // ignore: unnecessary_null_comparison - if (fileUri == null) { - problem(node, "'$name' has no fileUri", context: node); - return fileUri; - } if (node.fileOffset == TreeNode.noOffset && !target.verification.allowNoFileOffset(stage, node)) { problem(node, "'$name' has no fileOffset", context: node); diff --git a/pkg/kernel/lib/visitor.dart b/pkg/kernel/lib/visitor.dart index e2c27813851..c9045fcf427 100644 --- a/pkg/kernel/lib/visitor.dart +++ b/pkg/kernel/lib/visitor.dart @@ -1798,47 +1798,24 @@ class Transformer extends TreeVisitor { const Transformer(); T transform(T node) { - T result = node.accept(this) as T; - assert( - // ignore: unnecessary_null_comparison - result != null, - 'Attempting to remove ${node} (${node.runtimeType}) ' - 'in transformer.'); - return result; + return node.accept(this) as T; } void transformDartTypeList(List nodes) { for (int i = 0; i < nodes.length; ++i) { - DartType result = visitDartType(nodes[i]); - assert( - // ignore: unnecessary_null_comparison - result != null, - 'Attempting to remove ${nodes[i]} (${nodes[i].runtimeType}) ' - 'in transformer.'); - nodes[i] = result; + nodes[i] = visitDartType(nodes[i]); } } void transformSupertypeList(List nodes) { for (int i = 0; i < nodes.length; ++i) { - Supertype result = visitSupertype(nodes[i]); - assert( - // ignore: unnecessary_null_comparison - result != null, - 'Attempting to remove ${nodes[i]} (${nodes[i].runtimeType}) ' - 'in transformer.'); - nodes[i] = result; + nodes[i] = visitSupertype(nodes[i]); } } void transformList(List nodes, TreeNode parent) { for (int i = 0; i < nodes.length; ++i) { T result = transform(nodes[i]); - assert( - // ignore: unnecessary_null_comparison - result != null, - 'Attempting to remove ${nodes[i]} (${nodes[i].runtimeType}) ' - 'in transformer.'); result.parent = parent; nodes[i] = result; } diff --git a/pkg/testing/lib/src/error_handling.dart b/pkg/testing/lib/src/error_handling.dart index 7913f13529f..37c538e3f5b 100644 --- a/pkg/testing/lib/src/error_handling.dart +++ b/pkg/testing/lib/src/error_handling.dart @@ -20,10 +20,7 @@ Future withErrorHandling(Future Function() f, } catch (e, trace) { exitCode = 1; stderr.writeln(e); - // ignore: unnecessary_null_comparison - if (trace != null) { - stderr.writeln(trace); - } + stderr.writeln(trace); logger?.noticeFrameworkCatchError(e, trace); return null; } finally { diff --git a/pkg/testing/lib/src/log.dart b/pkg/testing/lib/src/log.dart index 68f3a66370d..c49481acf29 100644 --- a/pkg/testing/lib/src/log.dart +++ b/pkg/testing/lib/src/log.dart @@ -198,10 +198,7 @@ class StdoutLogger implements Logger { @override void logUncaughtError(error, StackTrace stackTrace) { logMessage(error); - // ignore: unnecessary_null_comparison - if (stackTrace != null) { - logMessage(stackTrace); - } + logMessage(stackTrace); } @override diff --git a/pkg/vm/lib/transformations/ffi/finalizable.dart b/pkg/vm/lib/transformations/ffi/finalizable.dart index 18bd5e516f4..7fcf726c7ca 100644 --- a/pkg/vm/lib/transformations/ffi/finalizable.dart +++ b/pkg/vm/lib/transformations/ffi/finalizable.dart @@ -166,29 +166,20 @@ mixin FinalizableTransformer on Transformer { // [variable] in scope. // First, transform the iterable, which does not have variable in scope. - // ignore: unnecessary_null_comparison - if (node.iterable != null) { - node.iterable = transform(node.iterable); - node.iterable.parent = node; - } + node.iterable = transform(node.iterable); + node.iterable.parent = node; final scope = _Scope(node, parent: _currentScope); _currentScope = scope; // Then, transform the variable, adding it to the new scope. - // ignore: unnecessary_null_comparison - if (node.variable != null) { - assert(node.variable.initializer == null); - node.variable = transform(node.variable); - node.variable.parent = node; - } + assert(node.variable.initializer == null); + node.variable = transform(node.variable); + node.variable.parent = node; // Then transform the body, with the new variable in scope. - // ignore: unnecessary_null_comparison - if (node.body != null) { - node.body = transform(node.body); - node.body.parent = node; - } + node.body = transform(node.body); + node.body.parent = node; _appendReachabilityFences(node.body, scope.toFenceThisScope); diff --git a/pkg/vm/lib/transformations/mixin_deduplication.dart b/pkg/vm/lib/transformations/mixin_deduplication.dart index 6ea5178f038..bd31ec999c8 100644 --- a/pkg/vm/lib/transformations/mixin_deduplication.dart +++ b/pkg/vm/lib/transformations/mixin_deduplication.dart @@ -109,8 +109,6 @@ class DeduplicateMixinsTransformer extends RemovingTransformer { Class canonical = _canonicalMixins.putIfAbsent(new _DeduplicateMixinKey(c), () => c); - // ignore: unnecessary_null_comparison - assert(canonical != null); if (canonical != c) { // Ensure that kernel file writer will not be able to diff --git a/pkg/vm/lib/transformations/specializer/factory_specializer.dart b/pkg/vm/lib/transformations/specializer/factory_specializer.dart index b86c3e6b1b8..5af8ab3ae08 100644 --- a/pkg/vm/lib/transformations/specializer/factory_specializer.dart +++ b/pkg/vm/lib/transformations/specializer/factory_specializer.dart @@ -31,11 +31,6 @@ class FactorySpecializer extends BaseSpecializer { TreeNode transformStaticInvocation(StaticInvocation invocation) { final target = invocation.target; - // ignore: unnecessary_null_comparison - if (target == null) { - return invocation; - } - final transformer = transformers[target]; if (transformer != null) { return transformer(invocation);