Background:
I'm working on a small code generator. I would like to avoid the usual problem of no code hints before the code is actually generated. To solve this I created a general generic dummy method of the sort I intend to generate.
inline fun <R: Any> Any.into(block: MorphBuilder<R>.() -> Unit): MorphBuilder<R> {
throw IllegalStateException("Didn't generate extension method")
}
This would provide the hints in the ide. After the actual specific methods would be generated
class FooMorphBuilder(
var a: String?,
var b: Double?,
var c: Int?,
var d: Float?,
var e: List<String>?
) : MorphBuilder<Foo> {
override fun morph(): Foo = Foo(a!!, b!!, c!!, d!!, e!!)
}
inline fun <Foo> Boo.into(block: FooMorphBuilder.() -> Unit): FooMorphBuilder =
FooMorphBuilder(this.a, this.b, this.c, this.d, this.e)
they should be used.
Problem:
Unfortunately this causes the following error.
Overload resolution ambiguity:
public inline fun <Foo> Boo.into(block: FooMorphBuilder.() -> Unit): FooMorphBuilder defined in com.example.morph
public inline fun <R : Any> Any.into(block: MorphBuilder<com.example.morph.Foo>.() -> Unit): MorphBuilder<com.example.morph.Foo> defined in com.example.morph
I was hoping the compiler would choose the most specific implementation, but this doesn't seem to be the case.
Is there a way to disambiguate between those signatures?