Skip to content

Commit 718e8eb

Browse files
committed
Inner type aliases.
Type alias is considered "inner" if it captures outer class type parameters (implicitly or explicitly).
1 parent 63fed20 commit 718e8eb

File tree

16 files changed

+244
-27
lines changed

16 files changed

+244
-27
lines changed

compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -710,18 +710,25 @@ else if (!languageVersionSettings.supportsFeature(LanguageFeature.TypeAliases))
710710
else {
711711
typeAliasDescriptor.initialize(
712712
typeParameterDescriptors,
713-
storageManager.createLazyValue(new Function0<SimpleType>() {
714-
@Override
715-
public SimpleType invoke() {
716-
return typeResolver.resolveAbbreviatedType(scopeWithTypeParameters, typeReference, trace);
717-
}
718-
}),
719-
storageManager.createLazyValue(new Function0<SimpleType>() {
720-
@Override
721-
public SimpleType invoke() {
722-
return typeResolver.resolveExpandedTypeForTypeAlias(typeAliasDescriptor);
723-
}
724-
}));
713+
storageManager.createRecursionTolerantLazyValue(
714+
new Function0<SimpleType>() {
715+
@Override
716+
public SimpleType invoke() {
717+
return typeResolver.resolveAbbreviatedType(scopeWithTypeParameters, typeReference, trace);
718+
}
719+
},
720+
ErrorUtils.createErrorType("Recursive type alias expansion for " + typeAliasDescriptor.getName().asString())
721+
),
722+
storageManager.createRecursionTolerantLazyValue(
723+
new Function0<SimpleType>() {
724+
@Override
725+
public SimpleType invoke() {
726+
return typeResolver.resolveExpandedTypeForTypeAlias(typeAliasDescriptor);
727+
}
728+
},
729+
ErrorUtils.createErrorType("Recursive type alias expansion for " + typeAliasDescriptor.getName().asString())
730+
)
731+
);
725732
}
726733

727734
trace.record(TYPE_ALIAS, typeAlias, typeAliasDescriptor);

compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeAliasExpansion.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class TypeAliasExpansion private constructor(
4848
typeAliasDescriptor: TypeAliasDescriptor,
4949
arguments: List<TypeProjection>
5050
): TypeAliasExpansion {
51-
val typeParameters = typeAliasDescriptor.typeConstructor.parameters.map { it.original as TypeParameterDescriptor }
51+
val typeParameters = typeAliasDescriptor.typeConstructor.parameters.map { it.original }
5252
val mappedArguments = typeParameters.zip(arguments).toMap()
5353
return TypeAliasExpansion(parent, typeAliasDescriptor, arguments, mappedArguments)
5454
}

compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyTypeAliasDescriptor.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.descriptors.impl.AbstractTypeAliasDescriptor
2222
import org.jetbrains.kotlin.name.Name
2323
import org.jetbrains.kotlin.resolve.BindingTrace
2424
import org.jetbrains.kotlin.storage.NotNullLazyValue
25+
import org.jetbrains.kotlin.storage.NullableLazyValue
2526
import org.jetbrains.kotlin.storage.StorageManager
2627
import org.jetbrains.kotlin.types.SimpleType
2728
import org.jetbrains.kotlin.types.TypeSubstitutor
@@ -42,9 +43,11 @@ class LazyTypeAliasDescriptor(
4243
private lateinit var underlyingTypeImpl: NotNullLazyValue<SimpleType>
4344
private lateinit var expandedTypeImpl: NotNullLazyValue<SimpleType>
4445
private lateinit var defaultTypeImpl: NotNullLazyValue<SimpleType>
46+
private lateinit var classDescriptorImpl: NullableLazyValue<ClassDescriptor>
4547

4648
override val underlyingType: SimpleType get() = underlyingTypeImpl()
4749
override val expandedType: SimpleType get() = expandedTypeImpl()
50+
override val classDescriptor: ClassDescriptor? get() = classDescriptorImpl()
4851
override fun getDefaultType(): SimpleType = defaultTypeImpl()
4952

5053
fun initialize(
@@ -56,10 +59,21 @@ class LazyTypeAliasDescriptor(
5659
this.underlyingTypeImpl = lazyUnderlyingType
5760
this.expandedTypeImpl = lazyExpandedType
5861
this.defaultTypeImpl = storageManager.createLazyValue { computeDefaultType() }
62+
this.classDescriptorImpl = storageManager.createRecursionTolerantNullableLazyValue({ computeClassDescriptor() }, null)
63+
}
64+
65+
private fun computeClassDescriptor(): ClassDescriptor? {
66+
if (underlyingType.isError) return null
67+
val underlyingTypeDescriptor = underlyingType.constructor.declarationDescriptor
68+
return when (underlyingTypeDescriptor) {
69+
is ClassDescriptor -> underlyingTypeDescriptor
70+
is TypeAliasDescriptor -> underlyingTypeDescriptor.classDescriptor
71+
else -> null
72+
}
5973
}
6074

6175
private val lazyTypeConstructorParameters =
62-
storageManager.createLazyValue { this.computeConstructorTypeParameters() }
76+
storageManager.createRecursionTolerantLazyValue({ this.computeConstructorTypeParameters() }, emptyList())
6377

6478
fun initialize(
6579
declaredTypeParameters: List<TypeParameterDescriptor>,

compiler/testData/diagnostics/tests/typealias/capturingTypeParametersFromOuterClass.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ public final class Outer</*0*/ TO> {
2121
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
2222
public typealias LTI /*captured type parameters: /*0*/ TI, /*1*/ TN*/ = kotlin.collections.List<TI>
2323
public typealias LTN /*captured type parameters: /*0*/ TI, /*1*/ TN*/ = kotlin.collections.List<TN>
24-
public typealias LTO /*captured type parameters: /*0*/ TI, /*1*/ TN*/ = kotlin.collections.List<[ERROR : TO]>
24+
public typealias LTO = kotlin.collections.List<[ERROR : TO]>
2525
}
2626
public typealias LTN /*captured type parameters: /*0*/ TN*/ = kotlin.collections.List<TN>
27-
public typealias LTO /*captured type parameters: /*0*/ TN*/ = kotlin.collections.List<[ERROR : TO]>
27+
public typealias LTO = kotlin.collections.List<[ERROR : TO]>
2828
}
2929
public typealias LTO /*captured type parameters: /*0*/ TO*/ = kotlin.collections.List<TO>
3030
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class Outer<T> {
2+
class Nested
3+
class GenericNested<TT>
4+
inner class Inner
5+
inner class GenericInner<TT>
6+
7+
typealias NestedAlias = Nested
8+
typealias GenericNestedAlias<TT> = GenericNested<TT>
9+
typealias InnerAlias = Inner
10+
typealias GenericInnerAlias<TT> = GenericInner<TT>
11+
12+
fun test1(x: NestedAlias) = x
13+
fun test2(x: GenericNestedAlias<Int>) = x
14+
fun <T> test3(x: GenericNestedAlias<T>) = x
15+
fun test4(x: InnerAlias) = x
16+
fun test5(x: GenericInnerAlias<Int>) = x
17+
fun <T> test6(x: GenericInnerAlias<T>) = x
18+
}
19+
fun test1(x: Outer<!TYPE_ARGUMENTS_FOR_OUTER_CLASS_WHEN_NESTED_REFERENCED!><Int><!>.NestedAlias) = <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>x<!>
20+
fun <T> test2(x: Outer<!TYPE_ARGUMENTS_FOR_OUTER_CLASS_WHEN_NESTED_REFERENCED!><T><!>.NestedAlias) = <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>x<!>
21+
fun test3(x: Outer.NestedAlias) = x
22+
fun test4(x: Outer<!TYPE_ARGUMENTS_FOR_OUTER_CLASS_WHEN_NESTED_REFERENCED!><Int><!>.GenericNestedAlias<Int>) = <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>x<!>
23+
fun <T> test5(x: Outer<!TYPE_ARGUMENTS_FOR_OUTER_CLASS_WHEN_NESTED_REFERENCED!><T><!>.GenericNestedAlias<Int>) = <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>x<!>
24+
fun <T> test6(x: Outer<!TYPE_ARGUMENTS_FOR_OUTER_CLASS_WHEN_NESTED_REFERENCED!><Int><!>.GenericNestedAlias<T>) = <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>x<!>
25+
fun test7(x: Outer.GenericNestedAlias<Int>) = x
26+
fun <T> test8(x: Outer.GenericNestedAlias<T>) = x
27+
fun test9(x: <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Outer<!>.InnerAlias) = <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>x<!>
28+
fun test10(x: Outer<Int>.InnerAlias) = x
29+
fun <T> test11(x: Outer<T>.InnerAlias) = x
30+
fun test12(x: <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Outer<!>.GenericInnerAlias<Int>) = <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>x<!>
31+
fun test13(x: Outer<Int>.GenericInnerAlias<Int>) = x
32+
fun <T> test14(x: Outer<T>.GenericInnerAlias<Int>) = x
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package
2+
3+
public fun test1(/*0*/ x: [ERROR : NestedAlias]<kotlin.Int>): [ERROR : NestedAlias]<kotlin.Int>
4+
public fun test10(/*0*/ x: Outer<kotlin.Int>.InnerAlias /* = Outer<kotlin.Int>.Inner */): Outer<kotlin.Int>.InnerAlias /* = Outer<kotlin.Int>.Inner */
5+
public fun </*0*/ T> test11(/*0*/ x: Outer<T>.InnerAlias /* = Outer<T>.Inner */): Outer<T>.InnerAlias /* = Outer<T>.Inner */
6+
public fun test12(/*0*/ x: [ERROR : GenericInnerAlias]<kotlin.Int>): [ERROR : GenericInnerAlias]<kotlin.Int>
7+
public fun test13(/*0*/ x: Outer<kotlin.Int>.GenericInnerAlias<kotlin.Int> /* = Outer<kotlin.Int>.GenericInner<kotlin.Int> */): Outer<kotlin.Int>.GenericInnerAlias<kotlin.Int> /* = Outer<kotlin.Int>.GenericInner<kotlin.Int> */
8+
public fun </*0*/ T> test14(/*0*/ x: Outer<T>.GenericInnerAlias<kotlin.Int> /* = Outer<T>.GenericInner<kotlin.Int> */): Outer<T>.GenericInnerAlias<kotlin.Int> /* = Outer<T>.GenericInner<kotlin.Int> */
9+
public fun </*0*/ T> test2(/*0*/ x: [ERROR : NestedAlias]<T>): [ERROR : NestedAlias]<T>
10+
public fun test3(/*0*/ x: Outer.NestedAlias /* = Outer.Nested */): Outer.NestedAlias /* = Outer.Nested */
11+
public fun test4(/*0*/ x: [ERROR : GenericNestedAlias]<kotlin.Int, kotlin.Int>): [ERROR : GenericNestedAlias]<kotlin.Int, kotlin.Int>
12+
public fun </*0*/ T> test5(/*0*/ x: [ERROR : GenericNestedAlias]<T, kotlin.Int>): [ERROR : GenericNestedAlias]<T, kotlin.Int>
13+
public fun </*0*/ T> test6(/*0*/ x: [ERROR : GenericNestedAlias]<kotlin.Int, T>): [ERROR : GenericNestedAlias]<kotlin.Int, T>
14+
public fun test7(/*0*/ x: Outer.GenericNestedAlias<kotlin.Int> /* = Outer.GenericNested<kotlin.Int> */): Outer.GenericNestedAlias<kotlin.Int> /* = Outer.GenericNested<kotlin.Int> */
15+
public fun </*0*/ T> test8(/*0*/ x: Outer.GenericNestedAlias<T> /* = Outer.GenericNested<T> */): Outer.GenericNestedAlias<T> /* = Outer.GenericNested<T> */
16+
public fun test9(/*0*/ x: [ERROR : InnerAlias]): [ERROR : InnerAlias]
17+
18+
public final class Outer</*0*/ T> {
19+
public constructor Outer</*0*/ T>()
20+
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
21+
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
22+
public final fun test1(/*0*/ x: Outer.NestedAlias /* = Outer.Nested */): Outer.NestedAlias /* = Outer.Nested */
23+
public final fun test2(/*0*/ x: Outer.GenericNestedAlias<kotlin.Int> /* = Outer.GenericNested<kotlin.Int> */): Outer.GenericNestedAlias<kotlin.Int> /* = Outer.GenericNested<kotlin.Int> */
24+
public final fun </*0*/ T> test3(/*0*/ x: Outer.GenericNestedAlias<T> /* = Outer.GenericNested<T> */): Outer.GenericNestedAlias<T> /* = Outer.GenericNested<T> */
25+
public final fun test4(/*0*/ x: Outer<T>.InnerAlias /* = Outer<T>.Inner */): Outer<T>.InnerAlias /* = Outer<T>.Inner */
26+
public final fun test5(/*0*/ x: Outer<T>.GenericInnerAlias<kotlin.Int> /* = Outer<T>.GenericInner<kotlin.Int> */): Outer<T>.GenericInnerAlias<kotlin.Int> /* = Outer<T>.GenericInner<kotlin.Int> */
27+
public final fun </*0*/ T> test6(/*0*/ x: Outer<T>.GenericInnerAlias<T> /* = Outer<T>.GenericInner<T> */): Outer<T>.GenericInnerAlias<T> /* = Outer<T>.GenericInner<T> */
28+
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
29+
30+
public final inner class GenericInner</*0*/ TT> /*captured type parameters: /*1*/ T*/ {
31+
public constructor GenericInner</*0*/ TT>()
32+
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
33+
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
34+
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
35+
}
36+
37+
public final class GenericNested</*0*/ TT> {
38+
public constructor GenericNested</*0*/ TT>()
39+
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
40+
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
41+
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
42+
}
43+
44+
public final inner class Inner /*captured type parameters: /*0*/ T*/ {
45+
public constructor Inner()
46+
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
47+
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
48+
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
49+
}
50+
51+
public final class Nested {
52+
public constructor Nested()
53+
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
54+
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
55+
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
56+
}
57+
public typealias GenericInnerAlias</*0*/ TT> /*captured type parameters: /*1*/ T*/ = Outer<T>.GenericInner<TT>
58+
public typealias GenericNestedAlias</*0*/ TT> = Outer.GenericNested<TT>
59+
public typealias InnerAlias /*captured type parameters: /*0*/ T*/ = Outer<T>.Inner
60+
public typealias NestedAlias = Outer.Nested
61+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class C<T> {
2+
inner class D
3+
4+
typealias DA = D
5+
typealias SDA = C<Int>.D
6+
typealias TSDA = C<T>.D
7+
typealias TC = C<T>
8+
typealias SSDA = C<*>.D
9+
typealias SSC = C<*>
10+
}
11+
12+
fun test1(x: C<Int>.DA) = x
13+
fun test2(x: C.SDA) = x
14+
fun test3(x: C<Int>.TSDA) = x
15+
fun test4(x: C<Int>.TC) = x
16+
17+
fun test5(x: C<*>.DA) = x
18+
fun test6(x: C<*>.TSDA) = x
19+
fun test7(x: C<*>.TC) = x
20+
21+
fun test8(x: C.SSDA) = x
22+
fun test9(x: C.SSC) = x
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package
2+
3+
public fun test1(/*0*/ x: C<kotlin.Int>.DA /* = C<kotlin.Int>.D */): C<kotlin.Int>.DA /* = C<kotlin.Int>.D */
4+
public fun test2(/*0*/ x: C.SDA /* = C<kotlin.Int>.D */): C.SDA /* = C<kotlin.Int>.D */
5+
public fun test3(/*0*/ x: C<kotlin.Int>.TSDA /* = C<kotlin.Int>.D */): C<kotlin.Int>.TSDA /* = C<kotlin.Int>.D */
6+
public fun test4(/*0*/ x: C<kotlin.Int>.TC /* = C<kotlin.Int> */): C<kotlin.Int>.TC /* = C<kotlin.Int> */
7+
public fun test5(/*0*/ x: C<*>.DA /* = C<*>.D */): C<*>.DA /* = C<*>.D */
8+
public fun test6(/*0*/ x: C<*>.TSDA /* = C<*>.D */): C<*>.TSDA /* = C<*>.D */
9+
public fun test7(/*0*/ x: C<*>.TC /* = C<*> */): C<*>.TC /* = C<*> */
10+
public fun test8(/*0*/ x: C.SSDA /* = C<*>.D */): C.SSDA /* = C<*>.D */
11+
public fun test9(/*0*/ x: C.SSC /* = C<*> */): C.SSC /* = C<*> */
12+
13+
public final class C</*0*/ T> {
14+
public constructor C</*0*/ T>()
15+
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
16+
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
17+
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
18+
19+
public final inner class D /*captured type parameters: /*0*/ T*/ {
20+
public constructor D()
21+
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
22+
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
23+
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
24+
}
25+
public typealias DA /*captured type parameters: /*0*/ T*/ = C<T>.D
26+
public typealias SDA = C<kotlin.Int>.D
27+
public typealias SSC = C<*>
28+
public typealias SSDA = C<*>.D
29+
public typealias TC /*captured type parameters: /*0*/ T*/ = C<T>
30+
public typealias TSDA /*captured type parameters: /*0*/ T*/ = C<T>.D
31+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class OuterClass<T1> {
2+
class NestedClass<T2>
3+
typealias NestedType<T> = NestedClass<T>
4+
}
5+
6+
typealias ON1<T1, T2> = OuterClass<!TYPE_ARGUMENTS_FOR_OUTER_CLASS_WHEN_NESTED_REFERENCED!><T1><!>.NestedClass<T2>
7+
typealias ON2<T1, T2> = OuterClass<!TYPE_ARGUMENTS_FOR_OUTER_CLASS_WHEN_NESTED_REFERENCED!><T1><!>.NestedType<T2>
8+
typealias ON3<T2> = OuterClass.NestedType<T2>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package
2+
3+
public final class OuterClass</*0*/ T1> {
4+
public constructor OuterClass</*0*/ T1>()
5+
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
6+
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
7+
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
8+
9+
public final class NestedClass</*0*/ T2> {
10+
public constructor NestedClass</*0*/ T2>()
11+
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
12+
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
13+
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
14+
}
15+
public typealias NestedType</*0*/ T> = OuterClass.NestedClass<T>
16+
}
17+
public typealias ON1</*0*/ T1, /*1*/ T2> = [ERROR : NestedClass]<T1, T2>
18+
public typealias ON2</*0*/ T1, /*1*/ T2> = [ERROR : NestedType]<T1, T2>
19+
public typealias ON3</*0*/ T2> = OuterClass.NestedType<T2>

compiler/testData/diagnostics/tests/typealias/typeAliasAsSuperQualifier.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public final class TestSuperForGenericBase</*0*/ T> : GB<T> /* = GenericBase<T>
3232
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
3333
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
3434
public typealias MyBase /*captured type parameters: /*0*/ T*/ = GB<T>
35-
public typealias MyBaseInt /*captured type parameters: /*0*/ T*/ = GB<kotlin.Int>
35+
public typealias MyBaseInt = GB<kotlin.Int>
3636
}
3737

3838
public final class Unrelated {

compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20926,6 +20926,18 @@ public void testInhreritedTypeAliasQualifiedByDerivedClass() throws Exception {
2092620926
doTest(fileName);
2092720927
}
2092820928

20929+
@TestMetadata("innerTypeAliasAsType.kt")
20930+
public void testInnerTypeAliasAsType() throws Exception {
20931+
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/innerTypeAliasAsType.kt");
20932+
doTest(fileName);
20933+
}
20934+
20935+
@TestMetadata("innerTypeAliasAsType2.kt")
20936+
public void testInnerTypeAliasAsType2() throws Exception {
20937+
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/innerTypeAliasAsType2.kt");
20938+
doTest(fileName);
20939+
}
20940+
2092920941
@TestMetadata("isAsWithTypeAlias.kt")
2093020942
public void testIsAsWithTypeAlias() throws Exception {
2093120943
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/isAsWithTypeAlias.kt");
@@ -20950,6 +20962,12 @@ public void testKt14498a() throws Exception {
2095020962
doTest(fileName);
2095120963
}
2095220964

20965+
@TestMetadata("kt14518.kt")
20966+
public void testKt14518() throws Exception {
20967+
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/kt14518.kt");
20968+
doTest(fileName);
20969+
}
20970+
2095320971
@TestMetadata("kt14641.kt")
2095420972
public void testKt14641() throws Exception {
2095520973
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/kt14641.kt");

core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/AbstractTypeAliasDescriptor.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,20 @@ abstract class AbstractTypeAliasDescriptor(
4747
visitor.visitTypeAliasDescriptor(this, data)
4848

4949
override fun isInner(): Boolean =
50-
containingDeclaration !is PackageFragmentDescriptor
50+
// NB: it's ok to use underlyingType here, since referenced inner type aliases also capture type parameters.
51+
// Using expandedType looks "proper", but in fact will cause a recursion in expandedType resolution,
52+
// which will silently produce wrong result.
53+
TypeUtils.contains(underlyingType) {
54+
!it.isError && run {
55+
val constructorDescriptor = it.constructor.declarationDescriptor
56+
constructorDescriptor is TypeParameterDescriptor &&
57+
constructorDescriptor.containingDeclaration != this@AbstractTypeAliasDescriptor
58+
}
59+
}
5160

5261
override fun getDeclaredTypeParameters(): List<TypeParameterDescriptor> =
5362
declaredTypeParametersImpl
5463

55-
override val classDescriptor: ClassDescriptor?
56-
get() = if (expandedType.isError) null else expandedType.constructor.declarationDescriptor as? ClassDescriptor
57-
5864
override fun getModality() = Modality.FINAL
5965

6066
override fun getVisibility() = visibilityImpl

0 commit comments

Comments
 (0)