<Does buildMap changes implementations in 1.6?> I ...
# stdlib
s
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
What type is
key
?
i
Your example works fine with Kotlin 1.6: https://pl.kotl.in/uDlx1wGR2 Could you share a complete reproducer?
s
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…