4a2a77d9b9
Previously, a function reference that used generic parameters from its outer scope was lowered into a top-level non-generic subclass of `FunctionN`, with `FunctionN` type arguments referencing type parameters not present in the scope anymore. This sometimes resulted in generating malformed mangled names. From now on the generated subclass of `FunctionN` is generic. The needed type arguments are passed upon instantiation, when the relevant generic parameters are present in the scope.
21 lines
451 B
Kotlin
Vendored
21 lines
451 B
Kotlin
Vendored
interface IntConvertible {
|
|
fun toInt(): Int
|
|
}
|
|
|
|
fun <FooTP> foo(init: Int, v: FooTP, l: Int.(FooTP) -> Int) = init.l(v)
|
|
|
|
fun <BarTP : IntConvertible> computeSum(array: Array<BarTP>) = foo(0, array) {
|
|
var res = this
|
|
for (element in it) res += element.toInt()
|
|
res
|
|
}
|
|
|
|
class N(val v: Int) : IntConvertible {
|
|
override fun toInt() = v
|
|
}
|
|
|
|
fun box(): String {
|
|
if (computeSum(arrayOf(N(2), N(14))) != 16) return "Fail"
|
|
return "OK"
|
|
}
|