-
Notifications
You must be signed in to change notification settings - Fork 415
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[K2] Fix typealiased type that leads to functional type (#3396)
* [K2] Fix typealiased type to function * Add check on emptiness
- Loading branch information
Showing
3 changed files
with
80 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
dokka-subprojects/plugin-base/src/test/kotlin/model/TypesTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package model | ||
|
||
import org.jetbrains.dokka.base.signatures.KotlinSignatureUtils.driOrNull | ||
import org.jetbrains.dokka.links.DRI | ||
import org.jetbrains.dokka.model.* | ||
import utils.AbstractModelTest | ||
import kotlin.test.Test | ||
import kotlin.test.assertTrue | ||
|
||
class TypesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "types") { | ||
|
||
@Test | ||
fun `type with typealias to functional type with parameter`() { | ||
inlineModelTest( | ||
""" | ||
|typealias HttpExceptionCallback<T> = String.(T) -> String | ||
|fun <T> exception(callback: HttpExceptionCallback<T>){}""" | ||
) { | ||
with((this / "types" / "HttpExceptionCallback").cast<DTypeAlias>()) { | ||
name equals "HttpExceptionCallback" | ||
assertTrue(type is GenericTypeConstructor) | ||
(type as GenericTypeConstructor).projections counts 1 | ||
underlyingType.values.first().driOrNull equals DRI("kotlin", "Function2") | ||
} | ||
with((this / "types" / "exception").cast<DFunction>()) { | ||
name equals "exception" | ||
val parameterType = parameters.first().type | ||
assertTrue(parameterType is TypeAliased) | ||
with(parameterType) { | ||
assertTrue(typeAlias is GenericTypeConstructor) | ||
(typeAlias as GenericTypeConstructor).projections counts 1 | ||
assertTrue(inner is FunctionalTypeConstructor) | ||
(inner as FunctionalTypeConstructor).dri equals DRI("kotlin", "Function2") | ||
(inner as FunctionalTypeConstructor).projections counts 3 | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun `type with typealias to functional type`() { | ||
inlineModelTest( | ||
""" | ||
|typealias CompletionHandler = (cause: Throwable?) -> Unit | ||
|fun exception(callback: CompletionHandler){}""" | ||
) { | ||
with((this / "types" / "CompletionHandler").cast<DTypeAlias>()) { | ||
assertTrue(type is GenericTypeConstructor) | ||
(type as GenericTypeConstructor).projections counts 0 | ||
name equals "CompletionHandler" | ||
underlyingType.values.first().driOrNull equals DRI("kotlin", "Function1") | ||
} | ||
with((this / "types" / "exception").cast<DFunction>()) { | ||
name equals "exception" | ||
val parameterType = parameters.first().type | ||
assertTrue(parameterType is TypeAliased) | ||
with(parameterType) { | ||
assertTrue(typeAlias is GenericTypeConstructor) | ||
assertTrue(inner is FunctionalTypeConstructor) | ||
(inner as FunctionalTypeConstructor).dri equals DRI("kotlin", "Function1") | ||
(inner as FunctionalTypeConstructor).projections counts 2 | ||
} | ||
} | ||
} | ||
} | ||
} |