diff --git a/pkg/compiler/analysis_options.yaml b/pkg/compiler/analysis_options.yaml index c3aa3cfd087..f832119697f 100644 --- a/pkg/compiler/analysis_options.yaml +++ b/pkg/compiler/analysis_options.yaml @@ -21,3 +21,4 @@ linter: - no_default_cases - unnecessary_ignore - unnecessary_statements + - use_null_aware_elements diff --git a/pkg/compiler/lib/src/elements/types.dart b/pkg/compiler/lib/src/elements/types.dart index d25331777b6..3b38d852a8f 100644 --- a/pkg/compiler/lib/src/elements/types.dart +++ b/pkg/compiler/lib/src/elements/types.dart @@ -1532,8 +1532,7 @@ class _DartTypeToStringVisitor extends DartTypeVisitor { // Assign names to _DeferredNames that were not assigned while visiting a // generic function type. Set usedNames = { - for (final deferred in variableToName.values) - if (deferred.name != null) deferred.name!, + for (final deferred in variableToName.values) ?deferred.name, }; int startGroup = (_genericFunctions?.length ?? 0) + 1; for (var entry in variableToName.entries) { diff --git a/pkg/compiler/lib/src/js/rewrite_async.dart b/pkg/compiler/lib/src/js/rewrite_async.dart index b141820d454..9c05884ec4c 100644 --- a/pkg/compiler/lib/src/js/rewrite_async.dart +++ b/pkg/compiler/lib/src/js/rewrite_async.dart @@ -2558,8 +2558,7 @@ class AsyncStarRewriter extends AsyncRewriterBase { List enclosingFinallyLabels = [ // At the bottom of the stack is the return label. exitLabel!, - for (final node in jumpTargets) - if (finallyLabels[node] != null) finallyLabels[node]!, + for (final node in jumpTargets) ?finallyLabels[node], ]; addStatement( diff --git a/pkg/compiler/lib/src/js_model/js_to_frontend_map.dart b/pkg/compiler/lib/src/js_model/js_to_frontend_map.dart index 3013281d615..51d2d4d67fd 100644 --- a/pkg/compiler/lib/src/js_model/js_to_frontend_map.dart +++ b/pkg/compiler/lib/src/js_model/js_to_frontend_map.dart @@ -101,7 +101,7 @@ class JsToFrontendMap { return { for (final member in set.map(toBackendMember)) // Members that are not live don't have a corresponding backend member. - if (member != null) member, + ?member, }; } diff --git a/pkg/compiler/lib/src/kernel/transformations/modular/list_factory_specializer.dart b/pkg/compiler/lib/src/kernel/transformations/modular/list_factory_specializer.dart index 3025a27e7a6..448d2ee7e62 100644 --- a/pkg/compiler/lib/src/kernel/transformations/modular/list_factory_specializer.dart +++ b/pkg/compiler/lib/src/kernel/transformations/modular/list_factory_specializer.dart @@ -170,7 +170,7 @@ class ListFactorySpecializer extends BaseSpecializer { )..fileOffset = node.fileOffset; return BlockExpression( - Block([if (lengthVariable != null) lengthVariable!, listVariable, loop]), + Block([?lengthVariable, listVariable, loop]), VariableGet(listVariable)..fileOffset = node.fileOffset, ); } diff --git a/pkg/compiler/lib/src/ssa/nodes.dart b/pkg/compiler/lib/src/ssa/nodes.dart index b549f9e6b2d..e4d4a108a74 100644 --- a/pkg/compiler/lib/src/ssa/nodes.dart +++ b/pkg/compiler/lib/src/ssa/nodes.dart @@ -3978,7 +3978,7 @@ abstract class HLateCheck extends HCheck { HInstruction? name, this.isTrusted, AbstractValue type, - ) : super([input, if (name != null) name], type); + ) : super([input, ?name], type); bool get hasName => inputs.length > 1; @@ -4989,13 +4989,7 @@ class HArrayFlagsCheck extends HCheck { HInstruction? operation, HInstruction? verb, AbstractValue type, - ) : super([ - array, - arrayFlags, - checkFlags, - if (operation != null) operation, - if (verb != null) verb, - ], type); + ) : super([array, arrayFlags, checkFlags, ?operation, ?verb], type); HInstruction get array => inputs[0]; HInstruction get arrayFlags => inputs[1];