mirror of
https://github.com/github/codeql.git
synced 2025-12-22 19:56:32 +01:00
Accept and amend check for anonymous types with type parameters
This commit is contained in:
committed by
Ian Lynagh
parent
c0f3988aaa
commit
96908d153d
@@ -1126,17 +1126,6 @@ open class KotlinFileExtractor(
|
||||
|
||||
extractNewExprForLocalFunction(ids, id, locId, enclosingCallable, enclosingStmt)
|
||||
} else {
|
||||
// Returns true if type is C<T1, T2, ...> where C is declared `class C<T1, T2, ...> { ... }`
|
||||
fun isUnspecialised(type: IrSimpleType) =
|
||||
type.classifier.owner is IrClass &&
|
||||
(type.classifier.owner as IrClass).typeParameters.zip(type.arguments).all { paramAndArg ->
|
||||
(paramAndArg.second as? IrTypeProjection)?.let {
|
||||
// Type arg refers to the class' own type parameter?
|
||||
it.variance == Variance.INVARIANT &&
|
||||
it.type.classifierOrNull?.owner === paramAndArg.first
|
||||
} ?: false
|
||||
}
|
||||
|
||||
val methodId =
|
||||
if (drType != null && extractClassTypeArguments && drType is IrSimpleType && !isUnspecialised(drType)) {
|
||||
if (isBigArityFunctionInvoke) {
|
||||
|
||||
@@ -388,8 +388,10 @@ open class KotlinUsesExtractor(
|
||||
// For non-generic types it will be zero-length list.
|
||||
fun useSimpleTypeClass(c: IrClass, args: List<IrTypeArgument>?, hasQuestionMark: Boolean): TypeResults {
|
||||
if (c.isAnonymousObject) {
|
||||
if (args?.isNotEmpty() == true) {
|
||||
logger.error("Anonymous class with unexpected type arguments")
|
||||
args?.let {
|
||||
if (it.isNotEmpty() && !isUnspecialised(c, it)) {
|
||||
logger.error("Unexpected specialised instance of generic anonymous class")
|
||||
}
|
||||
}
|
||||
|
||||
return useAnonymousClass(c)
|
||||
|
||||
@@ -191,4 +191,19 @@ fun IrTypeArgument.withQuestionMark(b: Boolean): IrTypeArgument =
|
||||
else -> this
|
||||
}
|
||||
|
||||
typealias TypeSubstitution = (IrType, KotlinUsesExtractor.TypeContext, IrPluginContext) -> IrType
|
||||
typealias TypeSubstitution = (IrType, KotlinUsesExtractor.TypeContext, IrPluginContext) -> IrType
|
||||
|
||||
// Returns true if type is C<T1, T2, ...> where C is declared `class C<T1, T2, ...> { ... }`
|
||||
fun isUnspecialised(classType: IrClass, args: List<IrTypeArgument>) =
|
||||
classType.typeParameters.zip(args).all { paramAndArg ->
|
||||
(paramAndArg.second as? IrTypeProjection)?.let {
|
||||
// Type arg refers to the class' own type parameter?
|
||||
it.variance == Variance.INVARIANT &&
|
||||
it.type.classifierOrNull?.owner === paramAndArg.first
|
||||
} ?: false
|
||||
}
|
||||
|
||||
// Returns true if type is C<T1, T2, ...> where C is declared `class C<T1, T2, ...> { ... }`
|
||||
fun isUnspecialised(type: IrSimpleType) = (type.classifier.owner as? IrClass)?.let {
|
||||
isUnspecialised(it, type.arguments)
|
||||
} ?: false
|
||||
|
||||
Reference in New Issue
Block a user