https://kotlinlang.org logo
Title
s

serebit

01/10/2019, 4:15 AM
Is there any particular reason that
class ReactMap : MutableMap<Long, MutableList<EmoteData>> by (mutableMapOf<Long, MutableList<EmoteData>>()
    .withDefault { mutableListOf<EmoteData>() })
compiles fine, and
class ReactMap : MutableMap<Long, MutableList<EmoteData>> by mutableMapOf()
compiles fine, but
class ReactMap : MutableMap<Long, MutableList<EmoteData>> by (mutableMapOf().withDefault { mutableListOf() })
doesn't? Is it a bug in the compiler, or is it intentional?
😕 1
d

Dico

01/10/2019, 12:46 PM
It's because the
mutableMapOf()
invocation can't infer type arguments in the last example. It might work if you enable the improved type inference, but I'm not sure.
s

serebit

01/10/2019, 5:31 PM
How do I enable that?
d

Dico

01/10/2019, 5:42 PM
I'm not sure, look for the blog post on 1.3 I guess
It should be a compiler argument
tasks.withType<KotlinCompile> {
        kotlinOptions {
            jvmTarget = "1.8"
            freeCompilerArgs = listOf(
                "-XXLanguage:+InlineClasses",
                "-XXLanguage:+NewTypeInference",
                "-Xuse-experimental=kotlin.Experimental"
            )
        }
    }
^ Using kotlin gradle DSL
-XXLanguage:+NewTypeInference
👌 1