Files
kotlin-fork/compiler/testData/codegen/box/closures/closureCapturingGenericParam.kt
T
Sergej Jaskiewicz f40278c036 An option to allow out-of-scope type parameters in IrManglerComputer
In the lowered IR there are often references to type parameters whose
containers are not in the current scope. This is incorrect semantically,
but it works in practice due to erasure, so when the mangler is used on
the lowered IR, we don't want to crash the compiler.
2023-03-03 22:08:57 +00:00

46 lines
1.1 KiB
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
}
interface Grouping<GroupingInputTP, out GroupingOutputTP> {
fun keyOf(element: GroupingInputTP): GroupingOutputTP
}
fun <GroupingByTP> groupingBy(keySelector: (Char) -> GroupingByTP): Grouping<Char, GroupingByTP> {
fun <T> foo(p0: T, p1: GroupingByTP) {}
foo(0, keySelector('a'))
class A<T>(p0: T, p1: GroupingByTP) {}
A(0, keySelector('a'))
return object : Grouping<Char, GroupingByTP> {
override fun keyOf(element: Char): GroupingByTP = keySelector(element)
}
}
class Delft<DelftTP> {
fun getComparator(other: DelftTP) = { this == other }
}
fun box(): String {
if (computeSum(arrayOf(N(2), N(14))) != 16) return "Fail1"
if (groupingBy { it }.keyOf('A') != 'A') return "Fail2"
return "OK"
}