https://kotlinlang.org logo
#stdlib
Title
# stdlib
s

smallufo

12/28/2021, 5:57 PM
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
Copy code
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 :
Copy code
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 :
Copy code
return buildMap {
      put(key, if (A) "A" else "B")
    }
It is OK but not so readable. But why !?
a

Ayfri

12/28/2021, 6:57 PM
What type is
key
?
i

ilya.gorbunov

12/28/2021, 10:48 PM
Your example works fine with Kotlin 1.6: https://pl.kotl.in/uDlx1wGR2 Could you share a complete reproducer?
s

smallufo

12/28/2021, 11:16 PM
Oops , today I reopened IntelliJ and rollback to my original style and IDEA recognizes it again… Not sure why.🙄 Maybe there was something wrong inside IDEA…
3 Views