Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Support "-no-reflect" in "kotlin" command
 #KT-13491 Fixed
  • Loading branch information
udalov committed Aug 26, 2016
1 parent 902232c commit 3298649
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
13 changes: 10 additions & 3 deletions compiler/cli/cli-runner/src/org/jetbrains/kotlin/runner/Main.kt
Expand Up @@ -37,6 +37,7 @@ object Main {
var runner: Runner? = null
var collectingArguments = false
val arguments = arrayListOf<String>()
var noReflect = false

classpath.add(".")

Expand Down Expand Up @@ -69,6 +70,9 @@ object Main {
runner = ExpressionRunner(next())
collectingArguments = true
}
else if ("-no-reflect" == arg) {
noReflect = true
}
else if (arg.startsWith("-")) {
throw RunnerException("unsupported argument: $arg")
}
Expand All @@ -89,8 +93,9 @@ object Main {

classpath.add(KOTLIN_HOME.toString() + "/lib/kotlin-runtime.jar")

// TODO: provide a way to disable including kotlin-reflect.jar to the classpath
classpath.add(KOTLIN_HOME.toString() + "/lib/kotlin-reflect.jar")
if (!noReflect) {
classpath.add(KOTLIN_HOME.toString() + "/lib/kotlin-reflect.jar")
}

if (runner == null) {
runner = ReplRunner()
Expand All @@ -99,7 +104,8 @@ object Main {
runner.run(classpath, arguments)
}

@JvmStatic fun main(args: Array<String>) {
@JvmStatic
fun main(args: Array<String>) {
try {
run(args)
}
Expand All @@ -124,6 +130,7 @@ where command may be one of:
-classpath (-cp) <path> Paths where to find user class files
-Dname=value Set a system JVM property
-J<option> Pass an option directly to JVM
-no-reflect Don't include Kotlin reflection implementation into classpath
-version Display Kotlin version
-help (-h) Print a synopsis of options
""")
Expand Down
11 changes: 11 additions & 0 deletions compiler/testData/launcher/reflectionUsage.kt
@@ -0,0 +1,11 @@
class Foo(val bar: String?)

fun main(args: Array<String>) {
try {
if (Foo::bar.returnType.isMarkedNullable) {
print("Foo#bar is nullable")
}
} catch (e: KotlinReflectionNotSupportedError) {
print("no reflection")
}
}
18 changes: 17 additions & 1 deletion compiler/tests/org/jetbrains/kotlin/cli/LauncherScriptTest.kt
Expand Up @@ -47,7 +47,7 @@ class LauncherScriptTest : TestCaseWithTmpdir() {
assertEquals(expectedStderr, stderr)
assertEquals(expectedExitCode.code, exitCode)
}
catch (e: Exception) {
catch (e: Throwable) {
System.err.println("exit code $exitCode")
System.err.println("<stdout>$stdout</stdout>")
System.err.println("<stderr>$stderr</stderr>")
Expand Down Expand Up @@ -82,4 +82,20 @@ class LauncherScriptTest : TestCaseWithTmpdir() {
"-output", File(tmpdir, "out.js").path
)
}

fun testKotlinNoReflect() {
runProcess(
"kotlinc",
"$testDataDirectory/reflectionUsage.kt",
"-d", tmpdir.path
)

runProcess(
"kotlin",
"-cp", tmpdir.path,
"-no-reflect",
"ReflectionUsageKt",
expectedStdout = "no reflection"
)
}
}

0 comments on commit 3298649

Please sign in to comment.