mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-03-10 08:31:29 +00:00
Change nestedClasses logic to accept classes with nested type aliases
#KT-47650 fixed
This commit is contained in:
@@ -36,6 +36,8 @@ dependencies {
|
||||
|
||||
testImplementation(intellijCoreDep()) { includeJars("intellij-core") }
|
||||
testRuntimeOnly(intellijDep()) { includeJars("jps-model", "jna") }
|
||||
|
||||
testImplementation(project(":kotlin-reflect"))
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
package org.jetbrains.kotlin.scripting.compiler.test
|
||||
|
||||
import junit.framework.TestCase
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.jetbrains.kotlin.scripting.compiler.plugin.impl.ScriptJvmCompilerIsolated
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.script.experimental.api.*
|
||||
import kotlin.script.experimental.host.toScriptSource
|
||||
import kotlin.script.experimental.jvm.defaultJvmScriptingHostConfiguration
|
||||
@@ -27,6 +29,23 @@ class ScriptCompilerTest : TestCase() {
|
||||
assertTrue(res.reports.none { it.message.contains("nonsense") })
|
||||
}
|
||||
|
||||
fun testTypeAliases() {
|
||||
val res = compileToClass(
|
||||
"""
|
||||
class Clazz
|
||||
typealias Tazz = List<Clazz>
|
||||
val x: Tazz = listOf()
|
||||
x
|
||||
""".trimIndent().toScriptSource()
|
||||
)
|
||||
|
||||
val kclass = res.valueOrThrow()
|
||||
val nestedClasses = kclass.nestedClasses.toList()
|
||||
|
||||
assertEquals(1, nestedClasses.size)
|
||||
assertEquals("Clazz", nestedClasses[0].simpleName)
|
||||
}
|
||||
|
||||
fun compile(
|
||||
script: SourceCode,
|
||||
cfgBody: ScriptCompilationConfiguration.Builder.() -> Unit
|
||||
@@ -35,4 +54,14 @@ class ScriptCompilerTest : TestCase() {
|
||||
val compiler = ScriptJvmCompilerIsolated(defaultJvmScriptingHostConfiguration)
|
||||
return compiler.compile(script, compilationConfiguration)
|
||||
}
|
||||
|
||||
fun compileToClass(
|
||||
script: SourceCode,
|
||||
evaluationConfiguration: ScriptEvaluationConfiguration = ScriptEvaluationConfiguration(),
|
||||
cfgBody: ScriptCompilationConfiguration.Builder.() -> Unit = {},
|
||||
): ResultWithDiagnostics<KClass<*>> {
|
||||
val result = compile(script, cfgBody)
|
||||
if (result is ResultWithDiagnostics.Failure) return result
|
||||
return runBlocking { result.valueOrThrow().getClass(evaluationConfiguration) }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user