question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot OptIn to an experimental annotation class

See original GitHub issue

A minimal repro:

import kotlin.time.*

@ExperimentalTime
val res = runBlocking {
    val mark = TimeSource.Monotonic.markNow()
    delay(300)
    mark.elapsedNow()
}

println(res)

Image for clarification: image

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:16

github_iconTop GitHub Comments

2reactions
ileasilecommented, Jan 19, 2021

Does this compiles for you?

@file:DependsOn("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2")
import kotlin.time.*
import kotlinx.coroutines.*
            
@OptIn(ExperimentalTime::class)
val res = runBlocking {
    val mark = kotlin.time.TimeSource.Monotonic.markNow()
    delay(3)
    mark.elapsedNow()
}
res

It seems that actual problem for you here is this issue

1reaction
ileasilecommented, Aug 18, 2021

@frankgerhardt sorry for delay, I haven’t mentioned your message… For now it works like this.

  1. Restart kernel and execute:
@file:CompilerArgs("-Xopt-in=kotlin.RequiresOptIn")

Note that it should be the first executed cell in the notebook session.

  1. Then execute the code you have mentioned, but with a minor change:
@file:DependsOn("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2")
import kotlin.time.*
import kotlinx.coroutines.*
            
@OptIn(ExperimentalTime::class)
val res = runBlocking {
    val mark = kotlin.time.TimeSource.Monotonic.markNow()
    delay(3)
    mark.elapsedNow()
}
@OptIn(ExperimentalTime::class)
res
Read more comments on GitHub >

github_iconTop Results From Across the Web

Opt-in requirements | Kotlin
To opt in to using an API in a module, compile it with the argument -opt-in , specifying the fully qualified name of...
Read more >
All About Opt-In Annotations - zsmb.co
In most cases, the API marked with opt-in annotations is public, but the annotation being present deters clients from using it.
Read more >
Confusing warning message "This class can only be used with ...
If I @OptIn to experimental API with level = WARNING only then the annotation causes the following warning: [EXPERIMENTAL_IS_NOT_ENABLED] This class can ...
Read more >
Handling multiple experimental annotations throughout an app
It does not force the users of this method/class to add annotation in their code. Opt-In Requirements | Kotlin. Problem. @ ...
Read more >
How to add opt-in compiler argument in build.gradle?
annotation class ExperimentalComposeUiApi. That means, in order to use this LocalSoftwareKeyboardController , I need to add @OptIn() ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found