Skip to content

Commit 46de1a6

Browse files
committed
K2: Handle DNN types properly during type aliases expansion
^KT-68383 Fixed ^KT-68497 Related
1 parent f061665 commit 46de1a6

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/TypeExpansionUtils.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,19 @@ private fun mapTypeAliasArguments(
136136

137137
override fun substituteArgument(projection: ConeTypeProjection, index: Int): ConeTypeProjection? {
138138
val type = (projection as? ConeKotlinTypeProjection)?.type ?: return null
139-
val symbol = (type as? ConeTypeParameterType)?.lookupTag?.symbol ?: return super.substituteArgument(
140-
projection,
141-
index
142-
)
139+
// TODO: Consider making code more generic and "ready" to any kind of types (KT-68497)
140+
val symbol =
141+
(type.unwrapFlexibleAndDefinitelyNotNull() as? ConeTypeParameterType)?.lookupTag?.symbol
142+
?: return super.substituteArgument(projection, index)
143143
val mappedProjection = typeAliasMap[symbol] ?: return super.substituteArgument(projection, index)
144144
var mappedType = (mappedProjection as? ConeKotlinTypeProjection)?.type.updateNullabilityIfNeeded(type)
145145
mappedType = when (mappedType) {
146146
is ConeErrorType,
147147
is ConeClassLikeTypeImpl,
148148
is ConeDefinitelyNotNullType,
149149
is ConeTypeParameterTypeImpl,
150-
is ConeFlexibleType -> {
150+
is ConeFlexibleType,
151+
-> {
151152
mappedType.withAttributes(type.attributes.add(mappedType.attributes))
152153
}
153154
null -> return mappedProjection

compiler/testData/diagnostics/tests/typealias/expansionDnnTypeArgument.fir.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ interface Inv2<K, V> {
66
typealias Inv1<T> = Inv2<String, T & Any>
77

88
fun test1(inv: Inv1<String>) {
9-
expectMap(<!ARGUMENT_TYPE_MISMATCH!>inv<!>)
9+
expectMap(inv)
1010
val x = inv.get("")
11-
x.<!UNRESOLVED_REFERENCE!>length<!>
11+
x.length
1212
}
1313

1414
fun test2(map: Inv1<String?>) {
1515
// Well, this K1 behavior doesn't look really correct, but we're not going to change it anymore
16-
expectMap(<!ARGUMENT_TYPE_MISMATCH!>map<!>)
16+
expectMap(map)
1717
val x = map.get("")
18-
x.<!UNRESOLVED_REFERENCE!>length<!>
18+
x.length
1919
}
2020

2121
fun expectMap(x: Inv2<String, String>) {}

0 commit comments

Comments
 (0)