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.
This commit is contained in:
Sergej Jaskiewicz
2023-03-03 15:00:40 +01:00
committed by Space Team
parent e3a4d6fa56
commit f40278c036
5 changed files with 51 additions and 11 deletions
@@ -14,7 +14,32 @@ 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 "Fail"
if (computeSum(arrayOf(N(2), N(14))) != 16) return "Fail1"
if (groupingBy { it }.keyOf('A') != 'A') return "Fail2"
return "OK"
}