Skip to content

Commit 1e7cb9d

Browse files
srawlinsCommit Queue
authored andcommitted
analyzer: Change the mock SDK Enum class to declare index and _name as concrete
This allows us to write enums in the mock SDK (which is currently broken). This will allow me to land such an enum in the SDK, in https://dart-review.googlesource.com/c/sdk/+/445403. This diverges from the actual Dart SDK implementation of the Enum class and the _Enum class. I think this is an acceptable divergence; these classes hardly ever change, and the changes will be easy to follow when they come, however many months or years from now. Change-Id: Ia6ff3803415af8c251dbee330a218f2618395cc4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/446141 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 7d3ecd2 commit 1e7cb9d

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

pkg/analysis_server/test/analysis/notification_navigation_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ void f() {
941941
''');
942942
await prepareNavigation();
943943
assertHasRegion('index');
944-
assertHasTargetInDartCore('index; // Enum');
944+
assertHasTargetInDartCore('index => -1; // Enum');
945945
}
946946

947947
Future<void> test_enum_method() async {

pkg/analyzer/lib/src/test_utilities/mock_sdk.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,14 @@ class Duration implements Comparable<Duration> {
406406
407407
@Since("2.14")
408408
abstract class Enum {
409-
int get index; // Enum
410-
String get _name;
409+
// These two getters are a departure here, from the real SDK. Here we have
410+
// concrete getters; the SDK has abstract gettesr. The real implementations
411+
// of enums require a significant amount of desugaring.
412+
// (See the spec:
413+
// https://github.com/dart-lang/language/blob/main/accepted/2.17/enhanced-enums/feature-specification.md#implementation).
414+
// As an alternative to desugaring, we make these getters concrete.
415+
int get index => -1; // Enum; this comment is necessary for notification_navigation_test.
416+
String get _name => '';
411417
}
412418
413419
abstract class _Enum implements Enum {

0 commit comments

Comments
 (0)