Skip to content

Commit 80cda05

Browse files
jensjohaCommit Queue
authored andcommitted
[CFE] Textual outline: allow formatter crash in experiment not enabled
Change-Id: Idefb2647592e359388901edd0218b21d511fd7bc Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/412580 Commit-Queue: Jens Johansen <[email protected]> Reviewed-by: Chloe Stefantsova <[email protected]>
1 parent 1e93ed7 commit 80cda05

18 files changed

+161
-34
lines changed

pkg/front_end/test/textual_outline_suite.dart

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import 'dart:typed_data';
88
import 'package:_fe_analyzer_shared/src/scanner/abstract_scanner.dart'
99
show ScannerConfiguration;
1010
import 'package:_fe_analyzer_shared/src/scanner/token.dart';
11-
import 'package:dart_style/dart_style.dart' show DartFormatter;
11+
import 'package:dart_style/dart_style.dart'
12+
show DartFormatter, FormatterException;
1213
import 'package:front_end/src/api_prototype/experimental_flags.dart';
1314
import 'package:front_end/src/util/textual_outline.dart';
1415
import 'package:testing/testing.dart'
@@ -110,6 +111,17 @@ class TextualOutline extends Step<TestDescription, TestDescription, Context> {
110111
Map<ExperimentalFlag, bool> experimentalFlagsExplicit =
111112
folderOptions.computeExplicitExperimentalFlags(const {});
112113

114+
bool allowFormatterCrash = false;
115+
for (MapEntry<ExperimentalFlag, bool> entry
116+
in experimentalFlagsExplicit.entries) {
117+
if (entry.value) {
118+
if (!entry.key.isEnabledByDefault) {
119+
allowFormatterCrash = true;
120+
break;
121+
}
122+
}
123+
}
124+
113125
Uint8List bytes = new File.fromUri(description.uri).readAsBytesSync();
114126
for (bool modelled in [false, true]) {
115127
TextualOutlineInfoForTesting info = new TextualOutlineInfoForTesting();
@@ -166,6 +178,13 @@ class TextualOutline extends Step<TestDescription, TestDescription, Context> {
166178
} catch (e, st) {
167179
formatterException = e;
168180
formatterExceptionSt = st;
181+
if (e is FormatterException) {
182+
for (var error in e.errors) {
183+
if (error.errorCode.name == "EXPERIMENT_NOT_ENABLED") {
184+
allowFormatterCrash = true;
185+
}
186+
}
187+
}
169188
}
170189
}
171190

@@ -184,22 +203,12 @@ class TextualOutline extends Step<TestDescription, TestDescription, Context> {
184203
null, context.expectationSet["UnknownChunk"], description.uri);
185204
}
186205

187-
if (formatterException != null && !info.hasParserErrors) {
188-
bool hasUnreleasedExperiment = false;
189-
for (MapEntry<ExperimentalFlag, bool> entry
190-
in experimentalFlagsExplicit.entries) {
191-
if (entry.value) {
192-
if (!entry.key.isEnabledByDefault) {
193-
hasUnreleasedExperiment = true;
194-
break;
195-
}
196-
}
197-
}
198-
if (!hasUnreleasedExperiment) {
199-
return new Result(null, context.expectationSet["FormatterCrash"],
200-
formatterException,
201-
trace: formatterExceptionSt);
202-
}
206+
if (formatterException != null &&
207+
!info.hasParserErrors &&
208+
!allowFormatterCrash) {
209+
return new Result(
210+
null, context.expectationSet["FormatterCrash"], formatterException,
211+
trace: formatterExceptionSt);
203212
}
204213
}
205214

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @dart = 2.12
2+
3+
class C<T> {
4+
const C();
5+
}
6+
7+
@C()
8+
@C<dynamic>()
9+
@C<int>()
10+
void foo() {}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @dart = 2.19
2+
3+
abstract base class B {}
4+
5+
base class A {}
6+
7+
base class C = Object with M;
8+
9+
base mixin M {}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @dart = 2.16
2+
3+
enum A { a; A() : super(); }
4+
5+
enum B { b; const B() : super(); }
6+
7+
main() {}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @dart = 2.18
2+
3+
extension type ExtensionType1(int it) {}
4+
5+
extension type ExtensionType2<T>._(int it) implements int, ExtensionType1 {}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @dart = 2.19
2+
3+
abstract final class B {}
4+
5+
final class A {}
6+
7+
final class C = Object with M;
8+
9+
mixin M {}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @dart = 2.19
2+
3+
abstract interface class B {}
4+
5+
interface class A {}
6+
7+
interface class C = Object with M;
8+
9+
mixin M {}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @dart = 2.16
2+
3+
enum T { t(); void test() { print("Success"); } }
4+
5+
void main() {}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @dart = 2.16
2+
3+
enum T { t; const T.named(); }
4+
5+
void main() {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// @dart = 2.13
2+
3+
abstract class Bar implements List<List<List<String>>> {}
4+
5+
class Foo {
6+
Foo operator >>>(_) => this;
7+
}
8+
9+
extension on Symbol {
10+
String call(_) => "Called";
11+
String operator >(_) => "Greater Than used";
12+
}
13+
14+
main() {}

0 commit comments

Comments
 (0)