Mattia Tommasone
12/11/2020, 1:50 PMrunBlocking {
delay(10000)
}
and then testing it with runBlockingTest
, but since it’s in another runBlocking
block the delay is not being skipped and my test is, in fact, hanging for 10 secs.
I’d like to test that the delay is indeed executed but without really having to wait for it to expireAnimesh Sahu
12/11/2020, 3:13 PMShort
? In other words, we aren't able to make compile time constants for Shorts?LeoColman
12/11/2020, 4:49 PM@No-Arg
data class MyClass(val foo: String) {
val bar by lazy { foo[0] }
}
// Create Foo through reflection, for example, getting it from a database. It will use the zero-arg constructor
val myFoo = getFoo()
myFoo.bar -> NullPointerException
When inspecting the bytecode, the bar$delegate (or something like this) is not initialized in the no-arg constructor, and thus is null in runtime. Do anybody have an idea on how to solve this?Nir
12/11/2020, 4:57 PMDaniele Segato
12/11/2020, 5:14 PMjava.lang.NoSuchMethodError: No direct method <init>(Lkotlin/coroutines/CoroutineContext;I)V in class Lkotlinx/coroutines/flow/internal/ChannelFlow; or its super classes (declaration of 'kotlinx.coroutines.flow.internal.ChannelFlow' appears in /data/app/~~ccBt4dlqHFv3AkedliSnSw==/redacted.package.name.debug-QqdNYvkOKVfFKcKUHZwhVg==/base.apk!classes18.dex)
at kotlinx.coroutines.reactive.PublisherAsFlow.<init>(ReactiveFlow.kt:51)
at kotlinx.coroutines.reactive.PublisherAsFlow.<init>(ReactiveFlow.kt:50)
at kotlinx.coroutines.reactive.ReactiveFlowKt.asFlow(ReactiveFlow.kt:30)
I had a library compiled with
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9
My project used a more recent version
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2
this apparently caused a binary incompatibility....
It is troubling to me because asFlow
wasn't marked experimental.
should I open a ticket / tweet to someone about it?
I shouldn't need to release a new version of the library to make it binary compatible with greater versions.
WHY this is DEEPLY troubling:
If the language doesn't guarantee binary backward compatibility with a previous minor version (1.3.x -> 1.4.x) it means that developers will have to constantly update libraries and eventually maintain multiple versions compiled against multiple version of kotlin for projects that still use a previous minor.
THIS IS A NO GO for any language.
Libraries compiled for Java 6 run just fine on Java 13.
I'm not kotlin need to be that conservative, but at least not break backward compatibility on stable api between minors? Deprecate them for a couple of minors is ok. This is not.bbaldino
12/11/2020, 5:49 PMHasLogger
interface (which defines a logger
property) and make the helper method an extension on that, so that way it could access the logger, but that requires all classes make access to their logger instance public, which seems wrong.
2. Make the helper function an extension function on Logger
directly. This feels like it would be awkward at the call site, as the function itself has nothing to do with logging but would look like logger.myHelperFunction(...)
. Even wrapping the call in a with(logger)
feels a bit weird because it feels like the fact that it logs shoudn't be so explicit.
3. Just suck it up and pass a logger instance. This works but I find it distracting. I have an auto-close-style helper withResource
and calling withResource(myResource) { ... }
feels a lot better than withResource(logger, myResource) { ... }
which seems like it makes it confusing as to which resource is being managed.
4. Have the method use its own logger. This works but our logger instances are part of a hierarchy and include contextual information from the parents, which it would be nice to have when the helper is called in the scope of some class' logger.
Has anyone done anything that worked well for a use case like this?eygraber
12/11/2020, 8:10 PMvar current: Segment? = null
data
.segments
.find { segment ->
shouldSegmentBeShown()
.let { (meetsDependency, crossesFrequencyThreshold) ->
if(meetsDependency && !crossesFrequencyThreshold) {
current = segment
}
meetsDependency && crossesFrequencyThreshold
}
}
Animesh Sahu
12/12/2020, 8:27 AMkotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.enableDependencyPropagation=false
I'm getting this, and can't build
java.lang.IllegalStateException: e: Failed to resolve Kotlin library: D:\Projects\KotlinProjects\keyboard-mouse-kt\keyboard\build\kotlinSourceSetMetadata\commonMain\org.jetbrains.kotlinx-atomicfu-common\org.jetbrains.kotlinx-atomicfu-common-nativeInterop.klib
It seems the lib is generated and present.Mikael Alfredsson
12/12/2020, 10:57 AMfun <T> f(): Foo where T : Bar, T : Baz { ... }
but can I do the same with for example a map?
val map = mapOf<String, T (where T:bar, T:Baz)>
thana
12/12/2020, 3:35 PMNir
12/12/2020, 7:28 PMreturn when(Math.floorMod(value / 90 * rot.dir, 4)) {
0 -> vector
1 -> Point(-vector.j, vector.i)
2 -> Point(-vector.i, -vector.j)
3 -> Point(vector.j,-vector.i)
else -> throw Exception("impossible")
}
THe compiler here forces me to have the else. And I can't even have an assert False in the else, because that doesn't type check, I have to throw an exception which forces me to make up a name. Maybe something like !else at the end of the when or something like that. Or maybe some kind of special function with a contract that lets you do modulus where the compiler knows that only 0 to N-1 are possible outputsNir
12/12/2020, 8:16 PMoperator fun<R> R.rem(transform: (R) -> R) = transform(this)
operator fun<R> R.rem(transform: R.() -> R) = this.transform()
I'm not even allowed to declare bothnanodeath
12/13/2020, 5:39 PMCLOVIS
12/13/2020, 6:03 PMinterface Attributes<T>
enum class StringAttributes : Attributes<T> { ... }
val attributes: Map<Attributes<Any>, Any>
val others: Map<StringAttributes, String> = ...
However, if I write:
attributes = others
I get a Type Mismatch
.
I guess the solution has something to do with properly using in and out, however I don't understand what the correct way to use those is.KayCee
12/14/2020, 4:44 AMlateinit var aLiveData: LiveData<List<..>>
val list = aLiveData.value
The crashlytics said there is a NPE in the second line. It occurs occasionally. I dont really get why, I thought it could be about the lateinit so I change it to a nullable variable (despite the fact there is no "lateinit exception"). Is that correct?Platon Malyugin
12/14/2020, 5:54 AMlateinit var aLiveData: LiveData<List<..>>
aLiveData = // define live data
val list = aLiveData.value
Animesh Sahu
12/14/2020, 8:10 AMmodel { platforms {
and things like that... Gradle docs seem to have no docs for kts as well in this topic 😞christophsturm
12/14/2020, 4:11 PMobject Blah {
val context = context()
}
how can i get the name of the object (“Blah”) from the context method?andylamax
12/15/2020, 5:42 AM10_000_000_000.0.toString()
to display as 10000000000.0
insted of 1.0E10
?xii
12/15/2020, 8:05 AMcafonsomota
12/15/2020, 11:39 AMw: Consider providing an explicit dependency on kotlin-reflect 1.4 to prevent strange errors
w: Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath
It seems kotlin-reflect is being used by android lint which is causing this error. I’ve already tried to:
• declare the right version of kotlin-reflect
• resolve it 1.4.21 via resolutionStrategy
But the error persists. Any suggestion on how I can fix it? Thank you 🙂christophsturm
12/15/2020, 1:41 PMobject MyObj { val blah=getBlah }
, when is getBlah called? when the containing file is imported? or when a method references MyObj.blah
?xii
12/15/2020, 2:57 PMNir
12/15/2020, 6:42 PMJeisson Sáchica
12/15/2020, 7:43 PMsealed
classes? I see a lot of issues like this https://youtrack.jetbrains.com/issue/KT-13495 marked as fixed a long time ago yet I experience this problem in 1.4.21sbeve
12/16/2020, 7:55 AMzain
12/16/2020, 10:32 AMEdoardo Luppi
12/16/2020, 11:07 AMnfrankel
12/16/2020, 11:17 AMwhen
block?
return if (string == null) null
else {
val id = Json.parse(string)?.asObject()?.get("id")
when {
id == null -> null
id.isString -> Util.entry(id.asString(), string)
else -> Util.entry(id.asObject(), string)
}
}
here, i first check a if
then compute the id
then execute my when
using the computed id
it feels not as readable as it couldnfrankel
12/16/2020, 11:18 AMwhen
but then, how do i compute the id
so i can use it in the later evaluations?