Skip to content

Commit 863e958

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Fix the issue with reusing LinkedElementFactory and supertype for Object.
Bug: https://buganizer.corp.google.com/issues/170429675 Change-Id: Ieaec29e8b09ce5cc9c02e7dce5919e8b56278910 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/166789 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent d650ea9 commit 863e958

File tree

4 files changed

+42
-56
lines changed

4 files changed

+42
-56
lines changed

pkg/analyzer/lib/src/dart/element/element.dart

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -860,18 +860,19 @@ class ClassElementImpl extends AbstractClassElementImpl
860860
InterfaceType get supertype {
861861
if (_supertype != null) return _supertype;
862862

863-
if (linkedNode != null) {
864-
var context = enclosingUnit.linkedContext;
865-
866-
var coreTypes = context.bundleContext.elementFactory.coreTypes;
867-
if (identical(this, coreTypes.objectClass)) {
868-
return null;
869-
}
863+
if (hasModifier(Modifier.DART_CORE_OBJECT)) {
864+
return null;
865+
}
870866

871-
var type = context.getSuperclass(linkedNode)?.type;
867+
if (linkedNode != null) {
868+
var type = linkedContext.getSuperclass(linkedNode)?.type;
872869
if (_isInterfaceTypeClass(type)) {
873870
return _supertype = type;
874871
}
872+
if (library.isDartCore && name == 'Object') {
873+
setModifier(Modifier.DART_CORE_OBJECT, true);
874+
return null;
875+
}
875876
return _supertype = library.typeProvider.objectType;
876877
}
877878
return _supertype;
@@ -5898,61 +5899,65 @@ class Modifier implements Comparable<Modifier> {
58985899
/// Indicates that the modifier 'covariant' was applied to the element.
58995900
static const Modifier COVARIANT = Modifier('COVARIANT', 3);
59005901

5902+
/// Indicates that the class is `Object` from `dart:core`.
5903+
static const Modifier DART_CORE_OBJECT = Modifier('DART_CORE_OBJECT', 4);
5904+
59015905
/// Indicates that the import element represents a deferred library.
5902-
static const Modifier DEFERRED = Modifier('DEFERRED', 4);
5906+
static const Modifier DEFERRED = Modifier('DEFERRED', 5);
59035907

59045908
/// Indicates that a class element was defined by an enum declaration.
5905-
static const Modifier ENUM = Modifier('ENUM', 5);
5909+
static const Modifier ENUM = Modifier('ENUM', 6);
59065910

59075911
/// Indicates that a class element was defined by an enum declaration.
5908-
static const Modifier EXTERNAL = Modifier('EXTERNAL', 6);
5912+
static const Modifier EXTERNAL = Modifier('EXTERNAL', 7);
59095913

59105914
/// Indicates that the modifier 'factory' was applied to the element.
5911-
static const Modifier FACTORY = Modifier('FACTORY', 7);
5915+
static const Modifier FACTORY = Modifier('FACTORY', 8);
59125916

59135917
/// Indicates that the modifier 'final' was applied to the element.
5914-
static const Modifier FINAL = Modifier('FINAL', 8);
5918+
static const Modifier FINAL = Modifier('FINAL', 9);
59155919

59165920
/// Indicates that an executable element has a body marked as being a
59175921
/// generator.
5918-
static const Modifier GENERATOR = Modifier('GENERATOR', 9);
5922+
static const Modifier GENERATOR = Modifier('GENERATOR', 10);
59195923

59205924
/// Indicates that the pseudo-modifier 'get' was applied to the element.
5921-
static const Modifier GETTER = Modifier('GETTER', 10);
5925+
static const Modifier GETTER = Modifier('GETTER', 11);
59225926

59235927
/// A flag used for libraries indicating that the defining compilation unit
59245928
/// contains at least one import directive whose URI uses the "dart-ext"
59255929
/// scheme.
5926-
static const Modifier HAS_EXT_URI = Modifier('HAS_EXT_URI', 11);
5930+
static const Modifier HAS_EXT_URI = Modifier('HAS_EXT_URI', 12);
59275931

59285932
/// Indicates that the associated element did not have an explicit type
59295933
/// associated with it. If the element is an [ExecutableElement], then the
59305934
/// type being referred to is the return type.
5931-
static const Modifier IMPLICIT_TYPE = Modifier('IMPLICIT_TYPE', 12);
5935+
static const Modifier IMPLICIT_TYPE = Modifier('IMPLICIT_TYPE', 13);
59325936

59335937
/// Indicates that modifier 'lazy' was applied to the element.
5934-
static const Modifier LATE = Modifier('LATE', 13);
5938+
static const Modifier LATE = Modifier('LATE', 14);
59355939

59365940
/// Indicates that a class is a mixin application.
5937-
static const Modifier MIXIN_APPLICATION = Modifier('MIXIN_APPLICATION', 14);
5941+
static const Modifier MIXIN_APPLICATION = Modifier('MIXIN_APPLICATION', 15);
59385942

59395943
/// Indicates that the pseudo-modifier 'set' was applied to the element.
5940-
static const Modifier SETTER = Modifier('SETTER', 15);
5944+
static const Modifier SETTER = Modifier('SETTER', 16);
59415945

59425946
/// Indicates that the modifier 'static' was applied to the element.
5943-
static const Modifier STATIC = Modifier('STATIC', 16);
5947+
static const Modifier STATIC = Modifier('STATIC', 17);
59445948

59455949
/// Indicates that the element does not appear in the source code but was
59465950
/// implicitly created. For example, if a class does not define any
59475951
/// constructors, an implicit zero-argument constructor will be created and it
59485952
/// will be marked as being synthetic.
5949-
static const Modifier SYNTHETIC = Modifier('SYNTHETIC', 17);
5953+
static const Modifier SYNTHETIC = Modifier('SYNTHETIC', 18);
59505954

59515955
static const List<Modifier> values = [
59525956
ABSTRACT,
59535957
ASYNCHRONOUS,
59545958
CONST,
59555959
COVARIANT,
5960+
DART_CORE_OBJECT,
59565961
DEFERRED,
59575962
ENUM,
59585963
EXTERNAL,

pkg/analyzer/lib/src/summary2/core_types.dart

Lines changed: 0 additions & 27 deletions
This file was deleted.

pkg/analyzer/lib/src/summary2/linked_element_factory.dart

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import 'package:analyzer/src/dart/element/element.dart';
1010
import 'package:analyzer/src/dart/element/type_provider.dart';
1111
import 'package:analyzer/src/dart/resolver/scope.dart';
1212
import 'package:analyzer/src/summary/idl.dart';
13-
import 'package:analyzer/src/summary2/core_types.dart';
1413
import 'package:analyzer/src/summary2/lazy_ast.dart';
1514
import 'package:analyzer/src/summary2/linked_bundle_context.dart';
1615
import 'package:analyzer/src/summary2/linked_unit_context.dart';
@@ -22,8 +21,6 @@ class LinkedElementFactory {
2221
final Reference rootReference;
2322
final Map<String, LinkedLibraryContext> libraryMap = {};
2423

25-
CoreTypes _coreTypes;
26-
2724
LinkedElementFactory(
2825
this.analysisContext,
2926
this.analysisSession,
@@ -34,10 +31,6 @@ class LinkedElementFactory {
3431
declareDartCoreDynamicNever();
3532
}
3633

37-
CoreTypes get coreTypes {
38-
return _coreTypes ??= CoreTypes(this);
39-
}
40-
4134
Reference get dynamicRef {
4235
return rootReference.getChild('dart:core').getChild('dynamic');
4336
}

pkg/analyzer/test/src/dart/micro/simple_file_resolver_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,21 @@ int b = a;
580580
]);
581581
}
582582

583+
test_switchCase_implementsEquals_enum() async {
584+
await assertNoErrorsInCode(r'''
585+
enum MyEnum {a, b, c}
586+
587+
void f(MyEnum myEnum) {
588+
switch (myEnum) {
589+
case MyEnum.a:
590+
break;
591+
default:
592+
break;
593+
}
594+
}
595+
''');
596+
}
597+
583598
test_unknown_uri() async {
584599
await assertErrorsInCode(r'''
585600
import 'foo:bar';

0 commit comments

Comments
 (0)