Is this a compiler bug or am I missing something? ...
# announcements
e
Is this a compiler bug or am I missing something?
Copy code
abstract class A<T> {
    abstract fun broken(vararg values: T): T
}

// Error: Class 'B' is not abstract and does not implement abstract base class member public abstract fun broken(vararg values: Int): Int defined in A
// Error: 'broken' overrides nothing
class B : A<Int>() {
    override fun broken(vararg values: Int): Int {
        return 5
    }
}
The same code works fine if the subclass is with a "normal" object and not a primitive type. Actually the IntelliJ IDE also thinks it should work, at least it generates the code for it but the compiler then complains about it. Tested with kotlin 1.3.31
youtrack 2
p
Looks like a bug. I guess class
A
expects method that accepts
Array<Int>
(or
Integer[]
) while class
B
has
IntArray
(or
int[]
).
e
In the meantime I found a bug entry in: https://youtrack.jetbrains.com/issue/KT-9495
👍 1
Based on the bug description I have found a workaround:
Copy code
abstract class A<T> {
    abstract fun broken(vararg values: T): String
}

class B : A<Int>() {
    override fun broken(values: Array<out Int>): String {
        return broken(*values.toIntArray())
    }

    fun broken(vararg values: Int): String {
        return values.joinToString { it.toString() }
    }
}
Unfortunately it pollutes
class B
with another visible method
broken(values: Array<out Int>)
. If the bug ever gets fixed the workaround will lead to a syntax error. Any better ideas?