Skip to content

Commit 707ecda

Browse files
jensjohacommit-bot@chromium.org
authored andcommitted
[analyzer] Add test for bang before type arguments
In https://dart-review.googlesource.com/c/sdk/+/128402 I was asked to add a test to the analyzer. This is the (somewhat belated) follow-up that does that. Change-Id: I7065882b458a480b12d79a4913a59e2bee4f35da Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136184 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Jens Johansen <jensj@google.com>
1 parent c11c0ae commit 707ecda

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

pkg/analyzer/test/generated/parser_fasta_test.dart

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3152,6 +3152,58 @@ main() {
31523152
expect(target.operand.toSource(), "foo");
31533153
}
31543154

3155+
void test_bangBeforeFuctionCall1() {
3156+
// https://github.com/dart-lang/sdk/issues/39776
3157+
var unit = parseCompilationUnit('f() { Function? f1; f1!(42); }');
3158+
var funct = unit.declarations[0] as FunctionDeclaration;
3159+
var body = funct.functionExpression.body as BlockFunctionBody;
3160+
var statement1 = body.block.statements[0] as VariableDeclarationStatement;
3161+
expect(statement1.toSource(), "Function? f1;");
3162+
var statement2 = body.block.statements[1] as ExpressionStatement;
3163+
3164+
// expression is "f1!(42)"
3165+
var expression = statement2.expression as FunctionExpressionInvocation;
3166+
expect(expression.toSource(), "f1!(42)");
3167+
3168+
var functionExpression = expression.function as PostfixExpression;
3169+
SimpleIdentifier identifier = functionExpression.operand;
3170+
expect(identifier.name, 'f1');
3171+
expect(functionExpression.operator.lexeme, '!');
3172+
3173+
expect(expression.typeArguments, null);
3174+
3175+
expect(expression.argumentList.arguments.length, 1);
3176+
IntegerLiteral argument = expression.argumentList.arguments.single;
3177+
expect(argument.value, 42);
3178+
}
3179+
3180+
void test_bangBeforeFuctionCall2() {
3181+
// https://github.com/dart-lang/sdk/issues/39776
3182+
var unit = parseCompilationUnit('f() { Function f2; f2!<int>(42); }');
3183+
var funct = unit.declarations[0] as FunctionDeclaration;
3184+
var body = funct.functionExpression.body as BlockFunctionBody;
3185+
var statement1 = body.block.statements[0] as VariableDeclarationStatement;
3186+
expect(statement1.toSource(), "Function f2;");
3187+
var statement2 = body.block.statements[1] as ExpressionStatement;
3188+
3189+
// expression is "f2!<int>(42)"
3190+
var expression = statement2.expression as FunctionExpressionInvocation;
3191+
expect(expression.toSource(), "f2!<int>(42)");
3192+
3193+
var functionExpression = expression.function as PostfixExpression;
3194+
SimpleIdentifier identifier = functionExpression.operand;
3195+
expect(identifier.name, 'f2');
3196+
expect(functionExpression.operator.lexeme, '!');
3197+
3198+
expect(expression.typeArguments.arguments.length, 1);
3199+
TypeName typeArgument = expression.typeArguments.arguments.single;
3200+
expect(typeArgument.name.name, "int");
3201+
3202+
expect(expression.argumentList.arguments.length, 1);
3203+
IntegerLiteral argument = expression.argumentList.arguments.single;
3204+
expect(argument.value, 42);
3205+
}
3206+
31553207
void test_nullCheckOnLiteral_disabled() {
31563208
parseCompilationUnit('f() { var x = 0!; }',
31573209
errors: [expectedError(ParserErrorCode.EXPERIMENT_NOT_ENABLED, 15, 1)],

0 commit comments

Comments
 (0)