spnda
05/12/2021, 2:47 PM'if' must have both main and 'else' branches if used as an expression
fun exampleFunc(someBoolean: Boolean) = when (someBoolean) {
else -> {
val otherBoolean = Random.nextBoolean()
if (otherBoolean) {
print("Yay!")
}
}
}
It seems to think it is a ternary, I guess.Colin Contreary
05/12/2021, 8:03 PMDany
05/13/2021, 2:10 AMLastExceed
05/13/2021, 8:29 AM?:
similar to how there's get()
for []
? if not, why not ?ninadmg
05/13/2021, 8:58 AMDanny Zhang
05/13/2021, 10:00 AMDavid Smith
05/13/2021, 2:26 PMFailed to inject value for parameter [client] of class
I’m trying to inject a client in the constructor of a StringSpec
test
@Client(value = "/") private val client: RxHttpClient,
I just can’t work it out.Slackbot
05/13/2021, 4:36 PMelect
05/14/2021, 5:31 AMpublic interface ArtifactRepository {
String getName();
void setName(String name);
I cant use a override var name: String
, but I'm forced to
class GithubArtifactRepository : ArtifactRepository {
private var n = "github"
override fun getName(): String = n
override fun setName(name: String) { n = name }
kralli
05/14/2021, 10:39 AMinterface A {
fun a(): String = bu
"test ${unresolved}"
}
}
Gilles Barbier
05/14/2021, 1:08 PMinterface TaskA
class TaskWithExceptionInInitializerError : Task(), TaskA {
companion object {
@JvmStatic
val e: Nothing = throw Exception("ExceptionInInitializerError")
}
}
Of course this task is written to trigger an Exception during instantiation. I had no issue with Kotlin 1.4.30, but with 1.5.0, it does not compile, with following error:
org.jetbrains.kotlin.backend.common.BackendException: Backend Internal error: Exception during code generation
...
Caused by: java.lang.RuntimeException: Exception while generating code for:
FUN JVM_STATIC_WRAPPER name:getE visibility:public modality:FINAL <> () returnType:kotlin.Nothing
EXPRESSION_BODY
BLOCK type=kotlin.Nothing origin=null
CALL 'public final fun <get-e> (): kotlin.Nothing declared in io.infinitic.config.tasks.TaskWithExceptionInInitializerError.Companion' type=kotlin.Nothing origin=null
$this: GET_FIELD 'FIELD FIELD_FOR_OBJECT_INSTANCE name:Companion type:io.infinitic.config.tasks.TaskWithExceptionInInitializerError.Companion visibility:public [final,static]' type=io.infinitic.config.tasks.TaskWithExceptionInInitializerError.Companion origin=null
CALL 'public final fun throwKotlinNothingValueException (): kotlin.Nothing declared in kotlin.jvm.internal.Intrinsics' type=kotlin.Nothing origin=null
at org.jetbrains.kotlin.backend.jvm.codegen.FunctionCodegen.generate(FunctionCodegen.kt:54)
at org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen.generateMethodNode(ClassCodegen.kt:338)
at org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen.generateMethod(ClassCodegen.kt:353)
at org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen.generate(ClassCodegen.kt:128)
at org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory.doGenerateFilesInternal(JvmIrCodegenFactory.kt:206)
... 35 more
Caused by: java.lang.AssertionError: IrCall expected inside JvmStatic wrapper:
FUN JVM_STATIC_WRAPPER name:getE visibility:public modality:FINAL <> () returnType:kotlin.Nothing
EXPRESSION_BODY
BLOCK type=kotlin.Nothing origin=null
CALL 'public final fun <get-e> (): kotlin.Nothing declared in io.infinitic.config.tasks.TaskWithExceptionInInitializerError.Companion' type=kotlin.Nothing origin=null
$this: GET_FIELD 'FIELD FIELD_FOR_OBJECT_INSTANCE name:Companion type:io.infinitic.config.tasks.TaskWithExceptionInInitializerError.Companion visibility:public [final,static]' type=io.infinitic.config.tasks.TaskWithExceptionInInitializerError.Companion origin=null
CALL 'public final fun throwKotlinNothingValueException (): kotlin.Nothing declared in kotlin.jvm.internal.Intrinsics' type=kotlin.Nothing origin=null
at org.jetbrains.kotlin.backend.jvm.codegen.IrCodegenUtilsKt.isAccessorForDeprecatedJvmStaticProperty(irCodegenUtils.kt:364)
at org.jetbrains.kotlin.backend.jvm.codegen.IrCodegenUtilsKt.isDeprecatedFunction(irCodegenUtils.kt:348)
at org.jetbrains.kotlin.backend.jvm.codegen.FunctionCodegen.calculateMethodFlags(FunctionCodegen.kt:184)
at org.jetbrains.kotlin.backend.jvm.codegen.FunctionCodegen.doGenerate(FunctionCodegen.kt:59)
at org.jetbrains.kotlin.backend.jvm.codegen.FunctionCodegen.generate(FunctionCodegen.kt:52)
... 39 more
Any idea, how to avoid this?Jose A.
05/14/2021, 2:50 PMjava.lang.ClassCastException: class [[Ljava.lang.Object; cannot be cast to class [[Ljava.lang.String; ([[Ljava.lang.Object; and [[Ljava.lang.String; are in module java.base of loader 'bootstrap')
at edu.upc.groups.service.adapter.GroupTemplateApi$$serializer.deserialize(GroupApiRestDomainMapping.kt:75)
at edu.upc.groups.service.adapter.GroupTemplateApi$$serializer.deserialize(GroupApiRestDomainMapping.kt:75)
at kotlinx.serialization.json.internal.PolymorphicKt.decodeSerializableValuePolymorphic(Polymorphic.kt:63)
The serializable class is (working perfectly in previous Kotlin version)
@Serializable
internal class GroupTemplateApi(
val id: String,
val expression: String,
val attributes: Array<String>,
val records: Array<Array<String>>,
val owner: Int,
)
What do you thing, I should file a bug? Kotlin? Serialize library? I already tried to clean and reset caches.Yan Pujante
05/14/2021, 3:22 PMimport kotlin.time.*
class MyClass {
// ...
private var _timeSource = TimeSource.Monotonic
// ...
}
results in Unresolved reference: TimeSource
If I use private var _timeSource = kotlin.time.TimeSource.Monotonic
, then it is fine. Any idea?LastExceed
05/14/2021, 7:17 PMLastExceed
05/14/2021, 7:18 PMPatrick Ramsey
05/15/2021, 12:17 AMChristopher Elías
05/15/2021, 1:33 AMflattenMerge
going to be "stable"? Whe are now in coroutines 1.5.0 and it still needs to be annotated with @ExperimentalCoroutinesApiClay Gillman
05/15/2021, 5:28 AMResult
by default! I was surprised to find this out given how quiet this change was.
Using Result
as a return type for libraries and in general seems like a great middle ground between the looseness of unchecked exceptions and the verboseness of sealed classes as return types.
You can force callers of your method to handle any failure by simply doing fun method(): Result<T> = runCatching { ... }
, allowing uncaught exceptions in the method to bubble up into the failure case of the result. This is much less code than creating a sealed class for every failure case and writing the logic to convert each exception to them. Easier to read and reason about, and doesn't even force you to adopt functional-style-programming.
Now that this is doable with vanilla Kotlin, what does everyone think? Would you adopt this as your default way of error handling? How would you feel consuming a library that exclusively used Result
instead of throwing exceptions?carbaj0
05/15/2021, 11:40 AMAyfri
05/16/2021, 12:41 AMGrigorii Yurkov
05/16/2021, 11:43 AMSirNapkin1334
05/16/2021, 8:19 PMval man = object : ScriptEngineManager(Thread.currentThread().contextClassLoader) {
val engine: ScriptEngine inline get() = getEngineByExtension("kts")!!
}
When I try to do man.engine
, it says Unresolved reference: engine
, as if it's not there at all. It's very strange. The weirdest thing, is that if I take that code, and copy-paste it into my function, so that man
is a local variable, it works fine. But if I have it as a field, I cannot access engine
and I don't know why. There are no naming conflicts with the superclass.Grigorii Yurkov
05/17/2021, 12:36 PMequals
and hashCode
(for class A
) with violating hashcode
contract. Is it bug, or am I wrong?nitrog42
05/17/2021, 2:30 PMglenkpeterson
05/17/2021, 3:05 PMdec31_2015
in Java. How should I name that in Kotlin? I get this warning about the underscore.Kirill Grouchnikov
05/17/2021, 5:19 PMShivansh Mishra
05/18/2021, 1:49 AMSangmin Lee
05/18/2021, 5:15 AMJ6ey
05/18/2021, 8:13 AMRoy Grini
05/18/2021, 10:07 AMRoy Grini
05/18/2021, 10:07 AMirus
05/18/2021, 10:12 AMLazard
05/18/2021, 10:27 AMirus
05/18/2021, 10:36 AMNow, both java and kotlin cater to this use case, they cater to it in a different way, and I'm pretty sure that if I could smack a giant reset button and design kotlin all over again and release it today into public beta, then kotlin would have followed in java's shoes. Especially considering that the java version is in many ways far more powerful than kotlins: You can do more than just 'check type' with this syntax (you can also 'deconstruct' value types), you don't NEED a block, as in, this works too:
Roy Grini
05/18/2021, 10:51 AMirus
05/18/2021, 10:55 AM@Metadata(
mv = {1, 4, 3},
bv = {1, 0, 3},
k = 1,
d1 = {"\u0000*\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010$\n\u0002\u0010\u000e\n\u0002\b\u0005\n\u0002\u0010\u0002\n\u0000\u0018\u00002\u00020\u0001B\u0015\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0005¢\u0006\u0002\u0010\u0006J\b\u0010\u000e\u001a\u00020\u000fH\u0016R&\u0010\u0007\u001a\u000e\u0012\u0004\u0012\u00020\t\u0012\u0004\u0012\u00020\t0\bX\u0096\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\n\u0010\u000b\"\u0004\b\f\u0010\rR\u000e\u0010\u0002\u001a\u00020\u0003X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0004\u001a\u00020\u0005X\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006\u0010"},
d2 = {"Llink/kotlin/repo/GithubConfigurationService;", "Llink/kotlin/repo/ConfigurationService;", "httpClient", "Lorg/apache/http/client/HttpClient;", "yamlMapper", "Lcom/fasterxml/jackson/databind/ObjectMapper;", "(Lorg/apache/http/client/HttpClient;Lcom/fasterxml/jackson/databind/ObjectMapper;)V", "configuration", "", "", "getConfiguration", "()Ljava/util/Map;", "setConfiguration", "(Ljava/util/Map;)V", "update", "", "repo.kotlin.link.main"}
)
Roy Grini
05/18/2021, 10:56 AMirus
05/18/2021, 10:57 AMThis annotation is present on any class file produced by the Kotlin compiler and is read by the compiler and reflection
Roy Grini
05/18/2021, 10:59 AMirus
05/18/2021, 11:01 AMIntelliJ needs this info also in order to provide debugging i guess.Debugging built on top of JDI, and probably can't benefit from @metadata directly
thanksforallthefish
05/18/2021, 12:21 PMirus
05/18/2021, 12:58 PM