Vampire
01/08/2021, 1:48 PMreturn
but it is a syntax violation. ๐mbonnin
01/08/2021, 1:54 PMmbonnin
01/08/2021, 1:54 PMVampire
01/08/2021, 1:56 PMmbonnin
01/08/2021, 1:57 PMmbonnin
01/08/2021, 1:58 PMVampire
01/08/2021, 1:58 PMVampire
01/08/2021, 1:58 PMVampire
01/08/2021, 1:59 PMVampire
01/08/2021, 1:59 PMif (whatever) return
doMoreStuff()
Vampire
01/08/2021, 1:59 PMapply
function at that time where I could simply do return
Vampire
01/08/2021, 2:01 PMif (!whatever) {
doMoreStuff()
}
but that increases the indentation for each such check which is why I usually have the other stylembonnin
01/08/2021, 2:02 PMmbonnin
01/08/2021, 2:08 PMreturn
is not allowed as a top level statement while others like println
areVampire
01/08/2021, 2:41 PMephemient
01/08/2021, 3:43 PMrun {
if (condition) {
return@run
}
doOtherStuff()
}
ephemient
01/08/2021, 3:44 PMreturn
from the top level of shell scripts, Python scripts, Perl scripts, Ruby scripts, ... anything else I can think ofVampire
01/08/2021, 3:46 PMrun
, thanksVampire
01/08/2021, 3:47 PMephemient
01/08/2021, 3:49 PM.
), return at the "top" level is allowed - it returns to the source-r. but if your script is executed directly (via sh
), return at the top level is not allowedephemient
01/08/2021, 3:50 PMVampire
01/08/2021, 3:55 PMVampire
01/08/2021, 3:55 PMVampire
01/08/2021, 3:56 PMephemient
01/08/2021, 4:01 PMephemient
01/08/2021, 4:02 PMreturn
is betterVampire
01/08/2021, 4:03 PMVampire
01/08/2021, 4:26 PMrun
version does not work. ๐
org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: Couldn't inline method call 'run' into
public constructor Build_label_gradle(target: org.gradle.api.Project, `$$implicitReceiver0`: org.gradle.api.Project) defined in de.empic.build.Build_label_gradle
Vampire
01/08/2021, 4:37 PMfun run(block: () -> Unit) = block()
run {
if (condition) {
return@run
}
doOtherStuff()
}
This works, but makes it a bit uglier againVampire
01/08/2021, 11:57 PMrun
trick does work.
It just didn't in my specific case.
I had this failing
run {
if (true) return@run
ByteArrayOutputStream().use { }
}
While these work:
run {
if (true) return@run
ByteArrayOutputStream().use { }
println()
}
run {
if (true) return@run
ByteArrayOutputStream()
}
also {
if (true) return@also
ByteArrayOutputStream().use { }
}
apply {
if (true) return@apply
ByteArrayOutputStream().use { }
}
ephemient
01/09/2021, 12:12 AM.use { }
Vampire
01/09/2021, 12:15 AMVampire
01/09/2021, 12:15 AMe: D:\Sourcecode\other\showcase\build.gradle.kts:1:1: Back-end (JVM) Internal error: Couldn't inline method call 'run' into
public constructor Build_gradle(host: org.gradle.kotlin.dsl.support.KotlinScriptHost<org.gradle.api.Project>, `$$implicitReceiver0`: org.gradle.api.Project) defined in Build_gradle
run {
if (true) return@run
java.io.ByteArrayOutputStream().use { }
}
Cause: run (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;:
@Lkotlin/internal/InlineOnly;() // invisible
L0
LDC 0
ISTORE 2
L1
LINENUMBER 54 L1
ICONST_0
ISTORE 3
L2
LINENUMBER 57 L2
ALOAD 1
ALOAD 0
INVOKEINTERFACE kotlin/jvm/functions/Function1.invoke (Ljava/lang/Object;)Ljava/lang/Object; (itf)
ARETURN
L3
LOCALVARIABLE $this$run Ljava/lang/Object; L0 L3 0
LOCALVARIABLE block Lkotlin/jvm/functions/Function1; L0 L3 1
LOCALVARIABLE $i$f$run I L1 L3 2
MAXSTACK = 2
MAXLOCALS = 4
File being compiled: (1,1) in C:/Users/bkautler/AppData/Local/Temp/gradle-kotlin-dsl-10303106793239029513.tmp/build.gradle.kts
The root cause java.lang.UnsupportedOperationException was thrown at: org.jetbrains.kotlin.load.kotlin.TypeSignatureMappingKt.mapType(typeSignatureMapping.kt:95)
Vampire
01/09/2021, 12:16 AMephemient
01/09/2021, 12:18 AMVampire
01/09/2021, 12:19 AMVampire
01/09/2021, 12:25 AM