KT-11588 Type aliases
Additional tests for generic type alias arguments. Small refactoring in TowerLevels.
This commit is contained in:
@@ -241,34 +241,32 @@ private fun ResolutionScope.getContributedVariablesAndObjects(name: Name, locati
|
||||
return getContributedVariables(name, location) + listOfNotNull(objectDescriptor)
|
||||
}
|
||||
|
||||
|
||||
private fun getFakeDescriptorForObject(classifier: ClassifierDescriptor?): FakeCallableDescriptorForObject? {
|
||||
return when (classifier) {
|
||||
is TypeAliasDescriptor ->
|
||||
getFakeDescriptorForObject(classifier.classDescriptor)
|
||||
is ClassDescriptor ->
|
||||
if (classifier.hasClassValueDescriptor)
|
||||
FakeCallableDescriptorForObject(classifier)
|
||||
else
|
||||
null
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
private fun getFakeDescriptorForObject(classifier: ClassifierDescriptor?): FakeCallableDescriptorForObject? =
|
||||
when (classifier) {
|
||||
is TypeAliasDescriptor ->
|
||||
getFakeDescriptorForObject(classifier.classDescriptor)
|
||||
is ClassDescriptor ->
|
||||
if (classifier.hasClassValueDescriptor)
|
||||
FakeCallableDescriptorForObject(classifier)
|
||||
else
|
||||
null
|
||||
else -> null
|
||||
}
|
||||
|
||||
private fun getClassWithConstructors(classifier: ClassifierDescriptor?): ClassDescriptor? =
|
||||
if (classifier !is ClassDescriptor || !classifier.canHaveCallableConstructors())
|
||||
if (classifier !is ClassDescriptor || !classifier.canHaveCallableConstructors)
|
||||
null
|
||||
else
|
||||
classifier
|
||||
|
||||
private fun ClassDescriptor.canHaveCallableConstructors() =
|
||||
!ErrorUtils.isError(this) && !kind.isSingleton
|
||||
private val ClassDescriptor.canHaveCallableConstructors: Boolean
|
||||
get() = !ErrorUtils.isError(this) && !kind.isSingleton
|
||||
|
||||
private fun ClassifierDescriptor.getTypeAliasConstructors(inner: Boolean): Collection<ConstructorDescriptor> {
|
||||
if (this !is TypeAliasDescriptor) return emptyList()
|
||||
|
||||
val classDescriptor = this.classDescriptor ?: return emptyList()
|
||||
if (!classDescriptor.canHaveCallableConstructors()) return emptyList()
|
||||
if (!classDescriptor.canHaveCallableConstructors) return emptyList()
|
||||
|
||||
val substitutor = this.getTypeSubstitutorForUnderlyingClass() ?: throw AssertionError("classDescriptor should be non-null for $this")
|
||||
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
class C<T1, T2> {
|
||||
companion object {
|
||||
val OK = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
typealias C2<T> = C<T, T>
|
||||
|
||||
val test1: String = <!FUNCTION_CALL_EXPECTED!>C2<String><!>.<!UNRESOLVED_REFERENCE!>OK<!>
|
||||
val test2: String = C2.OK
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package
|
||||
|
||||
public typealias C2</*0*/ T> = C<T, T>
|
||||
public val test1: kotlin.String
|
||||
public val test2: kotlin.String = "OK"
|
||||
|
||||
public final class C</*0*/ T1, /*1*/ T2> {
|
||||
public constructor C</*0*/ T1, /*1*/ T2>()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
public companion object Companion {
|
||||
private constructor Companion()
|
||||
public final val OK: kotlin.String = "OK"
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
+7
-1
@@ -2,4 +2,10 @@ class Pair<T1, T2>(val x1: T1, val x2: T2)
|
||||
|
||||
typealias P2<T> = Pair<T, T>
|
||||
|
||||
val test1 = P2<String>("", "")
|
||||
val test1: Pair<String, String> = P2<String>("", "")
|
||||
val test1x1: String = test1.x1
|
||||
val test1x2: String = test1.x2
|
||||
|
||||
val test2: P2<String> = P2<String>("", "")
|
||||
val test2x1: String = test2.x1
|
||||
val test2x2: String = test2.x2
|
||||
|
||||
+5
@@ -2,6 +2,11 @@ package
|
||||
|
||||
public typealias P2</*0*/ T> = Pair<T, T>
|
||||
public val test1: Pair<kotlin.String, kotlin.String>
|
||||
public val test1x1: kotlin.String
|
||||
public val test1x2: kotlin.String
|
||||
public val test2: P2<kotlin.String> [= Pair<kotlin.String, kotlin.String>]
|
||||
public val test2x1: kotlin.String
|
||||
public val test2x2: kotlin.String
|
||||
|
||||
public final class Pair</*0*/ T1, /*1*/ T2> {
|
||||
public constructor Pair</*0*/ T1, /*1*/ T2>(/*0*/ x1: T1, /*1*/ x2: T2)
|
||||
|
||||
@@ -19179,6 +19179,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("typeAliasArgumentsInCompanionObject.kt")
|
||||
public void testTypeAliasArgumentsInCompanionObject() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/typeAliasArgumentsInCompanionObject.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("typeAliasArgumentsInConstructor.kt")
|
||||
public void testTypeAliasArgumentsInConstructor() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/typeAliasArgumentsInConstructor.kt");
|
||||
|
||||
Reference in New Issue
Block a user