Kotlin: Revert type erasure within $default functions

This imprecise implementation turned out to cause linkage errors, e.g. when type variables in the signatures of member methods were inappropriately erased. For the time being we accept that $default methods despite having erased signatures in keeping with their JVM representation can contain expressions whose types make reference to their
surrounding function or class' type variables, even though they should be out of scope since $default methods are static and don't have type parameters, and need to cope with the inconsistency in QL.
This commit is contained in:
Chris Smowton
2022-12-12 18:33:22 +00:00
parent 636d5e341c
commit dd86f7a696
5 changed files with 48 additions and 28 deletions

View File

@@ -1337,7 +1337,7 @@ test.kt:
# 145| 0: [AssignExpr] ...=...
# 145| 0: [VarAccess] p4
# 145| 1: [MethodAccess] listOf(...)
# 145| -2: [TypeAccess] Object
# 145| -2: [TypeAccess] T
# 145| -1: [TypeAccess] CollectionsKt
# 145| 0: [VarAccess] p2
# 145| 3: [IfStmt] if (...)
@@ -1360,7 +1360,7 @@ test.kt:
# 145| 0: [AssignExpr] ...=...
# 145| 0: [VarAccess] p6
# 145| 1: [MethodAccess] listOf(...)
# 145| -2: [TypeAccess] Object
# 145| -2: [TypeAccess] S
# 145| -1: [TypeAccess] CollectionsKt
# 145| 0: [VarAccess] p1
# 145| 5: [ReturnStmt] return ...

View File

@@ -0,0 +1,36 @@
| test.kt:124:3:126:3 | ...=... | test.kt:122:19:122:19 | T |
| test.kt:124:3:126:3 | ...=... | test.kt:122:19:122:19 | T |
| test.kt:124:3:126:3 | p1 | test.kt:122:19:122:19 | T |
| test.kt:124:3:126:3 | p2 | test.kt:122:19:122:19 | T |
| test.kt:124:3:126:3 | p2 | test.kt:122:19:122:19 | T |
| test.kt:124:3:126:3 | p3 | test.kt:122:19:122:19 | T |
| test.kt:124:3:126:3 | p3 | test.kt:122:19:122:19 | T |
| test.kt:124:22:124:22 | p1 | test.kt:122:19:122:19 | T |
| test.kt:135:3:135:43 | ...=... | test.kt:122:19:122:19 | T |
| test.kt:135:3:135:43 | p1 | test.kt:122:19:122:19 | T |
| test.kt:135:3:135:43 | p2 | test.kt:122:19:122:19 | T |
| test.kt:135:3:135:43 | p2 | test.kt:122:19:122:19 | T |
| test.kt:135:3:135:43 | testReturn(...) | test.kt:122:19:122:19 | T |
| test.kt:145:3:147:3 | ...=... | file:///modules/java.base/java/util/List.class:0:0:0:0 | List<S> |
| test.kt:145:3:147:3 | ...=... | file:///modules/java.base/java/util/List.class:0:0:0:0 | List<T> |
| test.kt:145:3:147:3 | ...=... | test.kt:143:27:143:27 | T |
| test.kt:145:3:147:3 | ...=... | test.kt:143:27:143:27 | T |
| test.kt:145:3:147:3 | ...=... | test.kt:145:8:145:12 | S |
| test.kt:145:3:147:3 | p1 | test.kt:145:8:145:12 | S |
| test.kt:145:3:147:3 | p2 | test.kt:143:27:143:27 | T |
| test.kt:145:3:147:3 | p2 | test.kt:143:27:143:27 | T |
| test.kt:145:3:147:3 | p3 | test.kt:143:27:143:27 | T |
| test.kt:145:3:147:3 | p3 | test.kt:143:27:143:27 | T |
| test.kt:145:3:147:3 | p4 | file:///modules/java.base/java/util/List.class:0:0:0:0 | List<T> |
| test.kt:145:3:147:3 | p4 | file:///modules/java.base/java/util/List.class:0:0:0:0 | List<T> |
| test.kt:145:3:147:3 | p5 | test.kt:145:8:145:12 | S |
| test.kt:145:3:147:3 | p5 | test.kt:145:8:145:12 | S |
| test.kt:145:3:147:3 | p6 | file:///modules/java.base/java/util/List.class:0:0:0:0 | List<S> |
| test.kt:145:3:147:3 | p6 | file:///modules/java.base/java/util/List.class:0:0:0:0 | List<S> |
| test.kt:145:30:145:30 | p1 | test.kt:145:8:145:12 | S |
| test.kt:145:66:145:74 | T | test.kt:143:27:143:27 | T |
| test.kt:145:66:145:74 | listOf(...) | file:///modules/java.base/java/util/List.class:0:0:0:0 | List<T> |
| test.kt:145:73:145:73 | p2 | test.kt:143:27:143:27 | T |
| test.kt:145:111:145:119 | S | test.kt:145:8:145:12 | S |
| test.kt:145:111:145:119 | listOf(...) | file:///modules/java.base/java/util/List.class:0:0:0:0 | List<S> |
| test.kt:145:118:145:118 | p1 | test.kt:145:8:145:12 | S |

View File

@@ -5,6 +5,8 @@ class InstantiatedType extends ParameterizedType {
}
// This checks that all type parameter references are erased in the context of a $default function.
// Note this is currently expected to fail since for the time being we extract type variable references
// even where they should be out of scope.
predicate containsTypeVariables(Type t) {
t instanceof TypeVariable or
containsTypeVariables(t.(InstantiatedType).getATypeArgument()) or