Is this something outference would solve? ```fun L...
# language-evolution
y
Is this something outference would solve?
Copy code
fun List<*>.foo() {}
emptyList().foo()
I get an error on
emptyList()
. I understand why, of course, but it feels like overprecise initialisation to me! This example would be nice to support as well, although I can imagine it'd be harder:
Copy code
fun List<String>.foo() {}
emptyList().foo()
(thus `emptyList`'s type arg is
String
)
d
What about this?
Copy code
fun List<*>.foo() {}
fun List<String>.foo() {}

emptyList().foo()
y
An error here would be perfectly apt in my opinion. Interestingly, builder inference chooses the
String
overload:
Copy code
fun List<*>.foo() { println(1) }
fun List<String>.foo() { println(2) }

buildList { foo() } // prints 2
but it does report ambiguity in this case:
Copy code
fun List<Int>.foo() { println(1) }
fun List<String>.foo() { println(2) }

buildList { foo() }
Roughly, I want these "overprecise initialisation" situations to behave like builder inference. It sounds like maybe outference could do this
Another interesting example:
Copy code
fun <K> Map<K, *>.foo(key: K) {}
emptyMap().foo("foo")