Slight Problem with Varargs


#1

Say I have a generic class in Kotlin that is contravariant:

  class A<in T>

And a function/method has a varargs parameter of that type:

  fun afunc(varargs args: A<T>) …

When I use that function in Java code (I haven’t checked in Kotlin code yet), I get a compiler error when I try to use A objects where the generic is a superclass of T. To fix it, I actually explicitly tell the varargs to be contravariant:

  fun afunc(varargs args: A<in T>) …

And now the code works in Java, but I’m getting a warning from the Kotlin compiler that this is redundant (which I agree that it should be), but removing it causes errors. Something doesn’t seem to be quite right with the translation over to varargs when it comes to generics. The compiler knows that it shouldn’t be necessary to use the use-sight label, but it is necessary.


#2

It's a bug. Please report to the tracker: https://youtrack.jetbrains.com/issues/KT


#3

THAT'S where you report bugs. This was the closest I could find. I had expected to find it on github, but it wasn't there. Thanks for the link.


#4

It's the fifth link from the top in README.md on GitHub. It's also linked from the index page of kotlinlang.org. We're not hiding it.


#5

My bad. I skipped right over those links looking for a header about submitting issues.