mirror of
https://github.com/dart-lang/sdk
synced 2024-10-06 12:57:42 +00:00
Extension types. Apply substitution when copy superinterface members into extension types.
Change-Id: I93d8ab4582491bad262253eedc94dc63d33c5457 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/319900 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Phil Quitslund <pquitslund@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
2d0fba3981
commit
66b18bce40
|
@ -692,9 +692,10 @@ class InheritanceManager3 {
|
||||||
final extensionCandidates = <Name, List<ExecutableElement>>{};
|
final extensionCandidates = <Name, List<ExecutableElement>>{};
|
||||||
final notExtensionCandidates = <Name, List<ExecutableElement>>{};
|
final notExtensionCandidates = <Name, List<ExecutableElement>>{};
|
||||||
for (final interface in augmented.interfaces) {
|
for (final interface in augmented.interfaces) {
|
||||||
|
final substitution = Substitution.fromInterfaceType(interface);
|
||||||
for (final entry in getInterface(interface.element).map.entries) {
|
for (final entry in getInterface(interface.element).map.entries) {
|
||||||
final name = entry.key;
|
final name = entry.key;
|
||||||
final executable = entry.value;
|
final executable = ExecutableMember.from2(entry.value, substitution);
|
||||||
if (executable.enclosingElement is ExtensionTypeElement) {
|
if (executable.enclosingElement is ExtensionTypeElement) {
|
||||||
(extensionCandidates[name] ??= []).add(executable);
|
(extensionCandidates[name] ??= []).add(executable);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -765,6 +765,34 @@ declared
|
||||||
''');
|
''');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test_noDeclaration_implementClass_generic_method() async {
|
||||||
|
final library = await buildLibrary(r'''
|
||||||
|
class A<T> {
|
||||||
|
void foo(T a) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
class B extends A<int> {}
|
||||||
|
|
||||||
|
extension type C(B it) implements A<int> {}
|
||||||
|
''');
|
||||||
|
|
||||||
|
final element = library.extensionType('C');
|
||||||
|
assertInterfaceText(element, r'''
|
||||||
|
map
|
||||||
|
foo: MethodMember
|
||||||
|
base: self::@class::A::@method::foo
|
||||||
|
substitution: {T: int}
|
||||||
|
it: self::@extensionType::C::@getter::it
|
||||||
|
declared
|
||||||
|
it: self::@extensionType::C::@getter::it
|
||||||
|
redeclared
|
||||||
|
foo
|
||||||
|
MethodMember
|
||||||
|
base: self::@class::A::@method::foo
|
||||||
|
substitution: {T: int}
|
||||||
|
''');
|
||||||
|
}
|
||||||
|
|
||||||
test_noDeclaration_implementClass_implementExtensionType_hasConflict() async {
|
test_noDeclaration_implementClass_implementExtensionType_hasConflict() async {
|
||||||
final library = await buildLibrary(r'''
|
final library = await buildLibrary(r'''
|
||||||
class A {
|
class A {
|
||||||
|
@ -932,6 +960,36 @@ redeclared
|
||||||
''');
|
''');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test_noDeclaration_implementExtensionType_generic_method() async {
|
||||||
|
final library = await buildLibrary(r'''
|
||||||
|
extension type A<T>(T it) {
|
||||||
|
void foo(T a) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension type B(int it) implements A<int> {}
|
||||||
|
''');
|
||||||
|
|
||||||
|
final element = library.extensionType('B');
|
||||||
|
assertInterfaceText(element, r'''
|
||||||
|
map
|
||||||
|
foo: MethodMember
|
||||||
|
base: self::@extensionType::A::@method::foo
|
||||||
|
substitution: {T: int}
|
||||||
|
it: self::@extensionType::B::@getter::it
|
||||||
|
declared
|
||||||
|
it: self::@extensionType::B::@getter::it
|
||||||
|
redeclared
|
||||||
|
foo
|
||||||
|
MethodMember
|
||||||
|
base: self::@extensionType::A::@method::foo
|
||||||
|
substitution: {T: int}
|
||||||
|
it
|
||||||
|
PropertyAccessorMember
|
||||||
|
base: self::@extensionType::A::@getter::it
|
||||||
|
substitution: {T: int}
|
||||||
|
''');
|
||||||
|
}
|
||||||
|
|
||||||
test_noDeclaration_implementExtensionType_method() async {
|
test_noDeclaration_implementExtensionType_method() async {
|
||||||
final library = await buildLibrary(r'''
|
final library = await buildLibrary(r'''
|
||||||
extension type A(int it) {
|
extension type A(int it) {
|
||||||
|
|
Loading…
Reference in a new issue