KT-14071 Type alias cannot be used as a qualifier for super

Use corresponding class for type alias in super qualifier resolution.
This commit is contained in:
Dmitry Petrov
2016-09-29 16:24:55 +03:00
parent ff7c7538d4
commit bd95d2ef4c
4 changed files with 96 additions and 0 deletions
@@ -451,6 +451,10 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
supertype = components.typeResolver.resolveType(context.scope, superTypeQualifier, context.trace, true);
}
if (classifierCandidate instanceof TypeAliasDescriptor) {
classifierCandidate = ((TypeAliasDescriptor) classifierCandidate).getClassDescriptor();
}
if (supertype != null) {
if (supertypes.contains(supertype)) {
result = supertype;
@@ -0,0 +1,39 @@
open class Base {
open fun foo() {}
}
open class GenericBase<T> {
open fun foo() {}
}
class Unrelated {
fun foo() {}
}
typealias B = Base
typealias U = Unrelated
typealias GB<T> = GenericBase<T>
class TestSuperForBase : B() {
typealias MyBase = B
override fun foo() {
super<Base>.foo()
super<B>.foo()
super<MyBase>.foo()
super<<!NOT_A_SUPERTYPE!>U<!>>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>foo<!>()
}
}
class TestSuperForGenericBase<T> : GB<T>() {
typealias MyBase = GB<T>
typealias MyBaseInt = GB<Int>
override fun foo() {
super<GenericBase>.foo()
super<GB>.foo()
super<MyBase>.foo()
super<MyBaseInt>.foo() // Type arguments don't matter here
super<<!NOT_A_SUPERTYPE!>U<!>>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>foo<!>()
}
}
@@ -0,0 +1,47 @@
package
public open class Base {
public constructor Base()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open fun foo(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public open class GenericBase</*0*/ T> {
public constructor GenericBase</*0*/ T>()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open fun foo(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class TestSuperForBase : B /* = Base */ {
public constructor TestSuperForBase()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ fun foo(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public typealias MyBase = B
}
public final class TestSuperForGenericBase</*0*/ T> : GB<T> /* = GenericBase<T> */ {
public constructor TestSuperForGenericBase</*0*/ T>()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ fun foo(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public typealias MyBase /*captured type parameters: /*0*/ T*/ = GB<T>
public typealias MyBaseInt /*captured type parameters: /*0*/ T*/ = GB<kotlin.Int>
}
public final class Unrelated {
public constructor Unrelated()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun foo(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public typealias B = Base
public typealias GB</*0*/ T> = GenericBase<T>
public typealias U = Unrelated
@@ -20604,6 +20604,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("typeAliasAsSuperQualifier.kt")
public void testTypeAliasAsSuperQualifier() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/typeAliasAsSuperQualifier.kt");
doTest(fileName);
}
@TestMetadata("typeAliasConstructor.kt")
public void testTypeAliasConstructor() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/typeAliasConstructor.kt");