mirror of
https://github.com/github/codeql.git
synced 2026-04-30 03:05:15 +02:00
Introduce cast for <unsafe-coerce> calls
This commit is contained in:
@@ -1437,6 +1437,28 @@ open class KotlinFileExtractor(
|
||||
logger.warnElement(Severity.ErrorSevere, "Expected to find only one (vararg) argument in ${c.symbol.owner.name.asString()} call", c)
|
||||
}
|
||||
}
|
||||
isBuiltinCall(c, "<unsafe-coerce>", "kotlin.jvm.internal") -> {
|
||||
|
||||
if (c.valueArgumentsCount != 1) {
|
||||
logger.warnElement(Severity.ErrorSevere, "Expected to find only one argument for a kotlin.jvm.internal.<unsafe-coerce>() call", c)
|
||||
return
|
||||
}
|
||||
|
||||
if (c.typeArgumentsCount != 2) {
|
||||
logger.warnElement(Severity.ErrorSevere, "Expected to find two type arguments for a kotlin.jvm.internal.<unsafe-coerce>() call", c)
|
||||
return
|
||||
}
|
||||
|
||||
val id = tw.getFreshIdLabel<DbUnsafecoerceexpr>()
|
||||
val locId = tw.getLocation(c)
|
||||
val type = useType(c.type)
|
||||
tw.writeExprs_unsafecoerceexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
|
||||
tw.writeHasLocation(id, locId)
|
||||
tw.writeCallableEnclosingExpr(id, callable)
|
||||
tw.writeStatementEnclosingExpr(id, enclosingStmt)
|
||||
extractTypeAccess(c.getTypeArgument(1)!!, callable, id, 0, c, enclosingStmt)
|
||||
extractExpressionExpr(c.getValueArgument(0)!!, callable, id, 1, enclosingStmt)
|
||||
}
|
||||
else -> {
|
||||
extractMethodAccess(c.symbol.owner, true, true)
|
||||
}
|
||||
|
||||
@@ -747,6 +747,7 @@ case @expr.kind of
|
||||
| 83 = @stringtemplateexpr
|
||||
| 84 = @varargexpr
|
||||
| 85 = @notnullexpr
|
||||
| 86 = @unsafecoerceexpr
|
||||
;
|
||||
|
||||
/** Holds if this `when` expression was written as an `if` expression. */
|
||||
|
||||
@@ -1144,7 +1144,8 @@ class CastingExpr extends Expr {
|
||||
this instanceof @safecastexpr or
|
||||
this instanceof @implicitcastexpr or
|
||||
this instanceof @implicitnotnullexpr or
|
||||
this instanceof @implicitcoerciontounitexpr
|
||||
this instanceof @implicitcoerciontounitexpr or
|
||||
this instanceof @unsafecoerceexpr
|
||||
}
|
||||
|
||||
/** Gets the target type of this casting expression. */
|
||||
@@ -1194,6 +1195,14 @@ class ImplicitCoercionToUnitExpr extends CastingExpr, @implicitcoerciontounitexp
|
||||
override string getAPrimaryQlClass() { result = "ImplicitCoercionToUnitExpr" }
|
||||
}
|
||||
|
||||
/** An unsafe coerce expression. */
|
||||
class UnsafeCoerceExpr extends CastingExpr, @unsafecoerceexpr {
|
||||
/** Gets a printable representation of this expression. */
|
||||
override string toString() { result = "<unsafe coerce>" }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "UnsafeCoerceExpr" }
|
||||
}
|
||||
|
||||
/** A class instance creation expression. */
|
||||
class ClassInstanceExpr extends Expr, ConstructorCall, @classinstancexpr {
|
||||
/** Gets the number of arguments provided to the constructor of the class instance creation expression. */
|
||||
|
||||
Reference in New Issue
Block a user