Files
codeql/java/ql/test/kotlin/library-tests/parameter-defaults/erasure.ql
Chris Smowton bef4011947 Kotlin: fix type variable erasure inside default function values
Previously because extractClassInstance didn't use the declaration stack, we wouldn't notice that it was legal to refer to its type variable in the context of extracting a specialised method <-> method source-decl edge. This led to erasing the types of the source-decl, so that e.g. Map.put(...) would have signature (Object, Object) not (K, V)
as it should.
2022-10-07 17:31:38 +01:00

20 lines
622 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.
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()