Mark
02/04/2022, 10:30 AMbuildMap but please can someone explain why this gives a compilation error (unless I uncomment the null):
fun main() {
buildMap {
if (true) {
println("test")
// null
} else {
put("foo", "bar")
}
}
}
https://pl.kotl.in/sohJmyPiJgildor
02/04/2022, 10:33 AMJoffrey
02/04/2022, 10:34 AMif expression as Any?gildor
02/04/2022, 10:35 AMgildor
02/04/2022, 10:35 AMTechnically it could infer the wholeI think because it’s not really an expression it’s BuilderInferenceexpression asifAny?
Joffrey
02/04/2022, 10:36 AMUnit after the put in the else branch works. Interestingly, adding Unit after the whole if is not sufficient, so it's not about the return value of the lambda expected by buildMap.gildor
02/04/2022, 10:37 AMit’s not about the return value of the lambda expected byYes, it’s not about return value, it’s about builder interface inference
Joffrey
02/04/2022, 10:37 AMif from being legal. I expected the builder inference to look for put and infer the type based on that regardless of other structures and expressions. But I know nothing of the builder inference frankly 😄gildor
02/04/2022, 10:38 AMMark
02/04/2022, 10:44 AMnull is unused.Joffrey
02/04/2022, 10:49 AMbuildMap, as mentioned by Andrey. I wouldn't try to add null or Unit in the right places to fix the inferenceMark
02/04/2022, 11:00 AMVictor Petukhov
02/04/2022, 11:57 AMMark
02/10/2023, 2:15 PM