Files
codeql/java/ql/test/kotlin/library-tests/parameter-defaults/erasure.ql
Chris Smowton dd86f7a696 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.
2022-12-12 18:33:22 +00:00

22 lines
769 B
Plaintext

import java
class InstantiatedType extends ParameterizedType {
InstantiatedType() { typeArgs(_, _, this) }
}
// 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
containsTypeVariables(t.(NestedType).getEnclosingType()) or
containsTypeVariables(t.(Wildcard).getATypeBound().getType())
}
from Expr e
where
e.getEnclosingCallable().getName().matches("%$default") and
containsTypeVariables(e.getType())
select e, e.getType()