Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions test/classes_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -197,5 +197,37 @@ class D implements Object {}
expect(toString.canonicalEnclosingContainer!.isDartCoreObject, isTrue);
}

void test_multiplyInheritedOperator_oneIsPrivate() async {
// Test an edge case where inherited ExecutableElements can come both from
// private classes and public interfaces. The test makes sure the class
// still takes precedence.
// See https://github.com/dart-lang/dartdoc/issues/1561.
var library = await bootPackageWithLibrary('''
abstract class A<K, V> {
void operator []=(K key, V value);
}

abstract class B<K, V> implements A<K, V> {
@override
operator []=(K key, V value);
}

abstract class C<K, V> extends B<K, V> {}

abstract class _D<K, V> implements A<K, V> {
@override
void operator []=(K key, V value);
}

abstract class E<K, V> = C<K, V> with _D<K, V>;
''');

var indexAssign =
library.classes.named('E').inheritedOperators.named('operator []=');
expect(indexAssign.element2.enclosingElement2!.name3, '_D');
expect(indexAssign.canonicalEnclosingContainer!.name, 'E');
expect(indexAssign.canonicalModelElement!.enclosingElement!.name, 'E');
}

// TODO(srawlins): Test everything else about classes.
}
19 changes: 3 additions & 16 deletions test/end2end/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// ignore_for_file: non_constant_identifier_names

// ignore_for_file: analyzer_use_new_elements

// ignore_for_file: non_constant_identifier_names

import 'package:analyzer/dart/element/element2.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/source/line_info.dart';
Expand Down Expand Up @@ -909,7 +909,7 @@ void main() async {
});

test('can import other libraries with unusual URIs', () {
final importLists = fakeLibrary.element2.fragments
final importLists = fakeLibrary.element2.fragments
.map((fragment) => fragment.libraryImports2);
final exportLists = fakeLibrary.element2.fragments
.map((fragment) => fragment.libraryExports2);
Expand Down Expand Up @@ -1680,19 +1680,6 @@ void main() async {
var gadgetGetter = GadgetExtender.instanceFields.named('gadgetGetter');
expect(gadgetGetter.isCanonical, isTrue);
});

test(
'ExecutableElements from private classes and from public interfaces (#1561)',
() {
var MIEEMixinWithOverride =
fakeLibrary.classes.wherePublic.named('MIEEMixinWithOverride');
var problematicOperator =
MIEEMixinWithOverride.inheritedOperators.named('operator []=');
expect(problematicOperator.element2.enclosingElement2?.name3,
equals('_MIEEPrivateOverride'));
expect(problematicOperator.canonicalModelElement!.enclosingElement!.name,
equals('MIEEMixinWithOverride'));
});
});

group('Mixin', () {
Expand Down
28 changes: 0 additions & 28 deletions testing/test_package/lib/fake.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1117,34 +1117,6 @@ extension OnOldSchool on OldSchoolMixin {

class School with OldSchoolMixin, NewSchoolMixin {}

//
//
//

/// Test an edge case for cases where inherited ExecutableElements can come
/// both from private classes and public interfaces. The test makes sure the
/// class still takes precedence (#1561).
abstract class MIEEMixinWithOverride<K, V> = MIEEBase<K, V>
with _MIEEPrivateOverride<K, V>;

abstract class _MIEEPrivateOverride<K, V> implements MIEEThing<K, V> {
// ignore: annotate_overrides
void operator []=(K key, V value) {
throw UnsupportedError("Never use this");
}
}

abstract class MIEEBase<K, V> extends MIEEMixin<K, V> {}

abstract class MIEEMixin<K, V> implements MIEEThing<K, V> {
// ignore: annotate_overrides
operator []=(K key, V value);
}

abstract class MIEEThing<K, V> {
void operator []=(K key, V value);
}

abstract class ImplementingClassForTool {
/// Invokes a tool from inherited documentation via `implemented`
///
Expand Down