Skip to content

Commit 133a577

Browse files
johnniwinthercommit-bot@chromium.org
authored andcommitted
[cfe] Add test for issue 37108
Change-Id: Ib027812341cec8b2ed7b69709432a3940f470848 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107287 Commit-Queue: Johnni Winther <johnniwinther@google.com> Reviewed-by: Jens Johansen <jensj@google.com>
1 parent c4af35c commit 133a577

10 files changed

Lines changed: 132 additions & 1 deletion

pkg/front_end/test/fasta/testing/suite.dart

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import 'dart:convert' show jsonDecode;
1010

1111
import 'dart:io' show File, Platform;
1212

13-
import 'package:kernel/ast.dart' show Library, Component;
13+
import 'package:kernel/ast.dart'
14+
show AwaitExpression, Component, Library, Node, Visitor;
1415

1516
import 'package:kernel/class_hierarchy.dart' show ClassHierarchy;
1617

@@ -422,10 +423,37 @@ class Transform extends Step<Component, Component, FastaContext> {
422423
} finally {
423424
backendTarget.enabled = false;
424425
}
426+
List<String> errors = VerifyTransformed.verify(component);
427+
if (errors.isNotEmpty) {
428+
return fail(component, errors.join('\n'));
429+
}
425430
return pass(component);
426431
}
427432
}
428433

434+
/// Visitor that checks that the component has been transformed properly.
435+
// TODO(johnniwinther): Add checks for all nodes that are unsupported after
436+
// transformation.
437+
class VerifyTransformed extends Visitor<void> {
438+
List<String> errors = [];
439+
440+
@override
441+
void defaultNode(Node node) {
442+
node.visitChildren(this);
443+
}
444+
445+
@override
446+
void visitAwaitExpression(AwaitExpression node) {
447+
errors.add("ERROR: Untransformed await expression: $node");
448+
}
449+
450+
static List<String> verify(Component component) {
451+
VerifyTransformed visitor = new VerifyTransformed();
452+
component.accept(visitor);
453+
return visitor.errors;
454+
}
455+
}
456+
429457
class TestVmTarget extends VmTarget {
430458
bool enabled = false;
431459

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
main() {
6+
foo();
7+
}
8+
9+
foo() {
10+
// ignore: await_in_wrong_context
11+
await foo();
12+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
library;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/await_in_non_async.dart:11:3: Error: 'await' can only be used in 'async' or 'async*' methods.
6+
// await foo();
7+
// ^^^^^
8+
//
9+
import self as self;
10+
11+
static method main() → dynamic {
12+
self::foo();
13+
}
14+
static method foo() → dynamic {
15+
await self::foo();
16+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
library;
2+
import self as self;
3+
4+
static method main() → dynamic
5+
;
6+
static method foo() → dynamic
7+
;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
library;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/await_in_non_async.dart:11:3: Error: 'await' can only be used in 'async' or 'async*' methods.
6+
// await foo();
7+
// ^^^^^
8+
//
9+
import self as self;
10+
11+
static method main() → dynamic {
12+
self::foo();
13+
}
14+
static method foo() → dynamic {
15+
await self::foo();
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
library;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/await_in_non_async.dart:11:3: Error: 'await' can only be used in 'async' or 'async*' methods.
6+
// await foo();
7+
// ^^^^^
8+
//
9+
import self as self;
10+
11+
static method main() → dynamic {
12+
self::foo();
13+
}
14+
static method foo() → dynamic {
15+
await self::foo();
16+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
# for details. All rights reserved. Use of this source code is governed by a
3+
# BSD-style license that can be found in the LICENSE.md file.
4+
5+
type: newworld
6+
omitPlatform: false
7+
worlds:
8+
- entry: main.dart
9+
errors: false
10+
warnings: false
11+
sources:
12+
main.dart: |
13+
main() {
14+
foo();
15+
}
16+
foo() {}
17+
expectedLibraryCount: 1
18+
expectsPlatform: true
19+
- entry: main.dart
20+
errors: true
21+
warnings: false
22+
expectInitializeFromDill: false
23+
fromComponent: true
24+
invalidate:
25+
- main.dart
26+
sources:
27+
main.dart: |
28+
main() {
29+
await foo();
30+
}
31+
foo() {}
32+
expectedLibraryCount: 1
33+
expectsPlatform: true

pkg/front_end/testcases/legacy.status

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
DeltaBlue: Fail # Fasta and dartk disagree on static initializers
99
ambiguous_exports: RuntimeError # Expected, this file exports two main methods.
10+
await_in_non_async: Fail # Issue 37108.
1011
bug31124: RuntimeError # Test has no main method (and we shouldn't add one).
1112
call: Fail # Test can't run.
1213
constructor_const_inference: RuntimeError # Test exercises strong mode semantics. See also Issue #33813.

pkg/front_end/testcases/strong.status

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ abstract_members: TypeCheckError
1010
accessors: RuntimeError
1111
ambiguous_exports: RuntimeError # Expected, this file exports two main methods.
1212
argument_mismatch: InstrumentationMismatch # Test assumes Dart 1.0 semantics
13+
await_in_non_async: Fail # Issue 37108.
1314
bug21938: TypeCheckError
1415
bug30695: TypeCheckError
1516
bug31124: RuntimeError # Test has no main method (and we shouldn't add one).

pkg/front_end/testcases/text_serialization.status

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ arrow_function: TextSerializationFailure # Was: Pass
2424
async_function: TextSerializationFailure # Was: Pass
2525
async_nested: TextSerializationFailure # Was: Pass
2626
await: TextSerializationFailure # Was: Pass
27+
await_in_non_async: TextSerializationFailure
2728
bad_setter_abstract: TextSerializationFailure # Was: Pass
2829
bad_store: TextSerializationFailure # Was: Pass
2930
bad_type_variable_uses_in_supertypes: TextSerializationFailure

0 commit comments

Comments
 (0)