• d

    dimsuz

    9 months ago
    Most probably wrong channel (point me to the right one). I wonder why does this give me an "overload ambiguity" error?
    fun <R> task(body: () -> R): R = TODO()
    fun <P1, R> task(body: (P1) -> R): R = TODO()
    
    fun main() {
      // overload ambiguity
      task {
        33
      }
    }
    But no ambiguity for these two:
    fun <P1, R> task(body: (P1) -> R): R = TODO()
    fun <P1, P2, R> task(body: (P1, P2) -> R): R = TODO()
    
    fun main() {
      task { v: Int -> 33 }
    }
    d
    Fleshgrinder
    9 replies
    Copy to Clipboard
  • g

    Greg Rynkowski

    9 months ago
    Is that possible to add a new operator (not overload an existing but add a new one)?
    g
    Javier
    +5
    13 replies
    Copy to Clipboard
  • Orhan Tozan

    Orhan Tozan

    9 months ago
    Updated to Kotlin 1.6.10, but now I'm getting this build error. How do I solve this?:
    java.lang.IllegalStateException: Symbol for kotlin.collections/mutableMapOf|-4813910536206556932[0] is unbound
    	at org.jetbrains.kotlin.ir.symbols.impl.IrBindablePublicSymbolBase.getOwner(IrPublicSymbolBase.kt:52)
    Orhan Tozan
    elizarov
    2 replies
    Copy to Clipboard
  • Exerosis

    Exerosis

    9 months ago
    Why does checking if a nullable element is in a non nullable container not contract that the element be not null if true?
    Exerosis
    Dominaezzz
    +2
    6 replies
    Copy to Clipboard
  • Mustafa Ozhan

    Mustafa Ozhan

    9 months ago
    Hello 👋 Today i wanted to replace my custom
    Result
    class with Kotlin Result then I just realised that my coverage was decreased . Unfortunately none of the
    onSuccess
    and
    onFailure
    methods were covered. • Is there any plan of covering them ? • How do you guys cover these methods are you writing Unit test on Kotlin Result methods ?
    Mustafa Ozhan
    Big Chungus
    +1
    8 replies
    Copy to Clipboard
  • SecretX

    SecretX

    9 months ago
    Why does Kotlin compiler let's this trap compile? I introduced an error in production today on my company because of this, I thought the compiler or the IDE would catch something like this, but apparently not.
    ConcurrentHashMap<Int, String>().getOrPut(1) { null } // compiles just fine, but it'll throw in runtime
    mutableMapOf<Int, String>().getOrPut(1) { null } // compiler error: Null can not be a value of a non-null type String
    SecretX
    Big Chungus
    +2
    7 replies
    Copy to Clipboard
  • a

    Astronaut4449

    8 months ago
    Just out of curiosity: Was it ever considered to remove the infix function
    to
    from the stdlib and make it some encapsulated function of a map builder scope so that we can write:
    val squared = mapOf { // this refers to some MapBuilderScope<K,V> with builder inference
        1 to 1 // `to` is only visible in the `MapBuilderScope`
        2 to 4
        3 to 9
    }
    a
    mcpiroman
    +2
    7 replies
    Copy to Clipboard
  • s

    smallufo

    8 months ago
    Does buildMap changes implementations in 1.6? I asked at kotlin lang forum but it seems that forum is inactive … The following code works well before 1.6
    fun getMap(): Map<String, String> {
        return buildMap {
          if (A) {
            put(key, "A")
          } else {
            put(key, "B")
          }
        }
      }
    but after upgrade to kotlin 1.6 , compiler complains type mismatch :
    Type mismatch.
    Required:
    Unit
    Found:
    String
    Type mismatch.
    Required:
    Unit
    Found:
    TypeVariable(V)?
    Type mismatch.
    Required:
    Unit
    Found:
    String?
    I have to change to this style :
    return buildMap {
          put(key, if (A) "A" else "B")
        }
    It is OK but not so readable. But why !?
    s
    a
    +1
    3 replies
    Copy to Clipboard
  • r

    Ruckus

    8 months ago
    Would it make sense to add
    typealias Null = Nothing?
    to the stdlib (and preamble)? Common use case:
    class Info<T>(val description: String, val payload: T, ...)
    
    interface Base<T> {
        fun getInfo(): List<Info<T>>
    }
    
    class Derived: Base<Null> {
        override fun getInfo() = listOf(Info("...", null, ...), ...)
    }
    IMO it reads easier than
    class Derived: Base<Nothing?>
    .(Yes, I understand I could use
    Unit
    in this case to achieve basically the same thing in this contrived example. That's beside the point.)
    r
    ilya.gorbunov
    5 replies
    Copy to Clipboard
  • h

    holgerbrandl

    8 months ago
    To transition to the stable Duration API introduced in v1.6, how can I convert a
    kotlin.time.Duration
    to a
    java.time.temporal.TemporalAmont
    ? E.g. to do
    Instant.now() + 5.seconds
    . With the JDK Duration its easy, because it implements
    TemporalAmont
    .
    h
    ilya.gorbunov
    2 replies
    Copy to Clipboard