From 3263555dc598afd6369c4cab02fd97901f2f7db5 Mon Sep 17 00:00:00 2001 From: Erik Ernst Date: Wed, 27 May 2026 06:04:46 -0700 Subject: [PATCH] Start implementation of anonymous block methods This CL introduces support for anonymous block methods (that is, `e.{ print(this); }` as opposed to `e.=> print(this);`). It introduces the notion of a `ReturnContext` which is used to change the semantics of a return statement when it returns from an anonymous method (where it works like a `break` that terminates the execution of the block which is the body of the enclosing anonymous method), but keeps the semantics of return statements returning from a function (including function literals) still have the same semantics as today. Change-Id: I404459361fbb7c2e495e46d1bd29924063f3aac4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/503800 SLSA-Policy-Verified: SLSA Policy Verification Service Reviewed-by: Johnni Winther Commit-Queue: Erik Ernst --- .../lib/src/kernel/body_builder.dart | 143 ++++---- .../lib/src/kernel/internal_ast.dart | 45 +++ .../src/type_inference/inference_visitor.dart | 214 ++++++++++++ ...ck_cascaded_null_aware_with_parameter.dart | 29 ++ ...ll_aware_with_parameter.dart.strong.expect | 88 +++++ ..._with_parameter.dart.strong.modular.expect | 88 +++++ ..._with_parameter.dart.strong.outline.expect | 7 + ...h_parameter.dart.strong.transformed.expect | 88 +++++ ...with_parameter.dart.textual_outline.expect | 3 + ...meter.dart.textual_outline_modelled.expect | 3 + ...cascaded_null_aware_without_parameter.dart | 36 +++ ...aware_without_parameter.dart.strong.expect | 115 +++++++ ...thout_parameter.dart.strong.modular.expect | 115 +++++++ ...thout_parameter.dart.strong.outline.expect | 7 + ...t_parameter.dart.strong.transformed.expect | 115 +++++++ ...hout_parameter.dart.textual_outline.expect | 3 + ...meter.dart.textual_outline_modelled.expect | 3 + .../block_cascaded_with_parameter.dart | 27 ++ ...cascaded_with_parameter.dart.strong.expect | 87 +++++ ..._with_parameter.dart.strong.modular.expect | 87 +++++ ..._with_parameter.dart.strong.outline.expect | 5 + ...h_parameter.dart.strong.transformed.expect | 103 ++++++ ...with_parameter.dart.textual_outline.expect | 1 + ...meter.dart.textual_outline_modelled.expect | 1 + .../block_cascaded_without_parameter.dart | 34 ++ ...caded_without_parameter.dart.strong.expect | 114 +++++++ ...thout_parameter.dart.strong.modular.expect | 114 +++++++ ...thout_parameter.dart.strong.outline.expect | 5 + ...t_parameter.dart.strong.transformed.expect | 134 ++++++++ ...hout_parameter.dart.textual_outline.expect | 1 + ...meter.dart.textual_outline_modelled.expect | 1 + .../block_explicitly_typed.dart | 34 ++ .../block_explicitly_typed.dart.strong.expect | 106 ++++++ ...xplicitly_typed.dart.strong.modular.expect | 106 ++++++ ...xplicitly_typed.dart.strong.outline.expect | 5 + ...citly_typed.dart.strong.transformed.expect | 126 ++++++++ ...plicitly_typed.dart.textual_outline.expect | 1 + ...typed.dart.textual_outline_modelled.expect | 1 + .../block_explicitly_wrongly_typed.dart | 18 ++ ...xplicitly_wrongly_typed.dart.strong.expect | 77 +++++ ...y_wrongly_typed.dart.strong.modular.expect | 77 +++++ ...y_wrongly_typed.dart.strong.outline.expect | 5 + ...ongly_typed.dart.strong.transformed.expect | 85 +++++ ..._wrongly_typed.dart.textual_outline.expect | 1 + ...typed.dart.textual_outline_modelled.expect | 1 + .../block_extension_method.dart | 68 ++++ .../block_extension_method.dart.strong.expect | 215 ++++++++++++ ...xtension_method.dart.strong.modular.expect | 215 ++++++++++++ ...xtension_method.dart.strong.outline.expect | 14 + ...sion_method.dart.strong.transformed.expect | 251 ++++++++++++++ ...tension_method.dart.textual_outline.expect | 5 + ...ethod.dart.textual_outline_modelled.expect | 5 + .../block_null_aware_with_parameter.dart | 29 ++ ...ll_aware_with_parameter.dart.strong.expect | 76 +++++ ..._with_parameter.dart.strong.modular.expect | 76 +++++ ..._with_parameter.dart.strong.outline.expect | 7 + ...h_parameter.dart.strong.transformed.expect | 76 +++++ ...with_parameter.dart.textual_outline.expect | 3 + ...meter.dart.textual_outline_modelled.expect | 3 + .../block_null_aware_without_parameter.dart | 36 +++ ...aware_without_parameter.dart.strong.expect | 99 ++++++ ...thout_parameter.dart.strong.modular.expect | 99 ++++++ ...thout_parameter.dart.strong.outline.expect | 7 + ...t_parameter.dart.strong.transformed.expect | 99 ++++++ ...hout_parameter.dart.textual_outline.expect | 3 + ...meter.dart.textual_outline_modelled.expect | 3 + .../block_this_in_initializer.dart | 28 ++ ...ock_this_in_initializer.dart.strong.expect | 71 ++++ ..._in_initializer.dart.strong.modular.expect | 71 ++++ ..._in_initializer.dart.strong.outline.expect | 19 ++ ...initializer.dart.strong.transformed.expect | 71 ++++ ...in_initializer.dart.textual_outline.expect | 11 + ...lizer.dart.textual_outline_modelled.expect | 11 + .../block_void_receiver.dart | 64 ++++ .../block_void_receiver.dart.strong.expect | 306 ++++++++++++++++++ ...k_void_receiver.dart.strong.modular.expect | 306 ++++++++++++++++++ ...k_void_receiver.dart.strong.outline.expect | 6 + ...id_receiver.dart.strong.transformed.expect | 306 ++++++++++++++++++ ..._void_receiver.dart.textual_outline.expect | 3 + ...eiver.dart.textual_outline_modelled.expect | 3 + .../block_with_parameter.dart | 27 ++ .../block_with_parameter.dart.strong.expect | 75 +++++ ..._with_parameter.dart.strong.modular.expect | 75 +++++ ..._with_parameter.dart.strong.outline.expect | 5 + ...h_parameter.dart.strong.transformed.expect | 75 +++++ ...with_parameter.dart.textual_outline.expect | 1 + ...meter.dart.textual_outline_modelled.expect | 1 + .../block_without_parameter.dart | 34 ++ ...block_without_parameter.dart.strong.expect | 98 ++++++ ...thout_parameter.dart.strong.modular.expect | 98 ++++++ ...thout_parameter.dart.strong.outline.expect | 5 + ...t_parameter.dart.strong.transformed.expect | 98 ++++++ ...hout_parameter.dart.textual_outline.expect | 1 + ...meter.dart.textual_outline_modelled.expect | 1 + .../expression_void_receiver.dart | 8 +- ...xpression_void_receiver.dart.strong.expect | 16 +- ...n_void_receiver.dart.strong.modular.expect | 16 +- ...id_receiver.dart.strong.transformed.expect | 16 +- .../anonymous_methods/block/error_test.dart | 6 +- .../block/null_aware_plain_test.dart | 2 +- 100 files changed, 5684 insertions(+), 98 deletions(-) create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_with_parameter.dart create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_with_parameter.dart.strong.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_with_parameter.dart.strong.modular.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_with_parameter.dart.strong.outline.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_with_parameter.dart.strong.transformed.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_with_parameter.dart.textual_outline.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_with_parameter.dart.textual_outline_modelled.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_without_parameter.dart create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_without_parameter.dart.strong.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_without_parameter.dart.strong.modular.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_without_parameter.dart.strong.outline.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_without_parameter.dart.strong.transformed.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_without_parameter.dart.textual_outline.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_without_parameter.dart.textual_outline_modelled.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_with_parameter.dart create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_with_parameter.dart.strong.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_with_parameter.dart.strong.modular.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_with_parameter.dart.strong.outline.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_with_parameter.dart.strong.transformed.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_with_parameter.dart.textual_outline.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_with_parameter.dart.textual_outline_modelled.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_without_parameter.dart create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_without_parameter.dart.strong.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_without_parameter.dart.strong.modular.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_without_parameter.dart.strong.outline.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_without_parameter.dart.strong.transformed.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_without_parameter.dart.textual_outline.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_without_parameter.dart.textual_outline_modelled.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_typed.dart create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_typed.dart.strong.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_typed.dart.strong.modular.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_typed.dart.strong.outline.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_typed.dart.strong.transformed.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_typed.dart.textual_outline.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_typed.dart.textual_outline_modelled.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart.strong.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart.strong.modular.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart.strong.outline.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart.strong.transformed.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart.textual_outline.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart.textual_outline_modelled.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_extension_method.dart create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_extension_method.dart.strong.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_extension_method.dart.strong.modular.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_extension_method.dart.strong.outline.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_extension_method.dart.strong.transformed.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_extension_method.dart.textual_outline.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_extension_method.dart.textual_outline_modelled.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_with_parameter.dart create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_with_parameter.dart.strong.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_with_parameter.dart.strong.modular.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_with_parameter.dart.strong.outline.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_with_parameter.dart.strong.transformed.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_with_parameter.dart.textual_outline.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_with_parameter.dart.textual_outline_modelled.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_without_parameter.dart create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_without_parameter.dart.strong.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_without_parameter.dart.strong.modular.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_without_parameter.dart.strong.outline.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_without_parameter.dart.strong.transformed.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_without_parameter.dart.textual_outline.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_without_parameter.dart.textual_outline_modelled.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_this_in_initializer.dart create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_this_in_initializer.dart.strong.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_this_in_initializer.dart.strong.modular.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_this_in_initializer.dart.strong.outline.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_this_in_initializer.dart.strong.transformed.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_this_in_initializer.dart.textual_outline.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_this_in_initializer.dart.textual_outline_modelled.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart.strong.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart.strong.modular.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart.strong.outline.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart.strong.transformed.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart.textual_outline.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart.textual_outline_modelled.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_with_parameter.dart create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_with_parameter.dart.strong.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_with_parameter.dart.strong.modular.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_with_parameter.dart.strong.outline.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_with_parameter.dart.strong.transformed.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_with_parameter.dart.textual_outline.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_with_parameter.dart.textual_outline_modelled.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_without_parameter.dart create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_without_parameter.dart.strong.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_without_parameter.dart.strong.modular.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_without_parameter.dart.strong.outline.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_without_parameter.dart.strong.transformed.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_without_parameter.dart.textual_outline.expect create mode 100644 pkg/front_end/testcases/coverage/anonymous_methods/block_without_parameter.dart.textual_outline_modelled.expect diff --git a/pkg/front_end/lib/src/kernel/body_builder.dart b/pkg/front_end/lib/src/kernel/body_builder.dart index 81a35a730c4..7fa291ce1ab 100644 --- a/pkg/front_end/lib/src/kernel/body_builder.dart +++ b/pkg/front_end/lib/src/kernel/body_builder.dart @@ -3178,7 +3178,9 @@ class BodyBuilderImpl extends StackListenerImpl ) { debugEvent("ReturnStatement"); Expression? expression = hasExpression ? popForValue() : null; - if (expression != null && inConstructor) { + if (expression != null && + inConstructor && + _parameterlessAnonymousMethodDepth == 0) { push( buildProblemStatement( diag.constructorWithReturnType, @@ -8123,73 +8125,50 @@ class BodyBuilderImpl extends StackListenerImpl exitLocalScope(expectedScopeKinds: const [LocalScopeKind.formals]); } + Expression? bodyExpr; if (isExpression) { - Expression bodyExpr; - Expression receiver; - Variable variable; + bodyExpr = toValue(body); + } - bool isImplicitlyTyped; - int typeOffset; - if (formals is FormalParameters && - formals.parameters?.length == 1 && - formals.parameters![0].isRequiredPositional) { - bodyExpr = toValue(body); - receiver = popForValue(); - FormalParameterBuilder formal = formals.parameters![0]; + Expression receiver; + Variable variable; + bool isImplicitlyTyped; + int typeOffset; - // Build the variable declaration. - variable = formal.build(libraryBuilder); - variable.initializer = receiver; - variable.initializer!.parent = variable; + if (formals is FormalParameters && + formals.parameters?.length == 1 && + formals.parameters![0].isRequiredPositional) { + receiver = popForValue(); + FormalParameterBuilder formal = formals.parameters![0]; - isImplicitlyTyped = false; - if (variable is InternalVariable) { - isImplicitlyTyped = (variable as InternalVariable).isImplicitlyTyped; - } - typeOffset = formal.type.charOffset ?? variable.fileOffset; - } else if (formals == null) { - bodyExpr = toValue(body); - variable = _thisVariables.pop(); - _parameterlessAnonymousMethodDepth--; - receiver = popForValue(); - isImplicitlyTyped = true; - typeOffset = variable.fileOffset; - } else { - FormalParameters formalParameters = formals as FormalParameters; - addProblem( - diag.anonymousMethodWrongParameterList, - formalParameters.charOffset, - formalParameters.length, - ); - popForValue(); - bodyExpr = toValue(body); - Expression result = new InvalidExpression( - "An anonymous method must have a single mandatory positional " - "parameter, or no parameter list at all", - )..fileOffset = offsetForToken(beginToken); - push(result); - assignedVariables.endNode( - result, - isClosureOrLateVariableInitializer: false, - ); - return; + // Build the variable declaration. + variable = formal.build(libraryBuilder); + variable.initializer = receiver; + variable.initializer!.parent = variable; + + isImplicitlyTyped = false; + if (variable is InternalVariable) { + isImplicitlyTyped = (variable as InternalVariable).isImplicitlyTyped; } - int variableOffset = variable.initializer!.fileOffset; - - // Build the result expression. - bool isNullAware = - beginToken.lexeme == '?.' || beginToken.lexeme == '?..'; - bool isCascade = beginToken.lexeme == '..' || beginToken.lexeme == '?..'; - - Expression result = new AnonymousMethodExpression( - variable, - bodyExpr, - isImplicitlyTyped: isImplicitlyTyped, - isNullAware: isNullAware, - isCascade: isCascade, - typeOffset: typeOffset, - )..fileOffset = variableOffset; - + typeOffset = formal.type.charOffset ?? variable.fileOffset; + } else if (formals == null) { + variable = _thisVariables.pop(); + _parameterlessAnonymousMethodDepth--; + receiver = popForValue(); + isImplicitlyTyped = true; + typeOffset = variable.fileOffset; + } else { + FormalParameters formalParameters = formals as FormalParameters; + addProblem( + diag.anonymousMethodWrongParameterList, + formalParameters.charOffset, + formalParameters.length, + ); + popForValue(); + Expression result = new InvalidExpression( + "An anonymous method must have a single mandatory positional " + "parameter, or no parameter list at all", + )..fileOffset = offsetForToken(beginToken); push(result); assignedVariables.endNode( result, @@ -8197,9 +8176,39 @@ class BodyBuilderImpl extends StackListenerImpl ); return; } + int variableOffset = variable.initializer!.fileOffset; - // Coverage-ignore-block(suite): Not run. - throw new UnimplementedError("endAnonymousMethodInvocation other cases"); + // Build the result expression. + bool isNullAware = beginToken.lexeme == '?.' || beginToken.lexeme == '?..'; + bool isCascade = beginToken.lexeme == '..' || beginToken.lexeme == '?..'; + + Expression result; + if (isExpression) { + result = new AnonymousMethodExpression( + variable, + bodyExpr!, + isImplicitlyTyped: isImplicitlyTyped, + isNullAware: isNullAware, + isCascade: isCascade, + typeOffset: typeOffset, + )..fileOffset = variableOffset; + } else { + Statement bodyStatement = body as Statement; + result = new AnonymousMethodBlock( + variable, + bodyStatement, + isImplicitlyTyped: isImplicitlyTyped, + isNullAware: isNullAware, + isCascade: isCascade, + typeOffset: typeOffset, + )..fileOffset = variableOffset; + } + + push(result); + assignedVariables.endNode( + result, + isClosureOrLateVariableInitializer: false, + ); } @override @@ -9732,7 +9741,9 @@ class BodyBuilderImpl extends StackListenerImpl if (target == null) { push( problemInLoopOrSwitch = buildProblemStatement( - diag.continueWithoutLabelInCase, + _switchScope != null + ? diag.continueWithoutLabelInCase + : diag.continueOutsideOfLoop, continueKeyword.charOffset, length: continueKeyword.length, ), diff --git a/pkg/front_end/lib/src/kernel/internal_ast.dart b/pkg/front_end/lib/src/kernel/internal_ast.dart index 8db646283bf..7a833d420bc 100644 --- a/pkg/front_end/lib/src/kernel/internal_ast.dart +++ b/pkg/front_end/lib/src/kernel/internal_ast.dart @@ -558,6 +558,51 @@ class AnonymousMethodExpression extends InternalExpression { } } +/// Internal expression representing an anonymous block method invocation. +class AnonymousMethodBlock extends InternalExpression { + Variable variable; + Statement body; + final bool isCascade; + final bool isImplicitlyTyped; + final bool isNullAware; + final bool isParameterless; + final int typeOffset; + + AnonymousMethodBlock( + this.variable, + this.body, { + required this.isImplicitlyTyped, + required this.isNullAware, + required this.isCascade, + required this.typeOffset, + }) : isParameterless = variable.isSynthesized { + variable.parent = this; + body.parent = this; + } + + @override + ExpressionInferenceResult acceptInference( + InferenceVisitorImpl visitor, + DartType typeContext, + ) { + return visitor.visitAnonymousMethodBlock(this, typeContext); + } + + @override + String toString() { + return "AnonymousMethodBlock(${toStringInternal()})"; + } + + @override + // Coverage-ignore(suite): Not run. + void toTextInternal(AstPrinter printer) { + printer.write('let '); + printer.writeVariableInitialization(variable); + printer.write(' in '); + printer.writeStatement(body); + } +} + /// Internal expression representing a deferred check. // TODO(johnniwinther): Change the representation to be direct and perform // the [Let] encoding in the replacement. diff --git a/pkg/front_end/lib/src/type_inference/inference_visitor.dart b/pkg/front_end/lib/src/type_inference/inference_visitor.dart index 6aab8cedc19..572c5ffdc29 100644 --- a/pkg/front_end/lib/src/type_inference/inference_visitor.dart +++ b/pkg/front_end/lib/src/type_inference/inference_visitor.dart @@ -17,6 +17,7 @@ import 'package:_fe_analyzer_shared/src/types/shared_type.dart'; import 'package:_fe_analyzer_shared/src/util/null_value.dart'; import 'package:_fe_analyzer_shared/src/util/stack_checker.dart'; import 'package:_fe_analyzer_shared/src/util/value_kind.dart'; +import 'package:front_end/src/util/local_stack.dart'; import 'package:kernel/ast.dart'; import 'package:kernel/names.dart'; import 'package:kernel/src/non_null.dart'; @@ -104,6 +105,25 @@ abstract class InferenceVisitor { InitializerInferenceResult inferInitializer(Initializer initializer); } +abstract class ReturnContext {} + +class StandardReturnContext implements ReturnContext { + const StandardReturnContext(); +} + +class AnonymousMethodReturnContext extends ReturnContext { + final Variable resultVariable; + final LabeledStatement label; + final List returnTypes = []; + final DartType typeContext; + + AnonymousMethodReturnContext({ + required this.resultVariable, + required this.label, + required this.typeContext, + }); +} + class InferenceVisitorImpl extends InferenceVisitorBase with TypeAnalyzer< @@ -141,6 +161,11 @@ class InferenceVisitorImpl extends InferenceVisitorBase /// inside a closure. BodyInferenceContext? _bodyContext; + /// Stack for return contexts. + final LocalStack _returnContexts = new LocalStack([]); + + ReturnContext? get returnContext => _returnContexts.currentOrNull; + /// If a switch statement is being visited and the type being switched on is a /// (possibly nullable) enumerated type, the set of enum values for which no /// case head has been seen yet; otherwise `null`. @@ -3522,6 +3547,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase _inTryOrLocalFunction = true; Variable variable = node.variable; flowAnalysis.functionExpression_begin(node); + _returnContexts.push(const StandardReturnContext()); inferMetadata(this, variable); DartType? returnContext = node.hasImplicitReturnType ? null @@ -3546,6 +3572,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase initialized: true, ); flowAnalysis.functionExpression_end(); + _returnContexts.pop(); _inTryOrLocalFunction = oldInTryOrLocalFunction; return const StatementInferenceResult(); } @@ -3612,6 +3639,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase bool oldInTryOrLocalFunction = _inTryOrLocalFunction; _inTryOrLocalFunction = true; flowAnalysis.functionExpression_begin(node); + _returnContexts.push(const StandardReturnContext()); FunctionType inferredType = visitFunctionNode( node.function, typeContext, @@ -3624,6 +3652,7 @@ class InferenceVisitorImpl extends InferenceVisitorBase inferredType.returnType; } flowAnalysis.functionExpression_end(); + _returnContexts.pop(); _inTryOrLocalFunction = oldInTryOrLocalFunction; if (scopeProviderInfo != null) { _contextAllocationStrategy.exitScopeProvider(scopeProviderInfo); @@ -11918,6 +11947,163 @@ class InferenceVisitorImpl extends InferenceVisitorBase return new ExpressionInferenceResult(inferredType, replacement); } + ExpressionInferenceResult visitAnonymousMethodBlock( + AnonymousMethodBlock node, + DartType typeContext, + ) { + Variable resultVar = new Variable(null, isSynthesized: true) + ..fileOffset = node.fileOffset; + LabeledStatement label = new LabeledStatement(null) + ..fileOffset = node.fileOffset; + + AnonymousMethodReturnContext context = new AnonymousMethodReturnContext( + resultVariable: resultVar, + label: label, + typeContext: typeContext, + ); + _returnContexts.push(context); + + DartType variableType = node.variable.type; + ExpressionInferenceResult initializerResult = inferExpression( + node.variable.initializer!, + const UnknownType(), + continueNullShorting: true, + ); + + Expression initializer = initializerResult.expression; + DartType initializerType = initializerResult.inferredType; + + if (initializerType is VoidType) { + initializer = problemReporting.wrapInProblem( + compilerContext: compilerContext, + expression: initializer, + message: diag.voidExpression, + fileUri: fileUri, + fileOffset: initializer.fileOffset, + length: noLength, + ); + } + + if (node.isImplicitlyTyped) { + node.variable.type = node.isNullAware + ? initializerType.toNonNull() + : initializerType; + } else { + DartType checkedType = node.isNullAware + ? initializerType.toNonNull() + : initializerType; + if (!isAssignable(variableType, checkedType)) { + initializer = wrapUnassignableExpression( + initializer, + checkedType, + variableType, + diag.anonymousMethodWrongParameterTypeCfe.withArguments( + receiverType: checkedType, + parameterType: variableType, + ), + fileOffset: node.typeOffset, + ); + } + } + node.variable.initializer = initializer..parent = node.variable; + + flowAnalysis.declare( + node.variable, + new SharedTypeView(node.variable.type), + initialized: false, + ); + flowAnalysis.initialize( + node.variable, + new SharedTypeView(node.variable.type), + flowAnalysis.getExpressionInfo(node.variable.initializer!), + isFinal: false, + isLate: false, + isImplicitlyTyped: node.isImplicitlyTyped, + inheritPromotableProperties: node.isParameterless, + ); + bool isNullAwareAccess = node.isNullAware && _enclosingCascade == null; + if (node.isNullAware) { + Expression receiverExpr = node.variable.initializer!; + Variable? tempVar; + + if (isNullAwareAccess) { + tempVar = + new Variable(null, initializer: receiverExpr, isSynthesized: true) + ..type = initializerType + ..fileOffset = node.fileOffset; + receiverExpr = new VariableGet(tempVar); + } + + node.variable.initializer = + new AsExpression(receiverExpr, node.variable.type) + ..fileOffset = node.fileOffset + ..parent = node.variable; + + if (isNullAwareAccess) { + startNullShorting( + new NullAwareGuard(tempVar!, node.variable.fileOffset, this), + flowAnalysis.getExpressionInfo(tempVar.initializer!), + new SharedTypeView(tempVar.type), + guardVariable: tempVar, + ); + } + } + + if (node.isParameterless) { + flow.thisBinding_begin( + flowAnalysis.getExpressionInfo(node.variable.initializer!), + ); + } + + flowAnalysis.labeledStatement_begin(label); + StatementInferenceResult bodyResult = inferStatement(node.body); + bool isReachable = flowAnalysis.isReachable; + flowAnalysis.labeledStatement_end(); + + if (node.isParameterless) { + flow.thisBinding_end(); + } + + _returnContexts.pop(); + + Statement body = bodyResult.hasChanged ? bodyResult.statement : node.body; + label.body = body..parent = label; + + DartType inferredType = isReachable + ? const NullType() + : const NeverType.nonNullable(); + for (DartType returnType in context.returnTypes) { + inferredType = typeSchemaEnvironment.getStandardUpperBound( + inferredType, + returnType, + ); + } + resultVar.type = inferredType; + + if (node.isCascade) { + inferredType = initializerType; + } + + Block block = new Block([ + extern.createVariableStatement( + extern.createVariableDeclaration(node.variable), + ), + extern.createVariableStatement( + extern.createVariableDeclaration(resultVar), + ), + label, + ])..fileOffset = node.fileOffset; + + Expression replacement = new BlockExpression( + block, + node.isCascade + ? new VariableGet(node.variable) + : new VariableGet(resultVar), + )..fileOffset = node.fileOffset; + + return new ExpressionInferenceResult(inferredType, replacement); + } + ExpressionInferenceResult visitPropertySet( PropertySet node, DartType typeContext, @@ -12307,6 +12493,34 @@ class InferenceVisitorImpl extends InferenceVisitorBase StatementInferenceResult visitReturnStatement( covariant ReturnStatementImpl node, ) { + ReturnContext? context = returnContext; + if (context is AnonymousMethodReturnContext) { + Expression expression = + node.expression ?? (new NullLiteral()..fileOffset = node.fileOffset); + ExpressionInferenceResult expressionResult = inferExpression( + expression, + context.typeContext, + isVoidAllowed: true, + ); + context.returnTypes.add(expressionResult.inferredType); + + VariableSet assignment = new VariableSet( + context.resultVariable, + expressionResult.expression, + )..fileOffset = node.fileOffset; + BreakStatement breakStmt = new BreakStatement(context.label) + ..fileOffset = node.fileOffset; + + flowAnalysis.handleBreak(context.label); + + Statement replacement = new Block([ + new ExpressionStatement(assignment)..fileOffset = node.fileOffset, + breakStmt, + ])..fileOffset = node.fileOffset; + + return new StatementInferenceResult.single(replacement); + } + DartType typeContext = bodyContext.returnContext; DartType inferredType; Variable? thisVariable = _constructorContext?.thisVariable; diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_with_parameter.dart b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_with_parameter.dart new file mode 100644 index 00000000000..09e8ec4da31 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_with_parameter.dart @@ -0,0 +1,29 @@ +// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +int? i = null; + +void main() { + i?..(p) { + 1; + return; + }; + i?..(p) { + p; + return; + }; + i?..(p) { + p.isEven; + return; + }; + i?..(p) { + return 1; + }; + i?..(p) { + return p; + }; + i?..(p) { + return p.isEven; + }; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_with_parameter.dart.strong.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_with_parameter.dart.strong.expect new file mode 100644 index 00000000000..4a56546169f --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_with_parameter.dart.strong.expect @@ -0,0 +1,88 @@ +library; +import self as self; +import "dart:core" as core; + +static field core::int? i = null; +static method main() → void { + let final core::int? #t1 = self::i in #t1 == null ?{core::int?} null : block { + { + core::int p = #t1{core::int} as core::int; + Null #t2; + #L1: + { + 1; + { + #t2 = null; + break #L1; + } + } + } + } =>#t1; + let final core::int? #t3 = self::i in #t3 == null ?{core::int?} null : block { + { + core::int p = #t3{core::int} as core::int; + Null #t4; + #L2: + { + p; + { + #t4 = null; + break #L2; + } + } + } + } =>#t3; + let final core::int? #t5 = self::i in #t5 == null ?{core::int?} null : block { + { + core::int p = #t5{core::int} as core::int; + Null #t6; + #L3: + { + p.{core::int::isEven}{core::bool}; + { + #t6 = null; + break #L3; + } + } + } + } =>#t5; + let final core::int? #t7 = self::i in #t7 == null ?{core::int?} null : block { + { + core::int p = #t7{core::int} as core::int; + core::int #t8; + #L4: + { + { + #t8 = 1; + break #L4; + } + } + } + } =>#t7; + let final core::int? #t9 = self::i in #t9 == null ?{core::int?} null : block { + { + core::int p = #t9{core::int} as core::int; + core::int #t10; + #L5: + { + { + #t10 = p; + break #L5; + } + } + } + } =>#t9; + let final core::int? #t11 = self::i in #t11 == null ?{core::int?} null : block { + { + core::int p = #t11{core::int} as core::int; + core::bool #t12; + #L6: + { + { + #t12 = p.{core::int::isEven}{core::bool}; + break #L6; + } + } + } + } =>#t11; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_with_parameter.dart.strong.modular.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_with_parameter.dart.strong.modular.expect new file mode 100644 index 00000000000..4a56546169f --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_with_parameter.dart.strong.modular.expect @@ -0,0 +1,88 @@ +library; +import self as self; +import "dart:core" as core; + +static field core::int? i = null; +static method main() → void { + let final core::int? #t1 = self::i in #t1 == null ?{core::int?} null : block { + { + core::int p = #t1{core::int} as core::int; + Null #t2; + #L1: + { + 1; + { + #t2 = null; + break #L1; + } + } + } + } =>#t1; + let final core::int? #t3 = self::i in #t3 == null ?{core::int?} null : block { + { + core::int p = #t3{core::int} as core::int; + Null #t4; + #L2: + { + p; + { + #t4 = null; + break #L2; + } + } + } + } =>#t3; + let final core::int? #t5 = self::i in #t5 == null ?{core::int?} null : block { + { + core::int p = #t5{core::int} as core::int; + Null #t6; + #L3: + { + p.{core::int::isEven}{core::bool}; + { + #t6 = null; + break #L3; + } + } + } + } =>#t5; + let final core::int? #t7 = self::i in #t7 == null ?{core::int?} null : block { + { + core::int p = #t7{core::int} as core::int; + core::int #t8; + #L4: + { + { + #t8 = 1; + break #L4; + } + } + } + } =>#t7; + let final core::int? #t9 = self::i in #t9 == null ?{core::int?} null : block { + { + core::int p = #t9{core::int} as core::int; + core::int #t10; + #L5: + { + { + #t10 = p; + break #L5; + } + } + } + } =>#t9; + let final core::int? #t11 = self::i in #t11 == null ?{core::int?} null : block { + { + core::int p = #t11{core::int} as core::int; + core::bool #t12; + #L6: + { + { + #t12 = p.{core::int::isEven}{core::bool}; + break #L6; + } + } + } + } =>#t11; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_with_parameter.dart.strong.outline.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_with_parameter.dart.strong.outline.expect new file mode 100644 index 00000000000..c17141d4913 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_with_parameter.dart.strong.outline.expect @@ -0,0 +1,7 @@ +library; +import self as self; +import "dart:core" as core; + +static field core::int? i; +static method main() → void + ; diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_with_parameter.dart.strong.transformed.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_with_parameter.dart.strong.transformed.expect new file mode 100644 index 00000000000..4c9e00f2588 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_with_parameter.dart.strong.transformed.expect @@ -0,0 +1,88 @@ +library; +import self as self; +import "dart:core" as core; + +static field core::int? i = null; +static method main() → void { + let final core::int? #t1 = self::i in #t1 == null ?{core::int?} null : block { + { + core::int p = #t1{core::int} as{Unchecked} core::int; + Null #t2; + #L1: + { + 1; + { + #t2 = null; + break #L1; + } + } + } + } =>#t1; + let final core::int? #t3 = self::i in #t3 == null ?{core::int?} null : block { + { + core::int p = #t3{core::int} as{Unchecked} core::int; + Null #t4; + #L2: + { + p; + { + #t4 = null; + break #L2; + } + } + } + } =>#t3; + let final core::int? #t5 = self::i in #t5 == null ?{core::int?} null : block { + { + core::int p = #t5{core::int} as{Unchecked} core::int; + Null #t6; + #L3: + { + p.{core::int::isEven}{core::bool}; + { + #t6 = null; + break #L3; + } + } + } + } =>#t5; + let final core::int? #t7 = self::i in #t7 == null ?{core::int?} null : block { + { + core::int p = #t7{core::int} as{Unchecked} core::int; + core::int #t8; + #L4: + { + { + #t8 = 1; + break #L4; + } + } + } + } =>#t7; + let final core::int? #t9 = self::i in #t9 == null ?{core::int?} null : block { + { + core::int p = #t9{core::int} as{Unchecked} core::int; + core::int #t10; + #L5: + { + { + #t10 = p; + break #L5; + } + } + } + } =>#t9; + let final core::int? #t11 = self::i in #t11 == null ?{core::int?} null : block { + { + core::int p = #t11{core::int} as{Unchecked} core::int; + core::bool #t12; + #L6: + { + { + #t12 = p.{core::int::isEven}{core::bool}; + break #L6; + } + } + } + } =>#t11; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_with_parameter.dart.textual_outline.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_with_parameter.dart.textual_outline.expect new file mode 100644 index 00000000000..eedd821d211 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_with_parameter.dart.textual_outline.expect @@ -0,0 +1,3 @@ +int? i = null; + +void main() {} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_with_parameter.dart.textual_outline_modelled.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_with_parameter.dart.textual_outline_modelled.expect new file mode 100644 index 00000000000..eedd821d211 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_with_parameter.dart.textual_outline_modelled.expect @@ -0,0 +1,3 @@ +int? i = null; + +void main() {} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_without_parameter.dart b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_without_parameter.dart new file mode 100644 index 00000000000..d132360a2d7 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_without_parameter.dart @@ -0,0 +1,36 @@ +// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +int? i = null; + +void main() { + i?..{ + 1; + return; + }; + i?..{ + this; + return; + }; + i?..{ + this.isEven; + return; + }; + i?..{ + isEven; + return; + }; + i?..{ + return 1; + }; + i?..{ + return this; + }; + i?..{ + return this.isEven; + }; + i?..{ + return isEven; + }; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_without_parameter.dart.strong.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_without_parameter.dart.strong.expect new file mode 100644 index 00000000000..03961f9836a --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_without_parameter.dart.strong.expect @@ -0,0 +1,115 @@ +library; +import self as self; +import "dart:core" as core; + +static field core::int? i = null; +static method main() → void { + let final core::int? #t1 = self::i in #t1 == null ?{core::int?} null : block { + { + final synthesized core::int anonymous#this = #t1{core::int} as core::int; + Null #t2; + #L1: + { + 1; + { + #t2 = null; + break #L1; + } + } + } + } =>#t1; + let final core::int? #t3 = self::i in #t3 == null ?{core::int?} null : block { + { + final synthesized core::int anonymous#this = #t3{core::int} as core::int; + Null #t4; + #L2: + { + anonymous#this; + { + #t4 = null; + break #L2; + } + } + } + } =>#t3; + let final core::int? #t5 = self::i in #t5 == null ?{core::int?} null : block { + { + final synthesized core::int anonymous#this = #t5{core::int} as core::int; + Null #t6; + #L3: + { + anonymous#this.{core::int::isEven}{core::bool}; + { + #t6 = null; + break #L3; + } + } + } + } =>#t5; + let final core::int? #t7 = self::i in #t7 == null ?{core::int?} null : block { + { + final synthesized core::int anonymous#this = #t7{core::int} as core::int; + Null #t8; + #L4: + { + anonymous#this.{core::int::isEven}{core::bool}; + { + #t8 = null; + break #L4; + } + } + } + } =>#t7; + let final core::int? #t9 = self::i in #t9 == null ?{core::int?} null : block { + { + final synthesized core::int anonymous#this = #t9{core::int} as core::int; + core::int #t10; + #L5: + { + { + #t10 = 1; + break #L5; + } + } + } + } =>#t9; + let final core::int? #t11 = self::i in #t11 == null ?{core::int?} null : block { + { + final synthesized core::int anonymous#this = #t11{core::int} as core::int; + core::int #t12; + #L6: + { + { + #t12 = anonymous#this; + break #L6; + } + } + } + } =>#t11; + let final core::int? #t13 = self::i in #t13 == null ?{core::int?} null : block { + { + final synthesized core::int anonymous#this = #t13{core::int} as core::int; + core::bool #t14; + #L7: + { + { + #t14 = anonymous#this.{core::int::isEven}{core::bool}; + break #L7; + } + } + } + } =>#t13; + let final core::int? #t15 = self::i in #t15 == null ?{core::int?} null : block { + { + final synthesized core::int anonymous#this = #t15{core::int} as core::int; + core::bool #t16; + #L8: + { + { + #t16 = anonymous#this.{core::int::isEven}{core::bool}; + break #L8; + } + } + } + } =>#t15; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_without_parameter.dart.strong.modular.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_without_parameter.dart.strong.modular.expect new file mode 100644 index 00000000000..03961f9836a --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_without_parameter.dart.strong.modular.expect @@ -0,0 +1,115 @@ +library; +import self as self; +import "dart:core" as core; + +static field core::int? i = null; +static method main() → void { + let final core::int? #t1 = self::i in #t1 == null ?{core::int?} null : block { + { + final synthesized core::int anonymous#this = #t1{core::int} as core::int; + Null #t2; + #L1: + { + 1; + { + #t2 = null; + break #L1; + } + } + } + } =>#t1; + let final core::int? #t3 = self::i in #t3 == null ?{core::int?} null : block { + { + final synthesized core::int anonymous#this = #t3{core::int} as core::int; + Null #t4; + #L2: + { + anonymous#this; + { + #t4 = null; + break #L2; + } + } + } + } =>#t3; + let final core::int? #t5 = self::i in #t5 == null ?{core::int?} null : block { + { + final synthesized core::int anonymous#this = #t5{core::int} as core::int; + Null #t6; + #L3: + { + anonymous#this.{core::int::isEven}{core::bool}; + { + #t6 = null; + break #L3; + } + } + } + } =>#t5; + let final core::int? #t7 = self::i in #t7 == null ?{core::int?} null : block { + { + final synthesized core::int anonymous#this = #t7{core::int} as core::int; + Null #t8; + #L4: + { + anonymous#this.{core::int::isEven}{core::bool}; + { + #t8 = null; + break #L4; + } + } + } + } =>#t7; + let final core::int? #t9 = self::i in #t9 == null ?{core::int?} null : block { + { + final synthesized core::int anonymous#this = #t9{core::int} as core::int; + core::int #t10; + #L5: + { + { + #t10 = 1; + break #L5; + } + } + } + } =>#t9; + let final core::int? #t11 = self::i in #t11 == null ?{core::int?} null : block { + { + final synthesized core::int anonymous#this = #t11{core::int} as core::int; + core::int #t12; + #L6: + { + { + #t12 = anonymous#this; + break #L6; + } + } + } + } =>#t11; + let final core::int? #t13 = self::i in #t13 == null ?{core::int?} null : block { + { + final synthesized core::int anonymous#this = #t13{core::int} as core::int; + core::bool #t14; + #L7: + { + { + #t14 = anonymous#this.{core::int::isEven}{core::bool}; + break #L7; + } + } + } + } =>#t13; + let final core::int? #t15 = self::i in #t15 == null ?{core::int?} null : block { + { + final synthesized core::int anonymous#this = #t15{core::int} as core::int; + core::bool #t16; + #L8: + { + { + #t16 = anonymous#this.{core::int::isEven}{core::bool}; + break #L8; + } + } + } + } =>#t15; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_without_parameter.dart.strong.outline.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_without_parameter.dart.strong.outline.expect new file mode 100644 index 00000000000..c17141d4913 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_without_parameter.dart.strong.outline.expect @@ -0,0 +1,7 @@ +library; +import self as self; +import "dart:core" as core; + +static field core::int? i; +static method main() → void + ; diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_without_parameter.dart.strong.transformed.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_without_parameter.dart.strong.transformed.expect new file mode 100644 index 00000000000..643f84ab181 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_without_parameter.dart.strong.transformed.expect @@ -0,0 +1,115 @@ +library; +import self as self; +import "dart:core" as core; + +static field core::int? i = null; +static method main() → void { + let final core::int? #t1 = self::i in #t1 == null ?{core::int?} null : block { + { + final synthesized core::int anonymous#this = #t1{core::int} as{Unchecked} core::int; + Null #t2; + #L1: + { + 1; + { + #t2 = null; + break #L1; + } + } + } + } =>#t1; + let final core::int? #t3 = self::i in #t3 == null ?{core::int?} null : block { + { + final synthesized core::int anonymous#this = #t3{core::int} as{Unchecked} core::int; + Null #t4; + #L2: + { + anonymous#this; + { + #t4 = null; + break #L2; + } + } + } + } =>#t3; + let final core::int? #t5 = self::i in #t5 == null ?{core::int?} null : block { + { + final synthesized core::int anonymous#this = #t5{core::int} as{Unchecked} core::int; + Null #t6; + #L3: + { + anonymous#this.{core::int::isEven}{core::bool}; + { + #t6 = null; + break #L3; + } + } + } + } =>#t5; + let final core::int? #t7 = self::i in #t7 == null ?{core::int?} null : block { + { + final synthesized core::int anonymous#this = #t7{core::int} as{Unchecked} core::int; + Null #t8; + #L4: + { + anonymous#this.{core::int::isEven}{core::bool}; + { + #t8 = null; + break #L4; + } + } + } + } =>#t7; + let final core::int? #t9 = self::i in #t9 == null ?{core::int?} null : block { + { + final synthesized core::int anonymous#this = #t9{core::int} as{Unchecked} core::int; + core::int #t10; + #L5: + { + { + #t10 = 1; + break #L5; + } + } + } + } =>#t9; + let final core::int? #t11 = self::i in #t11 == null ?{core::int?} null : block { + { + final synthesized core::int anonymous#this = #t11{core::int} as{Unchecked} core::int; + core::int #t12; + #L6: + { + { + #t12 = anonymous#this; + break #L6; + } + } + } + } =>#t11; + let final core::int? #t13 = self::i in #t13 == null ?{core::int?} null : block { + { + final synthesized core::int anonymous#this = #t13{core::int} as{Unchecked} core::int; + core::bool #t14; + #L7: + { + { + #t14 = anonymous#this.{core::int::isEven}{core::bool}; + break #L7; + } + } + } + } =>#t13; + let final core::int? #t15 = self::i in #t15 == null ?{core::int?} null : block { + { + final synthesized core::int anonymous#this = #t15{core::int} as{Unchecked} core::int; + core::bool #t16; + #L8: + { + { + #t16 = anonymous#this.{core::int::isEven}{core::bool}; + break #L8; + } + } + } + } =>#t15; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_without_parameter.dart.textual_outline.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_without_parameter.dart.textual_outline.expect new file mode 100644 index 00000000000..eedd821d211 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_without_parameter.dart.textual_outline.expect @@ -0,0 +1,3 @@ +int? i = null; + +void main() {} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_without_parameter.dart.textual_outline_modelled.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_without_parameter.dart.textual_outline_modelled.expect new file mode 100644 index 00000000000..eedd821d211 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_null_aware_without_parameter.dart.textual_outline_modelled.expect @@ -0,0 +1,3 @@ +int? i = null; + +void main() {} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_with_parameter.dart b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_with_parameter.dart new file mode 100644 index 00000000000..1ef65b73687 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_with_parameter.dart @@ -0,0 +1,27 @@ +// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +void main() { + 1..(p) { + 1; + return; + }; + 1..(p) { + p; + return; + }; + 1..(p) { + p.isEven; + return; + }; + 1..(p) { + return 1; + }; + 1..(p) { + return p; + }; + 1..(p) { + return p.isEven; + }; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_with_parameter.dart.strong.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_with_parameter.dart.strong.expect new file mode 100644 index 00000000000..eb1c723eaad --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_with_parameter.dart.strong.expect @@ -0,0 +1,87 @@ +library; +import self as self; +import "dart:core" as core; + +static method main() → void { + let final core::int #t1 = 1 in block { + { + core::int p = #t1; + Null #t2; + #L1: + { + 1; + { + #t2 = null; + break #L1; + } + } + } + } =>#t1; + let final core::int #t3 = 1 in block { + { + core::int p = #t3; + Null #t4; + #L2: + { + p; + { + #t4 = null; + break #L2; + } + } + } + } =>#t3; + let final core::int #t5 = 1 in block { + { + core::int p = #t5; + Null #t6; + #L3: + { + p.{core::int::isEven}{core::bool}; + { + #t6 = null; + break #L3; + } + } + } + } =>#t5; + let final core::int #t7 = 1 in block { + { + core::int p = #t7; + core::int #t8; + #L4: + { + { + #t8 = 1; + break #L4; + } + } + } + } =>#t7; + let final core::int #t9 = 1 in block { + { + core::int p = #t9; + core::int #t10; + #L5: + { + { + #t10 = p; + break #L5; + } + } + } + } =>#t9; + let final core::int #t11 = 1 in block { + { + core::int p = #t11; + core::bool #t12; + #L6: + { + { + #t12 = p.{core::int::isEven}{core::bool}; + break #L6; + } + } + } + } =>#t11; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_with_parameter.dart.strong.modular.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_with_parameter.dart.strong.modular.expect new file mode 100644 index 00000000000..eb1c723eaad --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_with_parameter.dart.strong.modular.expect @@ -0,0 +1,87 @@ +library; +import self as self; +import "dart:core" as core; + +static method main() → void { + let final core::int #t1 = 1 in block { + { + core::int p = #t1; + Null #t2; + #L1: + { + 1; + { + #t2 = null; + break #L1; + } + } + } + } =>#t1; + let final core::int #t3 = 1 in block { + { + core::int p = #t3; + Null #t4; + #L2: + { + p; + { + #t4 = null; + break #L2; + } + } + } + } =>#t3; + let final core::int #t5 = 1 in block { + { + core::int p = #t5; + Null #t6; + #L3: + { + p.{core::int::isEven}{core::bool}; + { + #t6 = null; + break #L3; + } + } + } + } =>#t5; + let final core::int #t7 = 1 in block { + { + core::int p = #t7; + core::int #t8; + #L4: + { + { + #t8 = 1; + break #L4; + } + } + } + } =>#t7; + let final core::int #t9 = 1 in block { + { + core::int p = #t9; + core::int #t10; + #L5: + { + { + #t10 = p; + break #L5; + } + } + } + } =>#t9; + let final core::int #t11 = 1 in block { + { + core::int p = #t11; + core::bool #t12; + #L6: + { + { + #t12 = p.{core::int::isEven}{core::bool}; + break #L6; + } + } + } + } =>#t11; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_with_parameter.dart.strong.outline.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_with_parameter.dart.strong.outline.expect new file mode 100644 index 00000000000..2982c48b884 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_with_parameter.dart.strong.outline.expect @@ -0,0 +1,5 @@ +library; +import self as self; + +static method main() → void + ; diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_with_parameter.dart.strong.transformed.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_with_parameter.dart.strong.transformed.expect new file mode 100644 index 00000000000..eb806aae0de --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_with_parameter.dart.strong.transformed.expect @@ -0,0 +1,103 @@ +library; +import self as self; +import "dart:core" as core; + +static method main() → void { + let final core::int #t1 = 1 in block { + { + core::int p = #t1; + Null #t2; + #L1: + { + 1; + { + #t2 = null; + break #L1; + } + } + } + } =>#t1; + let final core::int #t3 = 1 in block { + { + core::int p = #t3; + Null #t4; + #L2: + { + p; + { + #t4 = null; + break #L2; + } + } + } + } =>#t3; + let final core::int #t5 = 1 in block { + { + core::int p = #t5; + Null #t6; + #L3: + { + p.{core::int::isEven}{core::bool}; + { + #t6 = null; + break #L3; + } + } + } + } =>#t5; + let final core::int #t7 = 1 in block { + { + core::int p = #t7; + core::int #t8; + #L4: + { + { + #t8 = 1; + break #L4; + } + } + } + } =>#t7; + let final core::int #t9 = 1 in block { + { + core::int p = #t9; + core::int #t10; + #L5: + { + { + #t10 = p; + break #L5; + } + } + } + } =>#t9; + let final core::int #t11 = 1 in block { + { + core::int p = #t11; + core::bool #t12; + #L6: + { + { + #t12 = p.{core::int::isEven}{core::bool}; + break #L6; + } + } + } + } =>#t11; +} + + +Extra constant evaluation status: +Evaluated: VariableGet @ org-dartlang-testcase:///block_cascaded_with_parameter.dart:6:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_cascaded_with_parameter.dart:6:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_cascaded_with_parameter.dart:10:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_cascaded_with_parameter.dart:10:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_cascaded_with_parameter.dart:14:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_cascaded_with_parameter.dart:14:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_cascaded_with_parameter.dart:18:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_cascaded_with_parameter.dart:18:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_cascaded_with_parameter.dart:21:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_cascaded_with_parameter.dart:21:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_cascaded_with_parameter.dart:24:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_cascaded_with_parameter.dart:24:3 -> IntConstant(1) +Extra constant evaluation: evaluated: 36, effectively constant: 12 diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_with_parameter.dart.textual_outline.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_with_parameter.dart.textual_outline.expect new file mode 100644 index 00000000000..ab73b3a234a --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_with_parameter.dart.textual_outline.expect @@ -0,0 +1 @@ +void main() {} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_with_parameter.dart.textual_outline_modelled.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_with_parameter.dart.textual_outline_modelled.expect new file mode 100644 index 00000000000..ab73b3a234a --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_with_parameter.dart.textual_outline_modelled.expect @@ -0,0 +1 @@ +void main() {} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_without_parameter.dart b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_without_parameter.dart new file mode 100644 index 00000000000..1e405bc26b4 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_without_parameter.dart @@ -0,0 +1,34 @@ +// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +void main() { + 1..{ + 1; + return; + }; + 1..{ + this; + return; + }; + 1..{ + this.isEven; + return; + }; + 1..{ + isEven; + return; + }; + 1..{ + return 1; + }; + 1..{ + return this; + }; + 1..{ + return this.isEven; + }; + 1..{ + return isEven; + }; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_without_parameter.dart.strong.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_without_parameter.dart.strong.expect new file mode 100644 index 00000000000..ade17f5648f --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_without_parameter.dart.strong.expect @@ -0,0 +1,114 @@ +library; +import self as self; +import "dart:core" as core; + +static method main() → void { + let final core::int #t1 = 1 in block { + { + final synthesized core::int anonymous#this = #t1; + Null #t2; + #L1: + { + 1; + { + #t2 = null; + break #L1; + } + } + } + } =>#t1; + let final core::int #t3 = 1 in block { + { + final synthesized core::int anonymous#this = #t3; + Null #t4; + #L2: + { + anonymous#this; + { + #t4 = null; + break #L2; + } + } + } + } =>#t3; + let final core::int #t5 = 1 in block { + { + final synthesized core::int anonymous#this = #t5; + Null #t6; + #L3: + { + anonymous#this.{core::int::isEven}{core::bool}; + { + #t6 = null; + break #L3; + } + } + } + } =>#t5; + let final core::int #t7 = 1 in block { + { + final synthesized core::int anonymous#this = #t7; + Null #t8; + #L4: + { + anonymous#this.{core::int::isEven}{core::bool}; + { + #t8 = null; + break #L4; + } + } + } + } =>#t7; + let final core::int #t9 = 1 in block { + { + final synthesized core::int anonymous#this = #t9; + core::int #t10; + #L5: + { + { + #t10 = 1; + break #L5; + } + } + } + } =>#t9; + let final core::int #t11 = 1 in block { + { + final synthesized core::int anonymous#this = #t11; + core::int #t12; + #L6: + { + { + #t12 = anonymous#this; + break #L6; + } + } + } + } =>#t11; + let final core::int #t13 = 1 in block { + { + final synthesized core::int anonymous#this = #t13; + core::bool #t14; + #L7: + { + { + #t14 = anonymous#this.{core::int::isEven}{core::bool}; + break #L7; + } + } + } + } =>#t13; + let final core::int #t15 = 1 in block { + { + final synthesized core::int anonymous#this = #t15; + core::bool #t16; + #L8: + { + { + #t16 = anonymous#this.{core::int::isEven}{core::bool}; + break #L8; + } + } + } + } =>#t15; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_without_parameter.dart.strong.modular.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_without_parameter.dart.strong.modular.expect new file mode 100644 index 00000000000..ade17f5648f --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_without_parameter.dart.strong.modular.expect @@ -0,0 +1,114 @@ +library; +import self as self; +import "dart:core" as core; + +static method main() → void { + let final core::int #t1 = 1 in block { + { + final synthesized core::int anonymous#this = #t1; + Null #t2; + #L1: + { + 1; + { + #t2 = null; + break #L1; + } + } + } + } =>#t1; + let final core::int #t3 = 1 in block { + { + final synthesized core::int anonymous#this = #t3; + Null #t4; + #L2: + { + anonymous#this; + { + #t4 = null; + break #L2; + } + } + } + } =>#t3; + let final core::int #t5 = 1 in block { + { + final synthesized core::int anonymous#this = #t5; + Null #t6; + #L3: + { + anonymous#this.{core::int::isEven}{core::bool}; + { + #t6 = null; + break #L3; + } + } + } + } =>#t5; + let final core::int #t7 = 1 in block { + { + final synthesized core::int anonymous#this = #t7; + Null #t8; + #L4: + { + anonymous#this.{core::int::isEven}{core::bool}; + { + #t8 = null; + break #L4; + } + } + } + } =>#t7; + let final core::int #t9 = 1 in block { + { + final synthesized core::int anonymous#this = #t9; + core::int #t10; + #L5: + { + { + #t10 = 1; + break #L5; + } + } + } + } =>#t9; + let final core::int #t11 = 1 in block { + { + final synthesized core::int anonymous#this = #t11; + core::int #t12; + #L6: + { + { + #t12 = anonymous#this; + break #L6; + } + } + } + } =>#t11; + let final core::int #t13 = 1 in block { + { + final synthesized core::int anonymous#this = #t13; + core::bool #t14; + #L7: + { + { + #t14 = anonymous#this.{core::int::isEven}{core::bool}; + break #L7; + } + } + } + } =>#t13; + let final core::int #t15 = 1 in block { + { + final synthesized core::int anonymous#this = #t15; + core::bool #t16; + #L8: + { + { + #t16 = anonymous#this.{core::int::isEven}{core::bool}; + break #L8; + } + } + } + } =>#t15; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_without_parameter.dart.strong.outline.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_without_parameter.dart.strong.outline.expect new file mode 100644 index 00000000000..2982c48b884 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_without_parameter.dart.strong.outline.expect @@ -0,0 +1,5 @@ +library; +import self as self; + +static method main() → void + ; diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_without_parameter.dart.strong.transformed.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_without_parameter.dart.strong.transformed.expect new file mode 100644 index 00000000000..c52462ad637 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_without_parameter.dart.strong.transformed.expect @@ -0,0 +1,134 @@ +library; +import self as self; +import "dart:core" as core; + +static method main() → void { + let final core::int #t1 = 1 in block { + { + final synthesized core::int anonymous#this = #t1; + Null #t2; + #L1: + { + 1; + { + #t2 = null; + break #L1; + } + } + } + } =>#t1; + let final core::int #t3 = 1 in block { + { + final synthesized core::int anonymous#this = #t3; + Null #t4; + #L2: + { + anonymous#this; + { + #t4 = null; + break #L2; + } + } + } + } =>#t3; + let final core::int #t5 = 1 in block { + { + final synthesized core::int anonymous#this = #t5; + Null #t6; + #L3: + { + anonymous#this.{core::int::isEven}{core::bool}; + { + #t6 = null; + break #L3; + } + } + } + } =>#t5; + let final core::int #t7 = 1 in block { + { + final synthesized core::int anonymous#this = #t7; + Null #t8; + #L4: + { + anonymous#this.{core::int::isEven}{core::bool}; + { + #t8 = null; + break #L4; + } + } + } + } =>#t7; + let final core::int #t9 = 1 in block { + { + final synthesized core::int anonymous#this = #t9; + core::int #t10; + #L5: + { + { + #t10 = 1; + break #L5; + } + } + } + } =>#t9; + let final core::int #t11 = 1 in block { + { + final synthesized core::int anonymous#this = #t11; + core::int #t12; + #L6: + { + { + #t12 = anonymous#this; + break #L6; + } + } + } + } =>#t11; + let final core::int #t13 = 1 in block { + { + final synthesized core::int anonymous#this = #t13; + core::bool #t14; + #L7: + { + { + #t14 = anonymous#this.{core::int::isEven}{core::bool}; + break #L7; + } + } + } + } =>#t13; + let final core::int #t15 = 1 in block { + { + final synthesized core::int anonymous#this = #t15; + core::bool #t16; + #L8: + { + { + #t16 = anonymous#this.{core::int::isEven}{core::bool}; + break #L8; + } + } + } + } =>#t15; +} + + +Extra constant evaluation status: +Evaluated: VariableGet @ org-dartlang-testcase:///block_cascaded_without_parameter.dart:6:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_cascaded_without_parameter.dart:6:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_cascaded_without_parameter.dart:10:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_cascaded_without_parameter.dart:10:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_cascaded_without_parameter.dart:14:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_cascaded_without_parameter.dart:14:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_cascaded_without_parameter.dart:18:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_cascaded_without_parameter.dart:18:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_cascaded_without_parameter.dart:22:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_cascaded_without_parameter.dart:22:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_cascaded_without_parameter.dart:25:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_cascaded_without_parameter.dart:25:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_cascaded_without_parameter.dart:28:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_cascaded_without_parameter.dart:28:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_cascaded_without_parameter.dart:31:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_cascaded_without_parameter.dart:31:3 -> IntConstant(1) +Extra constant evaluation: evaluated: 50, effectively constant: 16 diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_without_parameter.dart.textual_outline.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_without_parameter.dart.textual_outline.expect new file mode 100644 index 00000000000..ab73b3a234a --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_without_parameter.dart.textual_outline.expect @@ -0,0 +1 @@ +void main() {} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_without_parameter.dart.textual_outline_modelled.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_without_parameter.dart.textual_outline_modelled.expect new file mode 100644 index 00000000000..ab73b3a234a --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_cascaded_without_parameter.dart.textual_outline_modelled.expect @@ -0,0 +1 @@ +void main() {} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_typed.dart b/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_typed.dart new file mode 100644 index 00000000000..84d7efa1d00 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_typed.dart @@ -0,0 +1,34 @@ +// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +void main() { + 1.(int p) { + p; + return; + }; + 1?.(int p) { + p; + return; + }; + 1..(int p) { + p; + return; + }; + 1?..(int p) { + p; + return; + }; + 1.(int p) { + return p; + }; + 1?.(int p) { + return p; + }; + 1..(int p) { + return p; + }; + 1?..(int p) { + return p; + }; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_typed.dart.strong.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_typed.dart.strong.expect new file mode 100644 index 00000000000..79c3bb1a703 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_typed.dart.strong.expect @@ -0,0 +1,106 @@ +library; +import self as self; +import "dart:core" as core; + +static method main() → void { + { + core::int p = 1; + Null #t1; + #L1: + { + p; + { + #t1 = null; + break #L1; + } + } + } + let core::int #t2 = 1 in #t2 == null ?{Null} null : block { + core::int p = #t2 as core::int; + Null #t3; + #L2: + { + p; + { + #t3 = null; + break #L2; + } + } + } =>#t3; + let final core::int #t4 = 1 in block { + { + core::int p = #t4; + Null #t5; + #L3: + { + p; + { + #t5 = null; + break #L3; + } + } + } + } =>#t4; + let final core::int #t6 = 1 in #t6 == null ?{core::int} #t6 : block { + { + core::int p = #t6 as core::int; + Null #t7; + #L4: + { + p; + { + #t7 = null; + break #L4; + } + } + } + } =>#t6; + { + core::int p = 1; + core::int #t8; + #L5: + { + { + #t8 = p; + break #L5; + } + } + } + let core::int #t9 = 1 in #t9 == null ?{core::int?} null : block { + core::int p = #t9 as core::int; + core::int #t10; + #L6: + { + { + #t10 = p; + break #L6; + } + } + } =>#t10; + let final core::int #t11 = 1 in block { + { + core::int p = #t11; + core::int #t12; + #L7: + { + { + #t12 = p; + break #L7; + } + } + } + } =>#t11; + let final core::int #t13 = 1 in #t13 == null ?{core::int} #t13 : block { + { + core::int p = #t13 as core::int; + core::int #t14; + #L8: + { + { + #t14 = p; + break #L8; + } + } + } + } =>#t13; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_typed.dart.strong.modular.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_typed.dart.strong.modular.expect new file mode 100644 index 00000000000..79c3bb1a703 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_typed.dart.strong.modular.expect @@ -0,0 +1,106 @@ +library; +import self as self; +import "dart:core" as core; + +static method main() → void { + { + core::int p = 1; + Null #t1; + #L1: + { + p; + { + #t1 = null; + break #L1; + } + } + } + let core::int #t2 = 1 in #t2 == null ?{Null} null : block { + core::int p = #t2 as core::int; + Null #t3; + #L2: + { + p; + { + #t3 = null; + break #L2; + } + } + } =>#t3; + let final core::int #t4 = 1 in block { + { + core::int p = #t4; + Null #t5; + #L3: + { + p; + { + #t5 = null; + break #L3; + } + } + } + } =>#t4; + let final core::int #t6 = 1 in #t6 == null ?{core::int} #t6 : block { + { + core::int p = #t6 as core::int; + Null #t7; + #L4: + { + p; + { + #t7 = null; + break #L4; + } + } + } + } =>#t6; + { + core::int p = 1; + core::int #t8; + #L5: + { + { + #t8 = p; + break #L5; + } + } + } + let core::int #t9 = 1 in #t9 == null ?{core::int?} null : block { + core::int p = #t9 as core::int; + core::int #t10; + #L6: + { + { + #t10 = p; + break #L6; + } + } + } =>#t10; + let final core::int #t11 = 1 in block { + { + core::int p = #t11; + core::int #t12; + #L7: + { + { + #t12 = p; + break #L7; + } + } + } + } =>#t11; + let final core::int #t13 = 1 in #t13 == null ?{core::int} #t13 : block { + { + core::int p = #t13 as core::int; + core::int #t14; + #L8: + { + { + #t14 = p; + break #L8; + } + } + } + } =>#t13; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_typed.dart.strong.outline.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_typed.dart.strong.outline.expect new file mode 100644 index 00000000000..2982c48b884 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_typed.dart.strong.outline.expect @@ -0,0 +1,5 @@ +library; +import self as self; + +static method main() → void + ; diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_typed.dart.strong.transformed.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_typed.dart.strong.transformed.expect new file mode 100644 index 00000000000..326019738b3 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_typed.dart.strong.transformed.expect @@ -0,0 +1,126 @@ +library; +import self as self; +import "dart:core" as core; + +static method main() → void { + { + core::int p = 1; + Null #t1; + #L1: + { + p; + { + #t1 = null; + break #L1; + } + } + } + let core::int #t2 = 1 in #t2 == null ?{Null} null : block { + core::int p = #t2 as{Unchecked} core::int; + Null #t3; + #L2: + { + p; + { + #t3 = null; + break #L2; + } + } + } =>#t3; + let final core::int #t4 = 1 in block { + { + core::int p = #t4; + Null #t5; + #L3: + { + p; + { + #t5 = null; + break #L3; + } + } + } + } =>#t4; + let final core::int #t6 = 1 in #t6 == null ?{core::int} #t6 : block { + { + core::int p = #t6 as{Unchecked} core::int; + Null #t7; + #L4: + { + p; + { + #t7 = null; + break #L4; + } + } + } + } =>#t6; + { + core::int p = 1; + core::int #t8; + #L5: + { + { + #t8 = p; + break #L5; + } + } + } + let core::int #t9 = 1 in #t9 == null ?{core::int?} null : block { + core::int p = #t9 as{Unchecked} core::int; + core::int #t10; + #L6: + { + { + #t10 = p; + break #L6; + } + } + } =>#t10; + let final core::int #t11 = 1 in block { + { + core::int p = #t11; + core::int #t12; + #L7: + { + { + #t12 = p; + break #L7; + } + } + } + } =>#t11; + let final core::int #t13 = 1 in #t13 == null ?{core::int} #t13 : block { + { + core::int p = #t13 as{Unchecked} core::int; + core::int #t14; + #L8: + { + { + #t14 = p; + break #L8; + } + } + } + } =>#t13; +} + + +Extra constant evaluation status: +Evaluated: EqualsNull @ org-dartlang-testcase:///block_explicitly_typed.dart:10:11 -> BoolConstant(false) +Evaluated: AsExpression @ org-dartlang-testcase:///block_explicitly_typed.dart:10:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_explicitly_typed.dart:14:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_explicitly_typed.dart:14:3 -> IntConstant(1) +Evaluated: EqualsNull @ org-dartlang-testcase:///block_explicitly_typed.dart:18:3 -> BoolConstant(false) +Evaluated: VariableGet @ org-dartlang-testcase:///block_explicitly_typed.dart:18:3 -> IntConstant(1) +Evaluated: AsExpression @ org-dartlang-testcase:///block_explicitly_typed.dart:18:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_explicitly_typed.dart:18:3 -> IntConstant(1) +Evaluated: EqualsNull @ org-dartlang-testcase:///block_explicitly_typed.dart:25:11 -> BoolConstant(false) +Evaluated: AsExpression @ org-dartlang-testcase:///block_explicitly_typed.dart:25:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_explicitly_typed.dart:28:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_explicitly_typed.dart:28:3 -> IntConstant(1) +Evaluated: EqualsNull @ org-dartlang-testcase:///block_explicitly_typed.dart:31:3 -> BoolConstant(false) +Evaluated: VariableGet @ org-dartlang-testcase:///block_explicitly_typed.dart:31:3 -> IntConstant(1) +Evaluated: AsExpression @ org-dartlang-testcase:///block_explicitly_typed.dart:31:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_explicitly_typed.dart:31:3 -> IntConstant(1) +Extra constant evaluation: evaluated: 50, effectively constant: 16 diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_typed.dart.textual_outline.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_typed.dart.textual_outline.expect new file mode 100644 index 00000000000..ab73b3a234a --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_typed.dart.textual_outline.expect @@ -0,0 +1 @@ +void main() {} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_typed.dart.textual_outline_modelled.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_typed.dart.textual_outline_modelled.expect new file mode 100644 index 00000000000..ab73b3a234a --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_typed.dart.textual_outline_modelled.expect @@ -0,0 +1 @@ +void main() {} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart b/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart new file mode 100644 index 00000000000..eebcabec279 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart @@ -0,0 +1,18 @@ +// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +void test() { + 1.(String p) { // Error + p; + }; + 1?.(String p) { // Error + p; + }; + 1..(String p) { // Error + p; + }; + 1?..(String p) { // Error + p; + }; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart.strong.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart.strong.expect new file mode 100644 index 00000000000..c6578620ac1 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart.strong.expect @@ -0,0 +1,77 @@ +library; +// +// Problems in library: +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart:6:6: Error: The receiver type 'int' must be assignable to the formal parameter type 'String' in an anonymous method. +// Try removing the parameter type, or make it a supertype of the receiver type. +// 1.(String p) { // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart:9:7: Error: The receiver type 'int' must be assignable to the formal parameter type 'String' in an anonymous method. +// Try removing the parameter type, or make it a supertype of the receiver type. +// 1?.(String p) { // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart:12:7: Error: The receiver type 'int' must be assignable to the formal parameter type 'String' in an anonymous method. +// Try removing the parameter type, or make it a supertype of the receiver type. +// 1..(String p) { // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart:15:8: Error: The receiver type 'int' must be assignable to the formal parameter type 'String' in an anonymous method. +// Try removing the parameter type, or make it a supertype of the receiver type. +// 1?..(String p) { // Error +// ^ +// +import self as self; +import "dart:core" as core; + +static method test() → void { + { + core::String p = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart:6:6: Error: The receiver type 'int' must be assignable to the formal parameter type 'String' in an anonymous method. +Try removing the parameter type, or make it a supertype of the receiver type. + 1.(String p) { // Error + ^" in 1 as{TypeError} core::String; + Null #t1; + #L1: + { + p; + } + } + let core::int #t2 = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart:9:7: Error: The receiver type 'int' must be assignable to the formal parameter type 'String' in an anonymous method. +Try removing the parameter type, or make it a supertype of the receiver type. + 1?.(String p) { // Error + ^" in 1 as{TypeError} core::String in #t2 == null ?{Null} null : block { + core::String p = #t2 as core::String; + Null #t3; + #L2: + { + p; + } + } =>#t3; + let final core::int #t4 = 1 in block { + { + core::String p = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart:12:7: Error: The receiver type 'int' must be assignable to the formal parameter type 'String' in an anonymous method. +Try removing the parameter type, or make it a supertype of the receiver type. + 1..(String p) { // Error + ^" in #t4 as{TypeError} core::String; + Null #t5; + #L3: + { + p; + } + } + } =>#t4; + let final core::int #t6 = 1 in #t6 == null ?{core::int} #t6 : block { + { + core::String p = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart:15:8: Error: The receiver type 'int' must be assignable to the formal parameter type 'String' in an anonymous method. +Try removing the parameter type, or make it a supertype of the receiver type. + 1?..(String p) { // Error + ^" in #t6 as{TypeError} core::String as core::String; + Null #t7; + #L4: + { + p; + } + } + } =>#t6; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart.strong.modular.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart.strong.modular.expect new file mode 100644 index 00000000000..c6578620ac1 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart.strong.modular.expect @@ -0,0 +1,77 @@ +library; +// +// Problems in library: +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart:6:6: Error: The receiver type 'int' must be assignable to the formal parameter type 'String' in an anonymous method. +// Try removing the parameter type, or make it a supertype of the receiver type. +// 1.(String p) { // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart:9:7: Error: The receiver type 'int' must be assignable to the formal parameter type 'String' in an anonymous method. +// Try removing the parameter type, or make it a supertype of the receiver type. +// 1?.(String p) { // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart:12:7: Error: The receiver type 'int' must be assignable to the formal parameter type 'String' in an anonymous method. +// Try removing the parameter type, or make it a supertype of the receiver type. +// 1..(String p) { // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart:15:8: Error: The receiver type 'int' must be assignable to the formal parameter type 'String' in an anonymous method. +// Try removing the parameter type, or make it a supertype of the receiver type. +// 1?..(String p) { // Error +// ^ +// +import self as self; +import "dart:core" as core; + +static method test() → void { + { + core::String p = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart:6:6: Error: The receiver type 'int' must be assignable to the formal parameter type 'String' in an anonymous method. +Try removing the parameter type, or make it a supertype of the receiver type. + 1.(String p) { // Error + ^" in 1 as{TypeError} core::String; + Null #t1; + #L1: + { + p; + } + } + let core::int #t2 = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart:9:7: Error: The receiver type 'int' must be assignable to the formal parameter type 'String' in an anonymous method. +Try removing the parameter type, or make it a supertype of the receiver type. + 1?.(String p) { // Error + ^" in 1 as{TypeError} core::String in #t2 == null ?{Null} null : block { + core::String p = #t2 as core::String; + Null #t3; + #L2: + { + p; + } + } =>#t3; + let final core::int #t4 = 1 in block { + { + core::String p = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart:12:7: Error: The receiver type 'int' must be assignable to the formal parameter type 'String' in an anonymous method. +Try removing the parameter type, or make it a supertype of the receiver type. + 1..(String p) { // Error + ^" in #t4 as{TypeError} core::String; + Null #t5; + #L3: + { + p; + } + } + } =>#t4; + let final core::int #t6 = 1 in #t6 == null ?{core::int} #t6 : block { + { + core::String p = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart:15:8: Error: The receiver type 'int' must be assignable to the formal parameter type 'String' in an anonymous method. +Try removing the parameter type, or make it a supertype of the receiver type. + 1?..(String p) { // Error + ^" in #t6 as{TypeError} core::String as core::String; + Null #t7; + #L4: + { + p; + } + } + } =>#t6; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart.strong.outline.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart.strong.outline.expect new file mode 100644 index 00000000000..643a05ad8a2 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart.strong.outline.expect @@ -0,0 +1,5 @@ +library; +import self as self; + +static method test() → void + ; diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart.strong.transformed.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart.strong.transformed.expect new file mode 100644 index 00000000000..4cada8b0049 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart.strong.transformed.expect @@ -0,0 +1,85 @@ +library; +// +// Problems in library: +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart:6:6: Error: The receiver type 'int' must be assignable to the formal parameter type 'String' in an anonymous method. +// Try removing the parameter type, or make it a supertype of the receiver type. +// 1.(String p) { // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart:9:7: Error: The receiver type 'int' must be assignable to the formal parameter type 'String' in an anonymous method. +// Try removing the parameter type, or make it a supertype of the receiver type. +// 1?.(String p) { // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart:12:7: Error: The receiver type 'int' must be assignable to the formal parameter type 'String' in an anonymous method. +// Try removing the parameter type, or make it a supertype of the receiver type. +// 1..(String p) { // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart:15:8: Error: The receiver type 'int' must be assignable to the formal parameter type 'String' in an anonymous method. +// Try removing the parameter type, or make it a supertype of the receiver type. +// 1?..(String p) { // Error +// ^ +// +import self as self; +import "dart:core" as core; + +static method test() → void { + { + core::String p = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart:6:6: Error: The receiver type 'int' must be assignable to the formal parameter type 'String' in an anonymous method. +Try removing the parameter type, or make it a supertype of the receiver type. + 1.(String p) { // Error + ^" in 1 as{TypeError} core::String; + Null #t1; + #L1: + { + p; + } + } + let core::int #t2 = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart:9:7: Error: The receiver type 'int' must be assignable to the formal parameter type 'String' in an anonymous method. +Try removing the parameter type, or make it a supertype of the receiver type. + 1?.(String p) { // Error + ^" in 1 as{TypeError} core::String in #t2 == null ?{Null} null : block { + core::String p = #t2 as core::String; + Null #t3; + #L2: + { + p; + } + } =>#t3; + let final core::int #t4 = 1 in block { + { + core::String p = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart:12:7: Error: The receiver type 'int' must be assignable to the formal parameter type 'String' in an anonymous method. +Try removing the parameter type, or make it a supertype of the receiver type. + 1..(String p) { // Error + ^" in #t4 as{TypeError} core::String; + Null #t5; + #L3: + { + p; + } + } + } =>#t4; + let final core::int #t6 = 1 in #t6 == null ?{core::int} #t6 : block { + { + core::String p = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart:15:8: Error: The receiver type 'int' must be assignable to the formal parameter type 'String' in an anonymous method. +Try removing the parameter type, or make it a supertype of the receiver type. + 1?..(String p) { // Error + ^" in #t6 as{TypeError} core::String as{Unchecked} core::String; + Null #t7; + #L4: + { + p; + } + } + } =>#t6; +} + + +Extra constant evaluation status: +Evaluated: VariableGet @ org-dartlang-testcase:///block_explicitly_wrongly_typed.dart:12:3 -> IntConstant(1) +Evaluated: EqualsNull @ org-dartlang-testcase:///block_explicitly_wrongly_typed.dart:15:3 -> BoolConstant(false) +Evaluated: VariableGet @ org-dartlang-testcase:///block_explicitly_wrongly_typed.dart:15:3 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_explicitly_wrongly_typed.dart:15:3 -> IntConstant(1) +Extra constant evaluation: evaluated: 22, effectively constant: 4 diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart.textual_outline.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart.textual_outline.expect new file mode 100644 index 00000000000..7da700fd123 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart.textual_outline.expect @@ -0,0 +1 @@ +void test() {} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart.textual_outline_modelled.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart.textual_outline_modelled.expect new file mode 100644 index 00000000000..7da700fd123 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_explicitly_wrongly_typed.dart.textual_outline_modelled.expect @@ -0,0 +1 @@ +void test() {} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_extension_method.dart b/pkg/front_end/testcases/coverage/anonymous_methods/block_extension_method.dart new file mode 100644 index 00000000000..770f30d3151 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_extension_method.dart @@ -0,0 +1,68 @@ +// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +extension E on int { + void foo() { + 1.{ + this; + return; + }; + 1.(p) { + this; + return; + }; + 1?.{ + this; + return; + }; + 1?.(p) { + this; + return; + }; + 1..{ + this; + return; + }; + 1..(p) { + this; + return; + }; + 1?..{ + this; + return; + }; + 1?..(p) { + this; + return; + }; + 1.{ + return this; + }; + 1.(p) { + return this; + }; + 1?.{ + return this; + }; + 1?.(p) { + return this; + }; + 1..{ + return this; + }; + 1..(p) { + return this; + }; + 1?..{ + return this; + }; + 1?..(p) { + return this; + }; + } +} + +void main() { + 1.foo(); +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_extension_method.dart.strong.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_extension_method.dart.strong.expect new file mode 100644 index 00000000000..d84d0823979 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_extension_method.dart.strong.expect @@ -0,0 +1,215 @@ +library; +import self as self; +import "dart:core" as core; + +extension E on core::int { + method foo = self::E|foo; + method tearoff foo = self::E|get#foo; +} +static extension-member method E|foo(lowered final core::int #this) → void { + { + final synthesized core::int anonymous#this = 1; + Null #t1; + #L1: + { + anonymous#this; + { + #t1 = null; + break #L1; + } + } + } + { + core::int p = 1; + Null #t2; + #L2: + { + #this; + { + #t2 = null; + break #L2; + } + } + } + let core::int #t3 = 1 in #t3 == null ?{Null} null : block { + final synthesized core::int anonymous#this = #t3 as core::int; + Null #t4; + #L3: + { + anonymous#this; + { + #t4 = null; + break #L3; + } + } + } =>#t4; + let core::int #t5 = 1 in #t5 == null ?{Null} null : block { + core::int p = #t5 as core::int; + Null #t6; + #L4: + { + #this; + { + #t6 = null; + break #L4; + } + } + } =>#t6; + let final core::int #t7 = 1 in block { + { + final synthesized core::int anonymous#this = #t7; + Null #t8; + #L5: + { + anonymous#this; + { + #t8 = null; + break #L5; + } + } + } + } =>#t7; + let final core::int #t9 = 1 in block { + { + core::int p = #t9; + Null #t10; + #L6: + { + #this; + { + #t10 = null; + break #L6; + } + } + } + } =>#t9; + let final core::int #t11 = 1 in #t11 == null ?{core::int} #t11 : block { + { + final synthesized core::int anonymous#this = #t11 as core::int; + Null #t12; + #L7: + { + anonymous#this; + { + #t12 = null; + break #L7; + } + } + } + } =>#t11; + let final core::int #t13 = 1 in #t13 == null ?{core::int} #t13 : block { + { + core::int p = #t13 as core::int; + Null #t14; + #L8: + { + #this; + { + #t14 = null; + break #L8; + } + } + } + } =>#t13; + { + final synthesized core::int anonymous#this = 1; + core::int #t15; + #L9: + { + { + #t15 = anonymous#this; + break #L9; + } + } + } + { + core::int p = 1; + core::int #t16; + #L10: + { + { + #t16 = #this; + break #L10; + } + } + } + let core::int #t17 = 1 in #t17 == null ?{core::int?} null : block { + final synthesized core::int anonymous#this = #t17 as core::int; + core::int #t18; + #L11: + { + { + #t18 = anonymous#this; + break #L11; + } + } + } =>#t18; + let core::int #t19 = 1 in #t19 == null ?{core::int?} null : block { + core::int p = #t19 as core::int; + core::int #t20; + #L12: + { + { + #t20 = #this; + break #L12; + } + } + } =>#t20; + let final core::int #t21 = 1 in block { + { + final synthesized core::int anonymous#this = #t21; + core::int #t22; + #L13: + { + { + #t22 = anonymous#this; + break #L13; + } + } + } + } =>#t21; + let final core::int #t23 = 1 in block { + { + core::int p = #t23; + core::int #t24; + #L14: + { + { + #t24 = #this; + break #L14; + } + } + } + } =>#t23; + let final core::int #t25 = 1 in #t25 == null ?{core::int} #t25 : block { + { + final synthesized core::int anonymous#this = #t25 as core::int; + core::int #t26; + #L15: + { + { + #t26 = anonymous#this; + break #L15; + } + } + } + } =>#t25; + let final core::int #t27 = 1 in #t27 == null ?{core::int} #t27 : block { + { + core::int p = #t27 as core::int; + core::int #t28; + #L16: + { + { + #t28 = #this; + break #L16; + } + } + } + } =>#t27; +} +static extension-member method E|get#foo(lowered final core::int #this) → () → void + return () → void => self::E|foo(#this); +static method main() → void { + self::E|foo(1); +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_extension_method.dart.strong.modular.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_extension_method.dart.strong.modular.expect new file mode 100644 index 00000000000..d84d0823979 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_extension_method.dart.strong.modular.expect @@ -0,0 +1,215 @@ +library; +import self as self; +import "dart:core" as core; + +extension E on core::int { + method foo = self::E|foo; + method tearoff foo = self::E|get#foo; +} +static extension-member method E|foo(lowered final core::int #this) → void { + { + final synthesized core::int anonymous#this = 1; + Null #t1; + #L1: + { + anonymous#this; + { + #t1 = null; + break #L1; + } + } + } + { + core::int p = 1; + Null #t2; + #L2: + { + #this; + { + #t2 = null; + break #L2; + } + } + } + let core::int #t3 = 1 in #t3 == null ?{Null} null : block { + final synthesized core::int anonymous#this = #t3 as core::int; + Null #t4; + #L3: + { + anonymous#this; + { + #t4 = null; + break #L3; + } + } + } =>#t4; + let core::int #t5 = 1 in #t5 == null ?{Null} null : block { + core::int p = #t5 as core::int; + Null #t6; + #L4: + { + #this; + { + #t6 = null; + break #L4; + } + } + } =>#t6; + let final core::int #t7 = 1 in block { + { + final synthesized core::int anonymous#this = #t7; + Null #t8; + #L5: + { + anonymous#this; + { + #t8 = null; + break #L5; + } + } + } + } =>#t7; + let final core::int #t9 = 1 in block { + { + core::int p = #t9; + Null #t10; + #L6: + { + #this; + { + #t10 = null; + break #L6; + } + } + } + } =>#t9; + let final core::int #t11 = 1 in #t11 == null ?{core::int} #t11 : block { + { + final synthesized core::int anonymous#this = #t11 as core::int; + Null #t12; + #L7: + { + anonymous#this; + { + #t12 = null; + break #L7; + } + } + } + } =>#t11; + let final core::int #t13 = 1 in #t13 == null ?{core::int} #t13 : block { + { + core::int p = #t13 as core::int; + Null #t14; + #L8: + { + #this; + { + #t14 = null; + break #L8; + } + } + } + } =>#t13; + { + final synthesized core::int anonymous#this = 1; + core::int #t15; + #L9: + { + { + #t15 = anonymous#this; + break #L9; + } + } + } + { + core::int p = 1; + core::int #t16; + #L10: + { + { + #t16 = #this; + break #L10; + } + } + } + let core::int #t17 = 1 in #t17 == null ?{core::int?} null : block { + final synthesized core::int anonymous#this = #t17 as core::int; + core::int #t18; + #L11: + { + { + #t18 = anonymous#this; + break #L11; + } + } + } =>#t18; + let core::int #t19 = 1 in #t19 == null ?{core::int?} null : block { + core::int p = #t19 as core::int; + core::int #t20; + #L12: + { + { + #t20 = #this; + break #L12; + } + } + } =>#t20; + let final core::int #t21 = 1 in block { + { + final synthesized core::int anonymous#this = #t21; + core::int #t22; + #L13: + { + { + #t22 = anonymous#this; + break #L13; + } + } + } + } =>#t21; + let final core::int #t23 = 1 in block { + { + core::int p = #t23; + core::int #t24; + #L14: + { + { + #t24 = #this; + break #L14; + } + } + } + } =>#t23; + let final core::int #t25 = 1 in #t25 == null ?{core::int} #t25 : block { + { + final synthesized core::int anonymous#this = #t25 as core::int; + core::int #t26; + #L15: + { + { + #t26 = anonymous#this; + break #L15; + } + } + } + } =>#t25; + let final core::int #t27 = 1 in #t27 == null ?{core::int} #t27 : block { + { + core::int p = #t27 as core::int; + core::int #t28; + #L16: + { + { + #t28 = #this; + break #L16; + } + } + } + } =>#t27; +} +static extension-member method E|get#foo(lowered final core::int #this) → () → void + return () → void => self::E|foo(#this); +static method main() → void { + self::E|foo(1); +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_extension_method.dart.strong.outline.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_extension_method.dart.strong.outline.expect new file mode 100644 index 00000000000..0ee47384fc6 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_extension_method.dart.strong.outline.expect @@ -0,0 +1,14 @@ +library; +import self as self; +import "dart:core" as core; + +extension E on core::int { + method foo = self::E|foo; + method tearoff foo = self::E|get#foo; +} +static extension-member method E|foo(lowered final core::int #this) → void + ; +static extension-member method E|get#foo(lowered final core::int #this) → () → void + return () → void => self::E|foo(#this); +static method main() → void + ; diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_extension_method.dart.strong.transformed.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_extension_method.dart.strong.transformed.expect new file mode 100644 index 00000000000..b232fd6f37d --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_extension_method.dart.strong.transformed.expect @@ -0,0 +1,251 @@ +library; +import self as self; +import "dart:core" as core; + +extension E on core::int { + method foo = self::E|foo; + method tearoff foo = self::E|get#foo; +} +static extension-member method E|foo(lowered final core::int #this) → void { + { + final synthesized core::int anonymous#this = 1; + Null #t1; + #L1: + { + anonymous#this; + { + #t1 = null; + break #L1; + } + } + } + { + core::int p = 1; + Null #t2; + #L2: + { + #this; + { + #t2 = null; + break #L2; + } + } + } + let core::int #t3 = 1 in #t3 == null ?{Null} null : block { + final synthesized core::int anonymous#this = #t3 as{Unchecked} core::int; + Null #t4; + #L3: + { + anonymous#this; + { + #t4 = null; + break #L3; + } + } + } =>#t4; + let core::int #t5 = 1 in #t5 == null ?{Null} null : block { + core::int p = #t5 as{Unchecked} core::int; + Null #t6; + #L4: + { + #this; + { + #t6 = null; + break #L4; + } + } + } =>#t6; + let final core::int #t7 = 1 in block { + { + final synthesized core::int anonymous#this = #t7; + Null #t8; + #L5: + { + anonymous#this; + { + #t8 = null; + break #L5; + } + } + } + } =>#t7; + let final core::int #t9 = 1 in block { + { + core::int p = #t9; + Null #t10; + #L6: + { + #this; + { + #t10 = null; + break #L6; + } + } + } + } =>#t9; + let final core::int #t11 = 1 in #t11 == null ?{core::int} #t11 : block { + { + final synthesized core::int anonymous#this = #t11 as{Unchecked} core::int; + Null #t12; + #L7: + { + anonymous#this; + { + #t12 = null; + break #L7; + } + } + } + } =>#t11; + let final core::int #t13 = 1 in #t13 == null ?{core::int} #t13 : block { + { + core::int p = #t13 as{Unchecked} core::int; + Null #t14; + #L8: + { + #this; + { + #t14 = null; + break #L8; + } + } + } + } =>#t13; + { + final synthesized core::int anonymous#this = 1; + core::int #t15; + #L9: + { + { + #t15 = anonymous#this; + break #L9; + } + } + } + { + core::int p = 1; + core::int #t16; + #L10: + { + { + #t16 = #this; + break #L10; + } + } + } + let core::int #t17 = 1 in #t17 == null ?{core::int?} null : block { + final synthesized core::int anonymous#this = #t17 as{Unchecked} core::int; + core::int #t18; + #L11: + { + { + #t18 = anonymous#this; + break #L11; + } + } + } =>#t18; + let core::int #t19 = 1 in #t19 == null ?{core::int?} null : block { + core::int p = #t19 as{Unchecked} core::int; + core::int #t20; + #L12: + { + { + #t20 = #this; + break #L12; + } + } + } =>#t20; + let final core::int #t21 = 1 in block { + { + final synthesized core::int anonymous#this = #t21; + core::int #t22; + #L13: + { + { + #t22 = anonymous#this; + break #L13; + } + } + } + } =>#t21; + let final core::int #t23 = 1 in block { + { + core::int p = #t23; + core::int #t24; + #L14: + { + { + #t24 = #this; + break #L14; + } + } + } + } =>#t23; + let final core::int #t25 = 1 in #t25 == null ?{core::int} #t25 : block { + { + final synthesized core::int anonymous#this = #t25 as{Unchecked} core::int; + core::int #t26; + #L15: + { + { + #t26 = anonymous#this; + break #L15; + } + } + } + } =>#t25; + let final core::int #t27 = 1 in #t27 == null ?{core::int} #t27 : block { + { + core::int p = #t27 as{Unchecked} core::int; + core::int #t28; + #L16: + { + { + #t28 = #this; + break #L16; + } + } + } + } =>#t27; +} +static extension-member method E|get#foo(lowered final core::int #this) → () → void + return () → void => self::E|foo(#this); +static method main() → void { + self::E|foo(1); +} + + +Extra constant evaluation status: +Evaluated: EqualsNull @ org-dartlang-testcase:///block_extension_method.dart:15:6 -> BoolConstant(false) +Evaluated: AsExpression @ org-dartlang-testcase:///block_extension_method.dart:15:5 -> IntConstant(1) +Evaluated: EqualsNull @ org-dartlang-testcase:///block_extension_method.dart:19:9 -> BoolConstant(false) +Evaluated: AsExpression @ org-dartlang-testcase:///block_extension_method.dart:19:5 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_extension_method.dart:23:5 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_extension_method.dart:23:5 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_extension_method.dart:27:5 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_extension_method.dart:27:5 -> IntConstant(1) +Evaluated: EqualsNull @ org-dartlang-testcase:///block_extension_method.dart:31:5 -> BoolConstant(false) +Evaluated: VariableGet @ org-dartlang-testcase:///block_extension_method.dart:31:5 -> IntConstant(1) +Evaluated: AsExpression @ org-dartlang-testcase:///block_extension_method.dart:31:5 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_extension_method.dart:31:5 -> IntConstant(1) +Evaluated: EqualsNull @ org-dartlang-testcase:///block_extension_method.dart:35:5 -> BoolConstant(false) +Evaluated: VariableGet @ org-dartlang-testcase:///block_extension_method.dart:35:5 -> IntConstant(1) +Evaluated: AsExpression @ org-dartlang-testcase:///block_extension_method.dart:35:5 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_extension_method.dart:35:5 -> IntConstant(1) +Evaluated: EqualsNull @ org-dartlang-testcase:///block_extension_method.dart:45:6 -> BoolConstant(false) +Evaluated: AsExpression @ org-dartlang-testcase:///block_extension_method.dart:45:5 -> IntConstant(1) +Evaluated: EqualsNull @ org-dartlang-testcase:///block_extension_method.dart:48:9 -> BoolConstant(false) +Evaluated: AsExpression @ org-dartlang-testcase:///block_extension_method.dart:48:5 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_extension_method.dart:51:5 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_extension_method.dart:51:5 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_extension_method.dart:54:5 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_extension_method.dart:54:5 -> IntConstant(1) +Evaluated: EqualsNull @ org-dartlang-testcase:///block_extension_method.dart:57:5 -> BoolConstant(false) +Evaluated: VariableGet @ org-dartlang-testcase:///block_extension_method.dart:57:5 -> IntConstant(1) +Evaluated: AsExpression @ org-dartlang-testcase:///block_extension_method.dart:57:5 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_extension_method.dart:57:5 -> IntConstant(1) +Evaluated: EqualsNull @ org-dartlang-testcase:///block_extension_method.dart:60:5 -> BoolConstant(false) +Evaluated: VariableGet @ org-dartlang-testcase:///block_extension_method.dart:60:5 -> IntConstant(1) +Evaluated: AsExpression @ org-dartlang-testcase:///block_extension_method.dart:60:5 -> IntConstant(1) +Evaluated: VariableGet @ org-dartlang-testcase:///block_extension_method.dart:60:5 -> IntConstant(1) +Extra constant evaluation: evaluated: 104, effectively constant: 32 diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_extension_method.dart.textual_outline.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_extension_method.dart.textual_outline.expect new file mode 100644 index 00000000000..41e1ed2b527 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_extension_method.dart.textual_outline.expect @@ -0,0 +1,5 @@ +extension E on int { + void foo() {} +} + +void main() {} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_extension_method.dart.textual_outline_modelled.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_extension_method.dart.textual_outline_modelled.expect new file mode 100644 index 00000000000..41e1ed2b527 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_extension_method.dart.textual_outline_modelled.expect @@ -0,0 +1,5 @@ +extension E on int { + void foo() {} +} + +void main() {} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_with_parameter.dart b/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_with_parameter.dart new file mode 100644 index 00000000000..e299173dfae --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_with_parameter.dart @@ -0,0 +1,29 @@ +// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +int? i = null; + +void main() { + i?.(p) { + 1; + return; + }; + i?.(p) { + p; + return; + }; + i?.(p) { + p.isEven; + return; + }; + i?.(p) { + return 1; + }; + i?.(p) { + return p; + }; + i?.(p) { + return p.isEven; + }; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_with_parameter.dart.strong.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_with_parameter.dart.strong.expect new file mode 100644 index 00000000000..a4266c726ce --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_with_parameter.dart.strong.expect @@ -0,0 +1,76 @@ +library; +import self as self; +import "dart:core" as core; + +static field core::int? i = null; +static method main() → void { + let core::int? #t1 = self::i in #t1 == null ?{Null} null : block { + core::int p = #t1 as core::int; + Null #t2; + #L1: + { + 1; + { + #t2 = null; + break #L1; + } + } + } =>#t2; + let core::int? #t3 = self::i in #t3 == null ?{Null} null : block { + core::int p = #t3 as core::int; + Null #t4; + #L2: + { + p; + { + #t4 = null; + break #L2; + } + } + } =>#t4; + let core::int? #t5 = self::i in #t5 == null ?{Null} null : block { + core::int p = #t5 as core::int; + Null #t6; + #L3: + { + p.{core::int::isEven}{core::bool}; + { + #t6 = null; + break #L3; + } + } + } =>#t6; + let core::int? #t7 = self::i in #t7 == null ?{core::int?} null : block { + core::int p = #t7 as core::int; + core::int #t8; + #L4: + { + { + #t8 = 1; + break #L4; + } + } + } =>#t8; + let core::int? #t9 = self::i in #t9 == null ?{core::int?} null : block { + core::int p = #t9 as core::int; + core::int #t10; + #L5: + { + { + #t10 = p; + break #L5; + } + } + } =>#t10; + let core::int? #t11 = self::i in #t11 == null ?{core::bool?} null : block { + core::int p = #t11 as core::int; + core::bool #t12; + #L6: + { + { + #t12 = p.{core::int::isEven}{core::bool}; + break #L6; + } + } + } =>#t12; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_with_parameter.dart.strong.modular.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_with_parameter.dart.strong.modular.expect new file mode 100644 index 00000000000..a4266c726ce --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_with_parameter.dart.strong.modular.expect @@ -0,0 +1,76 @@ +library; +import self as self; +import "dart:core" as core; + +static field core::int? i = null; +static method main() → void { + let core::int? #t1 = self::i in #t1 == null ?{Null} null : block { + core::int p = #t1 as core::int; + Null #t2; + #L1: + { + 1; + { + #t2 = null; + break #L1; + } + } + } =>#t2; + let core::int? #t3 = self::i in #t3 == null ?{Null} null : block { + core::int p = #t3 as core::int; + Null #t4; + #L2: + { + p; + { + #t4 = null; + break #L2; + } + } + } =>#t4; + let core::int? #t5 = self::i in #t5 == null ?{Null} null : block { + core::int p = #t5 as core::int; + Null #t6; + #L3: + { + p.{core::int::isEven}{core::bool}; + { + #t6 = null; + break #L3; + } + } + } =>#t6; + let core::int? #t7 = self::i in #t7 == null ?{core::int?} null : block { + core::int p = #t7 as core::int; + core::int #t8; + #L4: + { + { + #t8 = 1; + break #L4; + } + } + } =>#t8; + let core::int? #t9 = self::i in #t9 == null ?{core::int?} null : block { + core::int p = #t9 as core::int; + core::int #t10; + #L5: + { + { + #t10 = p; + break #L5; + } + } + } =>#t10; + let core::int? #t11 = self::i in #t11 == null ?{core::bool?} null : block { + core::int p = #t11 as core::int; + core::bool #t12; + #L6: + { + { + #t12 = p.{core::int::isEven}{core::bool}; + break #L6; + } + } + } =>#t12; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_with_parameter.dart.strong.outline.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_with_parameter.dart.strong.outline.expect new file mode 100644 index 00000000000..c17141d4913 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_with_parameter.dart.strong.outline.expect @@ -0,0 +1,7 @@ +library; +import self as self; +import "dart:core" as core; + +static field core::int? i; +static method main() → void + ; diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_with_parameter.dart.strong.transformed.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_with_parameter.dart.strong.transformed.expect new file mode 100644 index 00000000000..5fd8a05a984 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_with_parameter.dart.strong.transformed.expect @@ -0,0 +1,76 @@ +library; +import self as self; +import "dart:core" as core; + +static field core::int? i = null; +static method main() → void { + let core::int? #t1 = self::i in #t1 == null ?{Null} null : block { + core::int p = let core::int? #t2 = #t1 in #t2 == null ?{core::int} #t2 as core::int : #t2{core::int}; + Null #t3; + #L1: + { + 1; + { + #t3 = null; + break #L1; + } + } + } =>#t3; + let core::int? #t4 = self::i in #t4 == null ?{Null} null : block { + core::int p = let core::int? #t5 = #t4 in #t5 == null ?{core::int} #t5 as core::int : #t5{core::int}; + Null #t6; + #L2: + { + p; + { + #t6 = null; + break #L2; + } + } + } =>#t6; + let core::int? #t7 = self::i in #t7 == null ?{Null} null : block { + core::int p = let core::int? #t8 = #t7 in #t8 == null ?{core::int} #t8 as core::int : #t8{core::int}; + Null #t9; + #L3: + { + p.{core::int::isEven}{core::bool}; + { + #t9 = null; + break #L3; + } + } + } =>#t9; + let core::int? #t10 = self::i in #t10 == null ?{core::int?} null : block { + core::int p = let core::int? #t11 = #t10 in #t11 == null ?{core::int} #t11 as core::int : #t11{core::int}; + core::int #t12; + #L4: + { + { + #t12 = 1; + break #L4; + } + } + } =>#t12; + let core::int? #t13 = self::i in #t13 == null ?{core::int?} null : block { + core::int p = let core::int? #t14 = #t13 in #t14 == null ?{core::int} #t14 as core::int : #t14{core::int}; + core::int #t15; + #L5: + { + { + #t15 = p; + break #L5; + } + } + } =>#t15; + let core::int? #t16 = self::i in #t16 == null ?{core::bool?} null : block { + core::int p = let core::int? #t17 = #t16 in #t17 == null ?{core::int} #t17 as core::int : #t17{core::int}; + core::bool #t18; + #L6: + { + { + #t18 = p.{core::int::isEven}{core::bool}; + break #L6; + } + } + } =>#t18; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_with_parameter.dart.textual_outline.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_with_parameter.dart.textual_outline.expect new file mode 100644 index 00000000000..eedd821d211 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_with_parameter.dart.textual_outline.expect @@ -0,0 +1,3 @@ +int? i = null; + +void main() {} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_with_parameter.dart.textual_outline_modelled.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_with_parameter.dart.textual_outline_modelled.expect new file mode 100644 index 00000000000..eedd821d211 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_with_parameter.dart.textual_outline_modelled.expect @@ -0,0 +1,3 @@ +int? i = null; + +void main() {} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_without_parameter.dart b/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_without_parameter.dart new file mode 100644 index 00000000000..43b90dcd2e3 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_without_parameter.dart @@ -0,0 +1,36 @@ +// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +int? i = null; + +void main() { + i?.{ + 1; + return; + }; + i?.{ + this; + return; + }; + i?.{ + this.isEven; + return; + }; + i?.{ + isEven; + return; + }; + i?.{ + return 1; + }; + i?.{ + return this; + }; + i?.{ + return this.isEven; + }; + i?.{ + return isEven; + }; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_without_parameter.dart.strong.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_without_parameter.dart.strong.expect new file mode 100644 index 00000000000..8815ffdd4fc --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_without_parameter.dart.strong.expect @@ -0,0 +1,99 @@ +library; +import self as self; +import "dart:core" as core; + +static field core::int? i = null; +static method main() → void { + let core::int? #t1 = self::i in #t1 == null ?{Null} null : block { + final synthesized core::int anonymous#this = #t1 as core::int; + Null #t2; + #L1: + { + 1; + { + #t2 = null; + break #L1; + } + } + } =>#t2; + let core::int? #t3 = self::i in #t3 == null ?{Null} null : block { + final synthesized core::int anonymous#this = #t3 as core::int; + Null #t4; + #L2: + { + anonymous#this; + { + #t4 = null; + break #L2; + } + } + } =>#t4; + let core::int? #t5 = self::i in #t5 == null ?{Null} null : block { + final synthesized core::int anonymous#this = #t5 as core::int; + Null #t6; + #L3: + { + anonymous#this.{core::int::isEven}{core::bool}; + { + #t6 = null; + break #L3; + } + } + } =>#t6; + let core::int? #t7 = self::i in #t7 == null ?{Null} null : block { + final synthesized core::int anonymous#this = #t7 as core::int; + Null #t8; + #L4: + { + anonymous#this.{core::int::isEven}{core::bool}; + { + #t8 = null; + break #L4; + } + } + } =>#t8; + let core::int? #t9 = self::i in #t9 == null ?{core::int?} null : block { + final synthesized core::int anonymous#this = #t9 as core::int; + core::int #t10; + #L5: + { + { + #t10 = 1; + break #L5; + } + } + } =>#t10; + let core::int? #t11 = self::i in #t11 == null ?{core::int?} null : block { + final synthesized core::int anonymous#this = #t11 as core::int; + core::int #t12; + #L6: + { + { + #t12 = anonymous#this; + break #L6; + } + } + } =>#t12; + let core::int? #t13 = self::i in #t13 == null ?{core::bool?} null : block { + final synthesized core::int anonymous#this = #t13 as core::int; + core::bool #t14; + #L7: + { + { + #t14 = anonymous#this.{core::int::isEven}{core::bool}; + break #L7; + } + } + } =>#t14; + let core::int? #t15 = self::i in #t15 == null ?{core::bool?} null : block { + final synthesized core::int anonymous#this = #t15 as core::int; + core::bool #t16; + #L8: + { + { + #t16 = anonymous#this.{core::int::isEven}{core::bool}; + break #L8; + } + } + } =>#t16; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_without_parameter.dart.strong.modular.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_without_parameter.dart.strong.modular.expect new file mode 100644 index 00000000000..8815ffdd4fc --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_without_parameter.dart.strong.modular.expect @@ -0,0 +1,99 @@ +library; +import self as self; +import "dart:core" as core; + +static field core::int? i = null; +static method main() → void { + let core::int? #t1 = self::i in #t1 == null ?{Null} null : block { + final synthesized core::int anonymous#this = #t1 as core::int; + Null #t2; + #L1: + { + 1; + { + #t2 = null; + break #L1; + } + } + } =>#t2; + let core::int? #t3 = self::i in #t3 == null ?{Null} null : block { + final synthesized core::int anonymous#this = #t3 as core::int; + Null #t4; + #L2: + { + anonymous#this; + { + #t4 = null; + break #L2; + } + } + } =>#t4; + let core::int? #t5 = self::i in #t5 == null ?{Null} null : block { + final synthesized core::int anonymous#this = #t5 as core::int; + Null #t6; + #L3: + { + anonymous#this.{core::int::isEven}{core::bool}; + { + #t6 = null; + break #L3; + } + } + } =>#t6; + let core::int? #t7 = self::i in #t7 == null ?{Null} null : block { + final synthesized core::int anonymous#this = #t7 as core::int; + Null #t8; + #L4: + { + anonymous#this.{core::int::isEven}{core::bool}; + { + #t8 = null; + break #L4; + } + } + } =>#t8; + let core::int? #t9 = self::i in #t9 == null ?{core::int?} null : block { + final synthesized core::int anonymous#this = #t9 as core::int; + core::int #t10; + #L5: + { + { + #t10 = 1; + break #L5; + } + } + } =>#t10; + let core::int? #t11 = self::i in #t11 == null ?{core::int?} null : block { + final synthesized core::int anonymous#this = #t11 as core::int; + core::int #t12; + #L6: + { + { + #t12 = anonymous#this; + break #L6; + } + } + } =>#t12; + let core::int? #t13 = self::i in #t13 == null ?{core::bool?} null : block { + final synthesized core::int anonymous#this = #t13 as core::int; + core::bool #t14; + #L7: + { + { + #t14 = anonymous#this.{core::int::isEven}{core::bool}; + break #L7; + } + } + } =>#t14; + let core::int? #t15 = self::i in #t15 == null ?{core::bool?} null : block { + final synthesized core::int anonymous#this = #t15 as core::int; + core::bool #t16; + #L8: + { + { + #t16 = anonymous#this.{core::int::isEven}{core::bool}; + break #L8; + } + } + } =>#t16; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_without_parameter.dart.strong.outline.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_without_parameter.dart.strong.outline.expect new file mode 100644 index 00000000000..c17141d4913 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_without_parameter.dart.strong.outline.expect @@ -0,0 +1,7 @@ +library; +import self as self; +import "dart:core" as core; + +static field core::int? i; +static method main() → void + ; diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_without_parameter.dart.strong.transformed.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_without_parameter.dart.strong.transformed.expect new file mode 100644 index 00000000000..9ece81ef635 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_without_parameter.dart.strong.transformed.expect @@ -0,0 +1,99 @@ +library; +import self as self; +import "dart:core" as core; + +static field core::int? i = null; +static method main() → void { + let core::int? #t1 = self::i in #t1 == null ?{Null} null : block { + final synthesized core::int anonymous#this = let core::int? #t2 = #t1 in #t2 == null ?{core::int} #t2 as core::int : #t2{core::int}; + Null #t3; + #L1: + { + 1; + { + #t3 = null; + break #L1; + } + } + } =>#t3; + let core::int? #t4 = self::i in #t4 == null ?{Null} null : block { + final synthesized core::int anonymous#this = let core::int? #t5 = #t4 in #t5 == null ?{core::int} #t5 as core::int : #t5{core::int}; + Null #t6; + #L2: + { + anonymous#this; + { + #t6 = null; + break #L2; + } + } + } =>#t6; + let core::int? #t7 = self::i in #t7 == null ?{Null} null : block { + final synthesized core::int anonymous#this = let core::int? #t8 = #t7 in #t8 == null ?{core::int} #t8 as core::int : #t8{core::int}; + Null #t9; + #L3: + { + anonymous#this.{core::int::isEven}{core::bool}; + { + #t9 = null; + break #L3; + } + } + } =>#t9; + let core::int? #t10 = self::i in #t10 == null ?{Null} null : block { + final synthesized core::int anonymous#this = let core::int? #t11 = #t10 in #t11 == null ?{core::int} #t11 as core::int : #t11{core::int}; + Null #t12; + #L4: + { + anonymous#this.{core::int::isEven}{core::bool}; + { + #t12 = null; + break #L4; + } + } + } =>#t12; + let core::int? #t13 = self::i in #t13 == null ?{core::int?} null : block { + final synthesized core::int anonymous#this = let core::int? #t14 = #t13 in #t14 == null ?{core::int} #t14 as core::int : #t14{core::int}; + core::int #t15; + #L5: + { + { + #t15 = 1; + break #L5; + } + } + } =>#t15; + let core::int? #t16 = self::i in #t16 == null ?{core::int?} null : block { + final synthesized core::int anonymous#this = let core::int? #t17 = #t16 in #t17 == null ?{core::int} #t17 as core::int : #t17{core::int}; + core::int #t18; + #L6: + { + { + #t18 = anonymous#this; + break #L6; + } + } + } =>#t18; + let core::int? #t19 = self::i in #t19 == null ?{core::bool?} null : block { + final synthesized core::int anonymous#this = let core::int? #t20 = #t19 in #t20 == null ?{core::int} #t20 as core::int : #t20{core::int}; + core::bool #t21; + #L7: + { + { + #t21 = anonymous#this.{core::int::isEven}{core::bool}; + break #L7; + } + } + } =>#t21; + let core::int? #t22 = self::i in #t22 == null ?{core::bool?} null : block { + final synthesized core::int anonymous#this = let core::int? #t23 = #t22 in #t23 == null ?{core::int} #t23 as core::int : #t23{core::int}; + core::bool #t24; + #L8: + { + { + #t24 = anonymous#this.{core::int::isEven}{core::bool}; + break #L8; + } + } + } =>#t24; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_without_parameter.dart.textual_outline.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_without_parameter.dart.textual_outline.expect new file mode 100644 index 00000000000..eedd821d211 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_without_parameter.dart.textual_outline.expect @@ -0,0 +1,3 @@ +int? i = null; + +void main() {} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_without_parameter.dart.textual_outline_modelled.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_without_parameter.dart.textual_outline_modelled.expect new file mode 100644 index 00000000000..eedd821d211 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_null_aware_without_parameter.dart.textual_outline_modelled.expect @@ -0,0 +1,3 @@ +int? i = null; + +void main() {} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_this_in_initializer.dart b/pkg/front_end/testcases/coverage/anonymous_methods/block_this_in_initializer.dart new file mode 100644 index 00000000000..2adf2ee94b0 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_this_in_initializer.dart @@ -0,0 +1,28 @@ +// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +int f() => 5; + +class A { + final int x; + A.n1() : x = 42.{ + return this; + }; + A.n2() : x = 'abc'.{ + return this.length; + }; + A.n3() : x = f.{ + return this(); + }; + A.n4() : x = 'def'.{ + return this.toString().length; + }; +} + +void main() { + A.n1(); + A.n2(); + A.n3(); + A.n4(); +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_this_in_initializer.dart.strong.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_this_in_initializer.dart.strong.expect new file mode 100644 index 00000000000..d187dc1bbbb --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_this_in_initializer.dart.strong.expect @@ -0,0 +1,71 @@ +library; +import self as self; +import "dart:core" as core; + +class A extends core::Object { + final field core::int x; + constructor n1() → self::A + : self::A::x = block { + final synthesized core::int anonymous#this = 42; + core::int #t1; + #L1: + { + { + #t1 = anonymous#this; + break #L1; + } + } + } =>#t1, super core::Object::•() + ; + constructor n2() → self::A + : self::A::x = block { + final synthesized core::String anonymous#this = "abc"; + core::int #t2; + #L2: + { + { + #t2 = anonymous#this.{core::String::length}{core::int}; + break #L2; + } + } + } =>#t2, super core::Object::•() + ; + constructor n3() → self::A + : self::A::x = block { + final synthesized () → core::int anonymous#this = #C1; + core::int #t3; + #L3: + { + { + #t3 = anonymous#this(){() → core::int}; + break #L3; + } + } + } =>#t3, super core::Object::•() + ; + constructor n4() → self::A + : self::A::x = block { + final synthesized core::String anonymous#this = "def"; + core::int #t4; + #L4: + { + { + #t4 = anonymous#this.{core::Object::toString}(){() → core::String}.{core::String::length}{core::int}; + break #L4; + } + } + } =>#t4, super core::Object::•() + ; +} +static method f() → core::int + return 5; +static method main() → void { + new self::A::n1(); + new self::A::n2(); + new self::A::n3(); + new self::A::n4(); +} + +constants { + #C1 = static-tearoff self::f +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_this_in_initializer.dart.strong.modular.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_this_in_initializer.dart.strong.modular.expect new file mode 100644 index 00000000000..d187dc1bbbb --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_this_in_initializer.dart.strong.modular.expect @@ -0,0 +1,71 @@ +library; +import self as self; +import "dart:core" as core; + +class A extends core::Object { + final field core::int x; + constructor n1() → self::A + : self::A::x = block { + final synthesized core::int anonymous#this = 42; + core::int #t1; + #L1: + { + { + #t1 = anonymous#this; + break #L1; + } + } + } =>#t1, super core::Object::•() + ; + constructor n2() → self::A + : self::A::x = block { + final synthesized core::String anonymous#this = "abc"; + core::int #t2; + #L2: + { + { + #t2 = anonymous#this.{core::String::length}{core::int}; + break #L2; + } + } + } =>#t2, super core::Object::•() + ; + constructor n3() → self::A + : self::A::x = block { + final synthesized () → core::int anonymous#this = #C1; + core::int #t3; + #L3: + { + { + #t3 = anonymous#this(){() → core::int}; + break #L3; + } + } + } =>#t3, super core::Object::•() + ; + constructor n4() → self::A + : self::A::x = block { + final synthesized core::String anonymous#this = "def"; + core::int #t4; + #L4: + { + { + #t4 = anonymous#this.{core::Object::toString}(){() → core::String}.{core::String::length}{core::int}; + break #L4; + } + } + } =>#t4, super core::Object::•() + ; +} +static method f() → core::int + return 5; +static method main() → void { + new self::A::n1(); + new self::A::n2(); + new self::A::n3(); + new self::A::n4(); +} + +constants { + #C1 = static-tearoff self::f +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_this_in_initializer.dart.strong.outline.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_this_in_initializer.dart.strong.outline.expect new file mode 100644 index 00000000000..7e5fcf959e2 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_this_in_initializer.dart.strong.outline.expect @@ -0,0 +1,19 @@ +library; +import self as self; +import "dart:core" as core; + +class A extends core::Object { + final field core::int x; + constructor n1() → self::A + ; + constructor n2() → self::A + ; + constructor n3() → self::A + ; + constructor n4() → self::A + ; +} +static method f() → core::int + ; +static method main() → void + ; diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_this_in_initializer.dart.strong.transformed.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_this_in_initializer.dart.strong.transformed.expect new file mode 100644 index 00000000000..d187dc1bbbb --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_this_in_initializer.dart.strong.transformed.expect @@ -0,0 +1,71 @@ +library; +import self as self; +import "dart:core" as core; + +class A extends core::Object { + final field core::int x; + constructor n1() → self::A + : self::A::x = block { + final synthesized core::int anonymous#this = 42; + core::int #t1; + #L1: + { + { + #t1 = anonymous#this; + break #L1; + } + } + } =>#t1, super core::Object::•() + ; + constructor n2() → self::A + : self::A::x = block { + final synthesized core::String anonymous#this = "abc"; + core::int #t2; + #L2: + { + { + #t2 = anonymous#this.{core::String::length}{core::int}; + break #L2; + } + } + } =>#t2, super core::Object::•() + ; + constructor n3() → self::A + : self::A::x = block { + final synthesized () → core::int anonymous#this = #C1; + core::int #t3; + #L3: + { + { + #t3 = anonymous#this(){() → core::int}; + break #L3; + } + } + } =>#t3, super core::Object::•() + ; + constructor n4() → self::A + : self::A::x = block { + final synthesized core::String anonymous#this = "def"; + core::int #t4; + #L4: + { + { + #t4 = anonymous#this.{core::Object::toString}(){() → core::String}.{core::String::length}{core::int}; + break #L4; + } + } + } =>#t4, super core::Object::•() + ; +} +static method f() → core::int + return 5; +static method main() → void { + new self::A::n1(); + new self::A::n2(); + new self::A::n3(); + new self::A::n4(); +} + +constants { + #C1 = static-tearoff self::f +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_this_in_initializer.dart.textual_outline.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_this_in_initializer.dart.textual_outline.expect new file mode 100644 index 00000000000..b9d6a13931a --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_this_in_initializer.dart.textual_outline.expect @@ -0,0 +1,11 @@ +int f() => 5; + +class A { + final int x; + A.n1() : x = 42.{ return this; }; + A.n2() : x = 'abc'.{ return this.length; }; + A.n3() : x = f.{ return this(); }; + A.n4() : x = 'def'.{ return this.toString().length; }; +} + +void main() {} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_this_in_initializer.dart.textual_outline_modelled.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_this_in_initializer.dart.textual_outline_modelled.expect new file mode 100644 index 00000000000..63fbc8759e3 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_this_in_initializer.dart.textual_outline_modelled.expect @@ -0,0 +1,11 @@ +class A { + A.n1() : x = 42.{ return this; }; + A.n2() : x = 'abc'.{ return this.length; }; + A.n3() : x = f.{ return this(); }; + A.n4() : x = 'def'.{ return this.toString().length; }; + final int x; +} + +int f() => 5; + +void main() {} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart b/pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart new file mode 100644 index 00000000000..de154a7ff98 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart @@ -0,0 +1,64 @@ +// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +void v = null; + +void test() { + v.{ // Error + 1; + return; + }; + v.(p) { // Error + 1; + return; + }; + v?.{ // Error + 1; + return; + }; + v?.(p) { // Error + 1; + return; + }; + v..{ // Error + 1; + return; + }; + v..(p) { // Error + 1; + return; + }; + v?..{ // Error + 1; + return; + }; + v?..(p) { // Error + 1; + return; + }; + v.{ // Error + return 1; + }; + v.(p) { // Error + return 1; + }; + v?.{ // Error + return 1; + }; + v?.(p) { // Error + return 1; + }; + v..{ // Error + return 1; + }; + v..(p) { // Error + return 1; + }; + v?..{ // Error + return 1; + }; + v?..(p) { // Error + return 1; + }; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart.strong.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart.strong.expect new file mode 100644 index 00000000000..44dad149a91 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart.strong.expect @@ -0,0 +1,306 @@ +library; +// +// Problems in library: +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:8:3: Error: This expression has type 'void' and can't be used. +// v.{ // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:12:3: Error: This expression has type 'void' and can't be used. +// v.(p) { // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:16:3: Error: This expression has type 'void' and can't be used. +// v?.{ // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:20:3: Error: This expression has type 'void' and can't be used. +// v?.(p) { // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:24:3: Error: This expression has type 'void' and can't be used. +// v..{ // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:28:3: Error: This expression has type 'void' and can't be used. +// v..(p) { // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:32:3: Error: This expression has type 'void' and can't be used. +// v?..{ // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:36:3: Error: This expression has type 'void' and can't be used. +// v?..(p) { // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:40:3: Error: This expression has type 'void' and can't be used. +// v.{ // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:43:3: Error: This expression has type 'void' and can't be used. +// v.(p) { // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:46:3: Error: This expression has type 'void' and can't be used. +// v?.{ // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:49:3: Error: This expression has type 'void' and can't be used. +// v?.(p) { // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:52:3: Error: This expression has type 'void' and can't be used. +// v..{ // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:55:3: Error: This expression has type 'void' and can't be used. +// v..(p) { // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:58:3: Error: This expression has type 'void' and can't be used. +// v?..{ // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:61:3: Error: This expression has type 'void' and can't be used. +// v?..(p) { // Error +// ^ +// +import self as self; +import "dart:core" as core; + +static field void v = null; +static method test() → void { + { + final synthesized void anonymous#this = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:8:3: Error: This expression has type 'void' and can't be used. + v.{ // Error + ^" in self::v; + Null #t1; + #L1: + { + 1; + { + #t1 = null; + break #L1; + } + } + } + { + void p = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:12:3: Error: This expression has type 'void' and can't be used. + v.(p) { // Error + ^" in self::v; + Null #t2; + #L2: + { + 1; + { + #t2 = null; + break #L2; + } + } + } + let void #t3 = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:16:3: Error: This expression has type 'void' and can't be used. + v?.{ // Error + ^" in self::v in #t3 == null ?{Null} null : block { + final synthesized void anonymous#this = #t3 as void; + Null #t4; + #L3: + { + 1; + { + #t4 = null; + break #L3; + } + } + } =>#t4; + let void #t5 = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:20:3: Error: This expression has type 'void' and can't be used. + v?.(p) { // Error + ^" in self::v in #t5 == null ?{Null} null : block { + void p = #t5 as void; + Null #t6; + #L4: + { + 1; + { + #t6 = null; + break #L4; + } + } + } =>#t6; + let final void #t7 = self::v in block { + { + final synthesized void anonymous#this = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:24:3: Error: This expression has type 'void' and can't be used. + v..{ // Error + ^" in #t7; + Null #t8; + #L5: + { + 1; + { + #t8 = null; + break #L5; + } + } + } + } =>#t7; + let final void #t9 = self::v in block { + { + void p = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:28:3: Error: This expression has type 'void' and can't be used. + v..(p) { // Error + ^" in #t9; + Null #t10; + #L6: + { + 1; + { + #t10 = null; + break #L6; + } + } + } + } =>#t9; + let final void #t11 = self::v in #t11 == null ?{void} null : block { + { + final synthesized void anonymous#this = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:32:3: Error: This expression has type 'void' and can't be used. + v?..{ // Error + ^" in #t11 as void; + Null #t12; + #L7: + { + 1; + { + #t12 = null; + break #L7; + } + } + } + } =>#t11; + let final void #t13 = self::v in #t13 == null ?{void} null : block { + { + void p = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:36:3: Error: This expression has type 'void' and can't be used. + v?..(p) { // Error + ^" in #t13 as void; + Null #t14; + #L8: + { + 1; + { + #t14 = null; + break #L8; + } + } + } + } =>#t13; + { + final synthesized void anonymous#this = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:40:3: Error: This expression has type 'void' and can't be used. + v.{ // Error + ^" in self::v; + core::int #t15; + #L9: + { + { + #t15 = 1; + break #L9; + } + } + } + { + void p = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:43:3: Error: This expression has type 'void' and can't be used. + v.(p) { // Error + ^" in self::v; + core::int #t16; + #L10: + { + { + #t16 = 1; + break #L10; + } + } + } + let void #t17 = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:46:3: Error: This expression has type 'void' and can't be used. + v?.{ // Error + ^" in self::v in #t17 == null ?{core::int?} null : block { + final synthesized void anonymous#this = #t17 as void; + core::int #t18; + #L11: + { + { + #t18 = 1; + break #L11; + } + } + } =>#t18; + let void #t19 = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:49:3: Error: This expression has type 'void' and can't be used. + v?.(p) { // Error + ^" in self::v in #t19 == null ?{core::int?} null : block { + void p = #t19 as void; + core::int #t20; + #L12: + { + { + #t20 = 1; + break #L12; + } + } + } =>#t20; + let final void #t21 = self::v in block { + { + final synthesized void anonymous#this = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:52:3: Error: This expression has type 'void' and can't be used. + v..{ // Error + ^" in #t21; + core::int #t22; + #L13: + { + { + #t22 = 1; + break #L13; + } + } + } + } =>#t21; + let final void #t23 = self::v in block { + { + void p = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:55:3: Error: This expression has type 'void' and can't be used. + v..(p) { // Error + ^" in #t23; + core::int #t24; + #L14: + { + { + #t24 = 1; + break #L14; + } + } + } + } =>#t23; + let final void #t25 = self::v in #t25 == null ?{void} null : block { + { + final synthesized void anonymous#this = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:58:3: Error: This expression has type 'void' and can't be used. + v?..{ // Error + ^" in #t25 as void; + core::int #t26; + #L15: + { + { + #t26 = 1; + break #L15; + } + } + } + } =>#t25; + let final void #t27 = self::v in #t27 == null ?{void} null : block { + { + void p = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:61:3: Error: This expression has type 'void' and can't be used. + v?..(p) { // Error + ^" in #t27 as void; + core::int #t28; + #L16: + { + { + #t28 = 1; + break #L16; + } + } + } + } =>#t27; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart.strong.modular.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart.strong.modular.expect new file mode 100644 index 00000000000..44dad149a91 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart.strong.modular.expect @@ -0,0 +1,306 @@ +library; +// +// Problems in library: +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:8:3: Error: This expression has type 'void' and can't be used. +// v.{ // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:12:3: Error: This expression has type 'void' and can't be used. +// v.(p) { // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:16:3: Error: This expression has type 'void' and can't be used. +// v?.{ // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:20:3: Error: This expression has type 'void' and can't be used. +// v?.(p) { // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:24:3: Error: This expression has type 'void' and can't be used. +// v..{ // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:28:3: Error: This expression has type 'void' and can't be used. +// v..(p) { // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:32:3: Error: This expression has type 'void' and can't be used. +// v?..{ // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:36:3: Error: This expression has type 'void' and can't be used. +// v?..(p) { // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:40:3: Error: This expression has type 'void' and can't be used. +// v.{ // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:43:3: Error: This expression has type 'void' and can't be used. +// v.(p) { // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:46:3: Error: This expression has type 'void' and can't be used. +// v?.{ // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:49:3: Error: This expression has type 'void' and can't be used. +// v?.(p) { // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:52:3: Error: This expression has type 'void' and can't be used. +// v..{ // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:55:3: Error: This expression has type 'void' and can't be used. +// v..(p) { // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:58:3: Error: This expression has type 'void' and can't be used. +// v?..{ // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:61:3: Error: This expression has type 'void' and can't be used. +// v?..(p) { // Error +// ^ +// +import self as self; +import "dart:core" as core; + +static field void v = null; +static method test() → void { + { + final synthesized void anonymous#this = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:8:3: Error: This expression has type 'void' and can't be used. + v.{ // Error + ^" in self::v; + Null #t1; + #L1: + { + 1; + { + #t1 = null; + break #L1; + } + } + } + { + void p = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:12:3: Error: This expression has type 'void' and can't be used. + v.(p) { // Error + ^" in self::v; + Null #t2; + #L2: + { + 1; + { + #t2 = null; + break #L2; + } + } + } + let void #t3 = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:16:3: Error: This expression has type 'void' and can't be used. + v?.{ // Error + ^" in self::v in #t3 == null ?{Null} null : block { + final synthesized void anonymous#this = #t3 as void; + Null #t4; + #L3: + { + 1; + { + #t4 = null; + break #L3; + } + } + } =>#t4; + let void #t5 = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:20:3: Error: This expression has type 'void' and can't be used. + v?.(p) { // Error + ^" in self::v in #t5 == null ?{Null} null : block { + void p = #t5 as void; + Null #t6; + #L4: + { + 1; + { + #t6 = null; + break #L4; + } + } + } =>#t6; + let final void #t7 = self::v in block { + { + final synthesized void anonymous#this = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:24:3: Error: This expression has type 'void' and can't be used. + v..{ // Error + ^" in #t7; + Null #t8; + #L5: + { + 1; + { + #t8 = null; + break #L5; + } + } + } + } =>#t7; + let final void #t9 = self::v in block { + { + void p = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:28:3: Error: This expression has type 'void' and can't be used. + v..(p) { // Error + ^" in #t9; + Null #t10; + #L6: + { + 1; + { + #t10 = null; + break #L6; + } + } + } + } =>#t9; + let final void #t11 = self::v in #t11 == null ?{void} null : block { + { + final synthesized void anonymous#this = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:32:3: Error: This expression has type 'void' and can't be used. + v?..{ // Error + ^" in #t11 as void; + Null #t12; + #L7: + { + 1; + { + #t12 = null; + break #L7; + } + } + } + } =>#t11; + let final void #t13 = self::v in #t13 == null ?{void} null : block { + { + void p = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:36:3: Error: This expression has type 'void' and can't be used. + v?..(p) { // Error + ^" in #t13 as void; + Null #t14; + #L8: + { + 1; + { + #t14 = null; + break #L8; + } + } + } + } =>#t13; + { + final synthesized void anonymous#this = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:40:3: Error: This expression has type 'void' and can't be used. + v.{ // Error + ^" in self::v; + core::int #t15; + #L9: + { + { + #t15 = 1; + break #L9; + } + } + } + { + void p = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:43:3: Error: This expression has type 'void' and can't be used. + v.(p) { // Error + ^" in self::v; + core::int #t16; + #L10: + { + { + #t16 = 1; + break #L10; + } + } + } + let void #t17 = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:46:3: Error: This expression has type 'void' and can't be used. + v?.{ // Error + ^" in self::v in #t17 == null ?{core::int?} null : block { + final synthesized void anonymous#this = #t17 as void; + core::int #t18; + #L11: + { + { + #t18 = 1; + break #L11; + } + } + } =>#t18; + let void #t19 = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:49:3: Error: This expression has type 'void' and can't be used. + v?.(p) { // Error + ^" in self::v in #t19 == null ?{core::int?} null : block { + void p = #t19 as void; + core::int #t20; + #L12: + { + { + #t20 = 1; + break #L12; + } + } + } =>#t20; + let final void #t21 = self::v in block { + { + final synthesized void anonymous#this = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:52:3: Error: This expression has type 'void' and can't be used. + v..{ // Error + ^" in #t21; + core::int #t22; + #L13: + { + { + #t22 = 1; + break #L13; + } + } + } + } =>#t21; + let final void #t23 = self::v in block { + { + void p = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:55:3: Error: This expression has type 'void' and can't be used. + v..(p) { // Error + ^" in #t23; + core::int #t24; + #L14: + { + { + #t24 = 1; + break #L14; + } + } + } + } =>#t23; + let final void #t25 = self::v in #t25 == null ?{void} null : block { + { + final synthesized void anonymous#this = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:58:3: Error: This expression has type 'void' and can't be used. + v?..{ // Error + ^" in #t25 as void; + core::int #t26; + #L15: + { + { + #t26 = 1; + break #L15; + } + } + } + } =>#t25; + let final void #t27 = self::v in #t27 == null ?{void} null : block { + { + void p = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:61:3: Error: This expression has type 'void' and can't be used. + v?..(p) { // Error + ^" in #t27 as void; + core::int #t28; + #L16: + { + { + #t28 = 1; + break #L16; + } + } + } + } =>#t27; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart.strong.outline.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart.strong.outline.expect new file mode 100644 index 00000000000..babd3bcf29f --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart.strong.outline.expect @@ -0,0 +1,6 @@ +library; +import self as self; + +static field void v; +static method test() → void + ; diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart.strong.transformed.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart.strong.transformed.expect new file mode 100644 index 00000000000..711178dcde4 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart.strong.transformed.expect @@ -0,0 +1,306 @@ +library; +// +// Problems in library: +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:8:3: Error: This expression has type 'void' and can't be used. +// v.{ // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:12:3: Error: This expression has type 'void' and can't be used. +// v.(p) { // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:16:3: Error: This expression has type 'void' and can't be used. +// v?.{ // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:20:3: Error: This expression has type 'void' and can't be used. +// v?.(p) { // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:24:3: Error: This expression has type 'void' and can't be used. +// v..{ // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:28:3: Error: This expression has type 'void' and can't be used. +// v..(p) { // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:32:3: Error: This expression has type 'void' and can't be used. +// v?..{ // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:36:3: Error: This expression has type 'void' and can't be used. +// v?..(p) { // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:40:3: Error: This expression has type 'void' and can't be used. +// v.{ // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:43:3: Error: This expression has type 'void' and can't be used. +// v.(p) { // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:46:3: Error: This expression has type 'void' and can't be used. +// v?.{ // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:49:3: Error: This expression has type 'void' and can't be used. +// v?.(p) { // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:52:3: Error: This expression has type 'void' and can't be used. +// v..{ // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:55:3: Error: This expression has type 'void' and can't be used. +// v..(p) { // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:58:3: Error: This expression has type 'void' and can't be used. +// v?..{ // Error +// ^ +// +// pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:61:3: Error: This expression has type 'void' and can't be used. +// v?..(p) { // Error +// ^ +// +import self as self; +import "dart:core" as core; + +static field void v = null; +static method test() → void { + { + final synthesized void anonymous#this = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:8:3: Error: This expression has type 'void' and can't be used. + v.{ // Error + ^" in self::v; + Null #t1; + #L1: + { + 1; + { + #t1 = null; + break #L1; + } + } + } + { + void p = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:12:3: Error: This expression has type 'void' and can't be used. + v.(p) { // Error + ^" in self::v; + Null #t2; + #L2: + { + 1; + { + #t2 = null; + break #L2; + } + } + } + let void #t3 = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:16:3: Error: This expression has type 'void' and can't be used. + v?.{ // Error + ^" in self::v in #t3 == null ?{Null} null : block { + final synthesized void anonymous#this = #t3 as{Unchecked} void; + Null #t4; + #L3: + { + 1; + { + #t4 = null; + break #L3; + } + } + } =>#t4; + let void #t5 = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:20:3: Error: This expression has type 'void' and can't be used. + v?.(p) { // Error + ^" in self::v in #t5 == null ?{Null} null : block { + void p = #t5 as{Unchecked} void; + Null #t6; + #L4: + { + 1; + { + #t6 = null; + break #L4; + } + } + } =>#t6; + let final void #t7 = self::v in block { + { + final synthesized void anonymous#this = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:24:3: Error: This expression has type 'void' and can't be used. + v..{ // Error + ^" in #t7; + Null #t8; + #L5: + { + 1; + { + #t8 = null; + break #L5; + } + } + } + } =>#t7; + let final void #t9 = self::v in block { + { + void p = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:28:3: Error: This expression has type 'void' and can't be used. + v..(p) { // Error + ^" in #t9; + Null #t10; + #L6: + { + 1; + { + #t10 = null; + break #L6; + } + } + } + } =>#t9; + let final void #t11 = self::v in #t11 == null ?{void} null : block { + { + final synthesized void anonymous#this = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:32:3: Error: This expression has type 'void' and can't be used. + v?..{ // Error + ^" in #t11 as{Unchecked} void; + Null #t12; + #L7: + { + 1; + { + #t12 = null; + break #L7; + } + } + } + } =>#t11; + let final void #t13 = self::v in #t13 == null ?{void} null : block { + { + void p = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:36:3: Error: This expression has type 'void' and can't be used. + v?..(p) { // Error + ^" in #t13 as{Unchecked} void; + Null #t14; + #L8: + { + 1; + { + #t14 = null; + break #L8; + } + } + } + } =>#t13; + { + final synthesized void anonymous#this = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:40:3: Error: This expression has type 'void' and can't be used. + v.{ // Error + ^" in self::v; + core::int #t15; + #L9: + { + { + #t15 = 1; + break #L9; + } + } + } + { + void p = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:43:3: Error: This expression has type 'void' and can't be used. + v.(p) { // Error + ^" in self::v; + core::int #t16; + #L10: + { + { + #t16 = 1; + break #L10; + } + } + } + let void #t17 = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:46:3: Error: This expression has type 'void' and can't be used. + v?.{ // Error + ^" in self::v in #t17 == null ?{core::int?} null : block { + final synthesized void anonymous#this = #t17 as{Unchecked} void; + core::int #t18; + #L11: + { + { + #t18 = 1; + break #L11; + } + } + } =>#t18; + let void #t19 = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:49:3: Error: This expression has type 'void' and can't be used. + v?.(p) { // Error + ^" in self::v in #t19 == null ?{core::int?} null : block { + void p = #t19 as{Unchecked} void; + core::int #t20; + #L12: + { + { + #t20 = 1; + break #L12; + } + } + } =>#t20; + let final void #t21 = self::v in block { + { + final synthesized void anonymous#this = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:52:3: Error: This expression has type 'void' and can't be used. + v..{ // Error + ^" in #t21; + core::int #t22; + #L13: + { + { + #t22 = 1; + break #L13; + } + } + } + } =>#t21; + let final void #t23 = self::v in block { + { + void p = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:55:3: Error: This expression has type 'void' and can't be used. + v..(p) { // Error + ^" in #t23; + core::int #t24; + #L14: + { + { + #t24 = 1; + break #L14; + } + } + } + } =>#t23; + let final void #t25 = self::v in #t25 == null ?{void} null : block { + { + final synthesized void anonymous#this = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:58:3: Error: This expression has type 'void' and can't be used. + v?..{ // Error + ^" in #t25 as{Unchecked} void; + core::int #t26; + #L15: + { + { + #t26 = 1; + break #L15; + } + } + } + } =>#t25; + let final void #t27 = self::v in #t27 == null ?{void} null : block { + { + void p = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart:61:3: Error: This expression has type 'void' and can't be used. + v?..(p) { // Error + ^" in #t27 as{Unchecked} void; + core::int #t28; + #L16: + { + { + #t28 = 1; + break #L16; + } + } + } + } =>#t27; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart.textual_outline.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart.textual_outline.expect new file mode 100644 index 00000000000..4a827bdcbee --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart.textual_outline.expect @@ -0,0 +1,3 @@ +void v = null; + +void test() {} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart.textual_outline_modelled.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart.textual_outline_modelled.expect new file mode 100644 index 00000000000..70ffa1ca6eb --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_void_receiver.dart.textual_outline_modelled.expect @@ -0,0 +1,3 @@ +void test() {} + +void v = null; diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_with_parameter.dart b/pkg/front_end/testcases/coverage/anonymous_methods/block_with_parameter.dart new file mode 100644 index 00000000000..6c9be67efe3 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_with_parameter.dart @@ -0,0 +1,27 @@ +// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +void main() { + 1.(p) { + 1; + return; + }; + 1.(p) { + p; + return; + }; + 1.(p) { + p.isEven; + return; + }; + 1.(p) { + return 1; + }; + 1.(p) { + return p; + }; + 1.(p) { + return p.isEven; + }; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_with_parameter.dart.strong.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_with_parameter.dart.strong.expect new file mode 100644 index 00000000000..ed357a52700 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_with_parameter.dart.strong.expect @@ -0,0 +1,75 @@ +library; +import self as self; +import "dart:core" as core; + +static method main() → void { + { + core::int p = 1; + Null #t1; + #L1: + { + 1; + { + #t1 = null; + break #L1; + } + } + } + { + core::int p = 1; + Null #t2; + #L2: + { + p; + { + #t2 = null; + break #L2; + } + } + } + { + core::int p = 1; + Null #t3; + #L3: + { + p.{core::int::isEven}{core::bool}; + { + #t3 = null; + break #L3; + } + } + } + { + core::int p = 1; + core::int #t4; + #L4: + { + { + #t4 = 1; + break #L4; + } + } + } + { + core::int p = 1; + core::int #t5; + #L5: + { + { + #t5 = p; + break #L5; + } + } + } + { + core::int p = 1; + core::bool #t6; + #L6: + { + { + #t6 = p.{core::int::isEven}{core::bool}; + break #L6; + } + } + } +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_with_parameter.dart.strong.modular.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_with_parameter.dart.strong.modular.expect new file mode 100644 index 00000000000..ed357a52700 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_with_parameter.dart.strong.modular.expect @@ -0,0 +1,75 @@ +library; +import self as self; +import "dart:core" as core; + +static method main() → void { + { + core::int p = 1; + Null #t1; + #L1: + { + 1; + { + #t1 = null; + break #L1; + } + } + } + { + core::int p = 1; + Null #t2; + #L2: + { + p; + { + #t2 = null; + break #L2; + } + } + } + { + core::int p = 1; + Null #t3; + #L3: + { + p.{core::int::isEven}{core::bool}; + { + #t3 = null; + break #L3; + } + } + } + { + core::int p = 1; + core::int #t4; + #L4: + { + { + #t4 = 1; + break #L4; + } + } + } + { + core::int p = 1; + core::int #t5; + #L5: + { + { + #t5 = p; + break #L5; + } + } + } + { + core::int p = 1; + core::bool #t6; + #L6: + { + { + #t6 = p.{core::int::isEven}{core::bool}; + break #L6; + } + } + } +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_with_parameter.dart.strong.outline.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_with_parameter.dart.strong.outline.expect new file mode 100644 index 00000000000..2982c48b884 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_with_parameter.dart.strong.outline.expect @@ -0,0 +1,5 @@ +library; +import self as self; + +static method main() → void + ; diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_with_parameter.dart.strong.transformed.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_with_parameter.dart.strong.transformed.expect new file mode 100644 index 00000000000..ed357a52700 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_with_parameter.dart.strong.transformed.expect @@ -0,0 +1,75 @@ +library; +import self as self; +import "dart:core" as core; + +static method main() → void { + { + core::int p = 1; + Null #t1; + #L1: + { + 1; + { + #t1 = null; + break #L1; + } + } + } + { + core::int p = 1; + Null #t2; + #L2: + { + p; + { + #t2 = null; + break #L2; + } + } + } + { + core::int p = 1; + Null #t3; + #L3: + { + p.{core::int::isEven}{core::bool}; + { + #t3 = null; + break #L3; + } + } + } + { + core::int p = 1; + core::int #t4; + #L4: + { + { + #t4 = 1; + break #L4; + } + } + } + { + core::int p = 1; + core::int #t5; + #L5: + { + { + #t5 = p; + break #L5; + } + } + } + { + core::int p = 1; + core::bool #t6; + #L6: + { + { + #t6 = p.{core::int::isEven}{core::bool}; + break #L6; + } + } + } +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_with_parameter.dart.textual_outline.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_with_parameter.dart.textual_outline.expect new file mode 100644 index 00000000000..ab73b3a234a --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_with_parameter.dart.textual_outline.expect @@ -0,0 +1 @@ +void main() {} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_with_parameter.dart.textual_outline_modelled.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_with_parameter.dart.textual_outline_modelled.expect new file mode 100644 index 00000000000..ab73b3a234a --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_with_parameter.dart.textual_outline_modelled.expect @@ -0,0 +1 @@ +void main() {} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_without_parameter.dart b/pkg/front_end/testcases/coverage/anonymous_methods/block_without_parameter.dart new file mode 100644 index 00000000000..61b5efc2c2c --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_without_parameter.dart @@ -0,0 +1,34 @@ +// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +void main() { + 1.{ + 1; + return; + }; + 1.{ + this; + return; + }; + 1.{ + this.isEven; + return; + }; + 1.{ + isEven; + return; + }; + 1.{ + return 1; + }; + 1.{ + return this; + }; + 1.{ + return this.isEven; + }; + 1.{ + return isEven; + }; +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_without_parameter.dart.strong.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_without_parameter.dart.strong.expect new file mode 100644 index 00000000000..5eb84f4bf46 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_without_parameter.dart.strong.expect @@ -0,0 +1,98 @@ +library; +import self as self; +import "dart:core" as core; + +static method main() → void { + { + final synthesized core::int anonymous#this = 1; + Null #t1; + #L1: + { + 1; + { + #t1 = null; + break #L1; + } + } + } + { + final synthesized core::int anonymous#this = 1; + Null #t2; + #L2: + { + anonymous#this; + { + #t2 = null; + break #L2; + } + } + } + { + final synthesized core::int anonymous#this = 1; + Null #t3; + #L3: + { + anonymous#this.{core::int::isEven}{core::bool}; + { + #t3 = null; + break #L3; + } + } + } + { + final synthesized core::int anonymous#this = 1; + Null #t4; + #L4: + { + anonymous#this.{core::int::isEven}{core::bool}; + { + #t4 = null; + break #L4; + } + } + } + { + final synthesized core::int anonymous#this = 1; + core::int #t5; + #L5: + { + { + #t5 = 1; + break #L5; + } + } + } + { + final synthesized core::int anonymous#this = 1; + core::int #t6; + #L6: + { + { + #t6 = anonymous#this; + break #L6; + } + } + } + { + final synthesized core::int anonymous#this = 1; + core::bool #t7; + #L7: + { + { + #t7 = anonymous#this.{core::int::isEven}{core::bool}; + break #L7; + } + } + } + { + final synthesized core::int anonymous#this = 1; + core::bool #t8; + #L8: + { + { + #t8 = anonymous#this.{core::int::isEven}{core::bool}; + break #L8; + } + } + } +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_without_parameter.dart.strong.modular.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_without_parameter.dart.strong.modular.expect new file mode 100644 index 00000000000..5eb84f4bf46 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_without_parameter.dart.strong.modular.expect @@ -0,0 +1,98 @@ +library; +import self as self; +import "dart:core" as core; + +static method main() → void { + { + final synthesized core::int anonymous#this = 1; + Null #t1; + #L1: + { + 1; + { + #t1 = null; + break #L1; + } + } + } + { + final synthesized core::int anonymous#this = 1; + Null #t2; + #L2: + { + anonymous#this; + { + #t2 = null; + break #L2; + } + } + } + { + final synthesized core::int anonymous#this = 1; + Null #t3; + #L3: + { + anonymous#this.{core::int::isEven}{core::bool}; + { + #t3 = null; + break #L3; + } + } + } + { + final synthesized core::int anonymous#this = 1; + Null #t4; + #L4: + { + anonymous#this.{core::int::isEven}{core::bool}; + { + #t4 = null; + break #L4; + } + } + } + { + final synthesized core::int anonymous#this = 1; + core::int #t5; + #L5: + { + { + #t5 = 1; + break #L5; + } + } + } + { + final synthesized core::int anonymous#this = 1; + core::int #t6; + #L6: + { + { + #t6 = anonymous#this; + break #L6; + } + } + } + { + final synthesized core::int anonymous#this = 1; + core::bool #t7; + #L7: + { + { + #t7 = anonymous#this.{core::int::isEven}{core::bool}; + break #L7; + } + } + } + { + final synthesized core::int anonymous#this = 1; + core::bool #t8; + #L8: + { + { + #t8 = anonymous#this.{core::int::isEven}{core::bool}; + break #L8; + } + } + } +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_without_parameter.dart.strong.outline.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_without_parameter.dart.strong.outline.expect new file mode 100644 index 00000000000..2982c48b884 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_without_parameter.dart.strong.outline.expect @@ -0,0 +1,5 @@ +library; +import self as self; + +static method main() → void + ; diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_without_parameter.dart.strong.transformed.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_without_parameter.dart.strong.transformed.expect new file mode 100644 index 00000000000..5eb84f4bf46 --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_without_parameter.dart.strong.transformed.expect @@ -0,0 +1,98 @@ +library; +import self as self; +import "dart:core" as core; + +static method main() → void { + { + final synthesized core::int anonymous#this = 1; + Null #t1; + #L1: + { + 1; + { + #t1 = null; + break #L1; + } + } + } + { + final synthesized core::int anonymous#this = 1; + Null #t2; + #L2: + { + anonymous#this; + { + #t2 = null; + break #L2; + } + } + } + { + final synthesized core::int anonymous#this = 1; + Null #t3; + #L3: + { + anonymous#this.{core::int::isEven}{core::bool}; + { + #t3 = null; + break #L3; + } + } + } + { + final synthesized core::int anonymous#this = 1; + Null #t4; + #L4: + { + anonymous#this.{core::int::isEven}{core::bool}; + { + #t4 = null; + break #L4; + } + } + } + { + final synthesized core::int anonymous#this = 1; + core::int #t5; + #L5: + { + { + #t5 = 1; + break #L5; + } + } + } + { + final synthesized core::int anonymous#this = 1; + core::int #t6; + #L6: + { + { + #t6 = anonymous#this; + break #L6; + } + } + } + { + final synthesized core::int anonymous#this = 1; + core::bool #t7; + #L7: + { + { + #t7 = anonymous#this.{core::int::isEven}{core::bool}; + break #L7; + } + } + } + { + final synthesized core::int anonymous#this = 1; + core::bool #t8; + #L8: + { + { + #t8 = anonymous#this.{core::int::isEven}{core::bool}; + break #L8; + } + } + } +} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_without_parameter.dart.textual_outline.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_without_parameter.dart.textual_outline.expect new file mode 100644 index 00000000000..ab73b3a234a --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_without_parameter.dart.textual_outline.expect @@ -0,0 +1 @@ +void main() {} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/block_without_parameter.dart.textual_outline_modelled.expect b/pkg/front_end/testcases/coverage/anonymous_methods/block_without_parameter.dart.textual_outline_modelled.expect new file mode 100644 index 00000000000..ab73b3a234a --- /dev/null +++ b/pkg/front_end/testcases/coverage/anonymous_methods/block_without_parameter.dart.textual_outline_modelled.expect @@ -0,0 +1 @@ +void main() {} diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart b/pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart index f75b7ab7136..6655649c4e1 100644 --- a/pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart +++ b/pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart @@ -5,12 +5,12 @@ void v = null; void test() { - v. => 1; // Error + v.=> 1; // Error v.(p) => 1; // Error - v?. => 1; // Error + v?.=> 1; // Error v?.(p) => 1; // Error - v.. => 1; // Error + v..=> 1; // Error v..(p) => 1; // Error - v?.. => 1; // Error + v?..=> 1; // Error v?..(p) => 1; // Error } diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart.strong.expect b/pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart.strong.expect index 4cd4831f4c3..847d3866d9b 100644 --- a/pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart.strong.expect +++ b/pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart.strong.expect @@ -3,7 +3,7 @@ library; // Problems in library: // // pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:8:3: Error: This expression has type 'void' and can't be used. -// v. => 1; // Error +// v.=> 1; // Error // ^ // // pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:9:3: Error: This expression has type 'void' and can't be used. @@ -11,7 +11,7 @@ library; // ^ // // pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:10:3: Error: This expression has type 'void' and can't be used. -// v?. => 1; // Error +// v?.=> 1; // Error // ^ // // pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:11:3: Error: This expression has type 'void' and can't be used. @@ -19,7 +19,7 @@ library; // ^ // // pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:12:3: Error: This expression has type 'void' and can't be used. -// v.. => 1; // Error +// v..=> 1; // Error // ^ // // pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:13:3: Error: This expression has type 'void' and can't be used. @@ -27,7 +27,7 @@ library; // ^ // // pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:14:3: Error: This expression has type 'void' and can't be used. -// v?.. => 1; // Error +// v?..=> 1; // Error // ^ // // pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:15:3: Error: This expression has type 'void' and can't be used. @@ -40,20 +40,20 @@ import "dart:core" as core; static field void v = null; static method test() → void { let final synthesized void anonymous#this = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:8:3: Error: This expression has type 'void' and can't be used. - v. => 1; // Error + v.=> 1; // Error ^" in self::v in 1; let void p = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:9:3: Error: This expression has type 'void' and can't be used. v.(p) => 1; // Error ^" in self::v in 1; let synthesized void anonymous#receiver = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:10:3: Error: This expression has type 'void' and can't be used. - v?. => 1; // Error + v?.=> 1; // Error ^" in self::v in anonymous#receiver == null ?{core::int?} null : let final synthesized void anonymous#this = anonymous#receiver as void in 1; let synthesized void anonymous#receiver = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:11:3: Error: This expression has type 'void' and can't be used. v?.(p) => 1; // Error ^" in self::v in anonymous#receiver == null ?{core::int?} null : let void p = anonymous#receiver as void in 1; let final void #t1 = self::v in block { let final synthesized void anonymous#this = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:12:3: Error: This expression has type 'void' and can't be used. - v.. => 1; // Error + v..=> 1; // Error ^" in #t1 in let dynamic #t2 = 1 in anonymous#this; } =>#t1; let final void #t3 = self::v in block { @@ -63,7 +63,7 @@ static method test() → void { } =>#t3; let final void #t5 = self::v in #t5 == null ?{void} null : block { let synthesized void anonymous#receiver = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:14:3: Error: This expression has type 'void' and can't be used. - v?.. => 1; // Error + v?..=> 1; // Error ^" in #t5 in anonymous#receiver == null ?{void} null : let final synthesized void anonymous#this = anonymous#receiver as void in let dynamic #t6 = 1 in anonymous#this; } =>#t5; let final void #t7 = self::v in #t7 == null ?{void} null : block { diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart.strong.modular.expect b/pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart.strong.modular.expect index 4cd4831f4c3..847d3866d9b 100644 --- a/pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart.strong.modular.expect +++ b/pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart.strong.modular.expect @@ -3,7 +3,7 @@ library; // Problems in library: // // pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:8:3: Error: This expression has type 'void' and can't be used. -// v. => 1; // Error +// v.=> 1; // Error // ^ // // pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:9:3: Error: This expression has type 'void' and can't be used. @@ -11,7 +11,7 @@ library; // ^ // // pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:10:3: Error: This expression has type 'void' and can't be used. -// v?. => 1; // Error +// v?.=> 1; // Error // ^ // // pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:11:3: Error: This expression has type 'void' and can't be used. @@ -19,7 +19,7 @@ library; // ^ // // pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:12:3: Error: This expression has type 'void' and can't be used. -// v.. => 1; // Error +// v..=> 1; // Error // ^ // // pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:13:3: Error: This expression has type 'void' and can't be used. @@ -27,7 +27,7 @@ library; // ^ // // pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:14:3: Error: This expression has type 'void' and can't be used. -// v?.. => 1; // Error +// v?..=> 1; // Error // ^ // // pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:15:3: Error: This expression has type 'void' and can't be used. @@ -40,20 +40,20 @@ import "dart:core" as core; static field void v = null; static method test() → void { let final synthesized void anonymous#this = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:8:3: Error: This expression has type 'void' and can't be used. - v. => 1; // Error + v.=> 1; // Error ^" in self::v in 1; let void p = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:9:3: Error: This expression has type 'void' and can't be used. v.(p) => 1; // Error ^" in self::v in 1; let synthesized void anonymous#receiver = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:10:3: Error: This expression has type 'void' and can't be used. - v?. => 1; // Error + v?.=> 1; // Error ^" in self::v in anonymous#receiver == null ?{core::int?} null : let final synthesized void anonymous#this = anonymous#receiver as void in 1; let synthesized void anonymous#receiver = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:11:3: Error: This expression has type 'void' and can't be used. v?.(p) => 1; // Error ^" in self::v in anonymous#receiver == null ?{core::int?} null : let void p = anonymous#receiver as void in 1; let final void #t1 = self::v in block { let final synthesized void anonymous#this = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:12:3: Error: This expression has type 'void' and can't be used. - v.. => 1; // Error + v..=> 1; // Error ^" in #t1 in let dynamic #t2 = 1 in anonymous#this; } =>#t1; let final void #t3 = self::v in block { @@ -63,7 +63,7 @@ static method test() → void { } =>#t3; let final void #t5 = self::v in #t5 == null ?{void} null : block { let synthesized void anonymous#receiver = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:14:3: Error: This expression has type 'void' and can't be used. - v?.. => 1; // Error + v?..=> 1; // Error ^" in #t5 in anonymous#receiver == null ?{void} null : let final synthesized void anonymous#this = anonymous#receiver as void in let dynamic #t6 = 1 in anonymous#this; } =>#t5; let final void #t7 = self::v in #t7 == null ?{void} null : block { diff --git a/pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart.strong.transformed.expect b/pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart.strong.transformed.expect index 5737071cfde..4eaa9ae3987 100644 --- a/pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart.strong.transformed.expect +++ b/pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart.strong.transformed.expect @@ -3,7 +3,7 @@ library; // Problems in library: // // pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:8:3: Error: This expression has type 'void' and can't be used. -// v. => 1; // Error +// v.=> 1; // Error // ^ // // pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:9:3: Error: This expression has type 'void' and can't be used. @@ -11,7 +11,7 @@ library; // ^ // // pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:10:3: Error: This expression has type 'void' and can't be used. -// v?. => 1; // Error +// v?.=> 1; // Error // ^ // // pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:11:3: Error: This expression has type 'void' and can't be used. @@ -19,7 +19,7 @@ library; // ^ // // pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:12:3: Error: This expression has type 'void' and can't be used. -// v.. => 1; // Error +// v..=> 1; // Error // ^ // // pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:13:3: Error: This expression has type 'void' and can't be used. @@ -27,7 +27,7 @@ library; // ^ // // pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:14:3: Error: This expression has type 'void' and can't be used. -// v?.. => 1; // Error +// v?..=> 1; // Error // ^ // // pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:15:3: Error: This expression has type 'void' and can't be used. @@ -40,20 +40,20 @@ import "dart:core" as core; static field void v = null; static method test() → void { let final synthesized void anonymous#this = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:8:3: Error: This expression has type 'void' and can't be used. - v. => 1; // Error + v.=> 1; // Error ^" in self::v in 1; let void p = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:9:3: Error: This expression has type 'void' and can't be used. v.(p) => 1; // Error ^" in self::v in 1; let synthesized void anonymous#receiver = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:10:3: Error: This expression has type 'void' and can't be used. - v?. => 1; // Error + v?.=> 1; // Error ^" in self::v in anonymous#receiver == null ?{core::int?} null : let final synthesized void anonymous#this = anonymous#receiver as{Unchecked} void in 1; let synthesized void anonymous#receiver = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:11:3: Error: This expression has type 'void' and can't be used. v?.(p) => 1; // Error ^" in self::v in anonymous#receiver == null ?{core::int?} null : let void p = anonymous#receiver as{Unchecked} void in 1; let final void #t1 = self::v in block { let final synthesized void anonymous#this = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:12:3: Error: This expression has type 'void' and can't be used. - v.. => 1; // Error + v..=> 1; // Error ^" in #t1 in let dynamic #t2 = 1 in anonymous#this; } =>#t1; let final void #t3 = self::v in block { @@ -63,7 +63,7 @@ static method test() → void { } =>#t3; let final void #t5 = self::v in #t5 == null ?{void} null : block { let synthesized void anonymous#receiver = invalid-expression "pkg/front_end/testcases/coverage/anonymous_methods/expression_void_receiver.dart:14:3: Error: This expression has type 'void' and can't be used. - v?.. => 1; // Error + v?..=> 1; // Error ^" in #t5 in anonymous#receiver == null ?{void} null : let final synthesized void anonymous#this = anonymous#receiver as{Unchecked} void in let dynamic #t6 = 1 in anonymous#this; } =>#t5; let final void #t7 = self::v in #t7 == null ?{void} null : block { diff --git a/tests/language/anonymous_methods/block/error_test.dart b/tests/language/anonymous_methods/block/error_test.dart index 89968218182..dd0c63e08bc 100644 --- a/tests/language/anonymous_methods/block/error_test.dart +++ b/tests/language/anonymous_methods/block/error_test.dart @@ -42,19 +42,19 @@ void main() { "".(int i) {}; // ^^^ // [analyzer] COMPILE_TIME_ERROR.ANONYMOUS_METHOD_WRONG_PARAMETER_TYPE -// [cfe] The receiver type 'String' must be assignable to the formal parameter type 'int' of an anonymous method. +// [cfe] The receiver type 'String' must be assignable to the formal parameter type 'int' in an anonymous method. // Using a void value as receiver. StringBuffer('').{ return print('0'); }.toString(); //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // [analyzer] COMPILE_TIME_ERROR.USE_OF_VOID_RESULT -// ^ +//^ // [cfe] This expression has type 'void' and can't be used. StringBuffer('').{ return print('0'); }.{ print('1'); }; //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // [analyzer] COMPILE_TIME_ERROR.USE_OF_VOID_RESULT -// ^ +//^ // [cfe] This expression has type 'void' and can't be used. // Break outside of loop/switch. diff --git a/tests/language/anonymous_methods/block/null_aware_plain_test.dart b/tests/language/anonymous_methods/block/null_aware_plain_test.dart index fb82904f2d9..5bededd7ee9 100644 --- a/tests/language/anonymous_methods/block/null_aware_plain_test.dart +++ b/tests/language/anonymous_methods/block/null_aware_plain_test.dart @@ -146,7 +146,7 @@ void main() { v3.expectStaticType>; Expect.equals(buffer?.length, v1); Expect.equals('true', v2); - Expect.equals(false, v3); + Expect.equals(true, v3); } // Dependency on parameter.