Skip to content

Commit 203648d

Browse files
committed
added test for nested generic type
1 parent 63921a5 commit 203648d

File tree

4 files changed

+12
-2
lines changed
  • core
    • generated-sources/src
      • main/kotlin/org/jetbrains/kotlinx/dataframe/impl
      • test/kotlin/org/jetbrains/kotlinx/dataframe/types
    • src
      • main/kotlin/org/jetbrains/kotlinx/dataframe/impl
      • test/kotlin/org/jetbrains/kotlinx/dataframe/types

4 files changed

+12
-2
lines changed

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/TypeUtils.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ internal fun KType.replaceGenericTypeParametersWithUpperbound(): KType {
7474
(oldType.classifier as KTypeParameter).upperBounds.firstOrNull() ?: typeOf<Any?>()
7575

7676
// Type<in T> cannot be replaced with Type<Any?>, instead it should be replaced with Type<Nothing>
77+
// TODO: issue #471
7778
IN -> nothingType(false)
7879
}
7980
}

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/types/UtilTests.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,18 @@ class UtilTests {
168168
interface TypeWithUpperbound1<T : UpperBound>
169169
interface TestType1<T : UpperBound> : TypeWithUpperbound1<T>
170170
interface TestTypeIn1<in T> : Comparable<T>
171+
interface TestType2<S: UpperBound> : TestTypeIn1<TestType1<S>>
171172

172173
@Test
173-
fun eraseGenericTypeParameters() {
174+
fun replaceGenericTypeParametersWithUpperbound() {
174175
val typeWithUpperboundT = TestType1::class.supertypes.first() // TypeWithUpperbound<T>
175176
typeWithUpperboundT.replaceGenericTypeParametersWithUpperbound() shouldBe typeOf<TypeWithUpperbound1<UpperBound>>()
176177

177178
val comparableTypeT = TestTypeIn1::class.supertypes.first() // Comparable<T>
178179
comparableTypeT.replaceGenericTypeParametersWithUpperbound() shouldBe typeOf<Comparable<Nothing>>()
180+
181+
val nestedTypeWithUpperboundT = TestType2::class.supertypes.first() // TestTypeIn1<TestType1<S>>
182+
nestedTypeWithUpperboundT.replaceGenericTypeParametersWithUpperbound() shouldBe typeOf<TestTypeIn1<TestType1<UpperBound>>>()
179183
}
180184

181185
interface AbstractType<T>

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/TypeUtils.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ internal fun KType.replaceGenericTypeParametersWithUpperbound(): KType {
7474
(oldType.classifier as KTypeParameter).upperBounds.firstOrNull() ?: typeOf<Any?>()
7575

7676
// Type<in T> cannot be replaced with Type<Any?>, instead it should be replaced with Type<Nothing>
77+
// TODO: issue #471
7778
IN -> nothingType(false)
7879
}
7980
}

core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/types/UtilTests.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,18 @@ class UtilTests {
168168
interface TypeWithUpperbound1<T : UpperBound>
169169
interface TestType1<T : UpperBound> : TypeWithUpperbound1<T>
170170
interface TestTypeIn1<in T> : Comparable<T>
171+
interface TestType2<S: UpperBound> : TestTypeIn1<TestType1<S>>
171172

172173
@Test
173-
fun eraseGenericTypeParameters() {
174+
fun replaceGenericTypeParametersWithUpperbound() {
174175
val typeWithUpperboundT = TestType1::class.supertypes.first() // TypeWithUpperbound<T>
175176
typeWithUpperboundT.replaceGenericTypeParametersWithUpperbound() shouldBe typeOf<TypeWithUpperbound1<UpperBound>>()
176177

177178
val comparableTypeT = TestTypeIn1::class.supertypes.first() // Comparable<T>
178179
comparableTypeT.replaceGenericTypeParametersWithUpperbound() shouldBe typeOf<Comparable<Nothing>>()
180+
181+
val nestedTypeWithUpperboundT = TestType2::class.supertypes.first() // TestTypeIn1<TestType1<S>>
182+
nestedTypeWithUpperboundT.replaceGenericTypeParametersWithUpperbound() shouldBe typeOf<TestTypeIn1<TestType1<UpperBound>>>()
179183
}
180184

181185
interface AbstractType<T>

0 commit comments

Comments
 (0)