Kotlin compiler argument not applied to scratch file

296 views Asked by At

I wanted to use kotlin.time.measureTime in a Kotlin scratch file but it doesn't work.

...
kotlinOptions {
    ...
    freeCompilerArgs = ["-Xopt-in=kotlin.time.ExperimentalTime"]
}

experimental-annotation

Of course in my scratch file I "use classpath of module" which defines the compiler argument. When I use measureTime in regular code it works fine, but in the scratch file doesn't.

2

There are 2 answers

1
Михаил Нафталь On

Try to use explicit declaration of experimental API usage inside scratch file:

@ExperimentalTime
val s = measureTime {
    
}
0
Eugene Shmakov On

@OptIn works for me (see alternative recommendation by IntelliJ IDEA).

@OptIn(ExperimentalTime::class)
val s = measureTime { sleep(10) }
println(s)