Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b4beddf

Browse files
tamasvajkigfoo
authored andcommitted
Introduce cast for <unsafe-coerce> calls
1 parent 8d754f5 commit b4beddf

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,28 @@ open class KotlinFileExtractor(
14371437
logger.warnElement(Severity.ErrorSevere, "Expected to find only one (vararg) argument in ${c.symbol.owner.name.asString()} call", c)
14381438
}
14391439
}
1440+
isBuiltinCall(c, "<unsafe-coerce>", "kotlin.jvm.internal") -> {
1441+
1442+
if (c.valueArgumentsCount != 1) {
1443+
logger.warnElement(Severity.ErrorSevere, "Expected to find only one argument for a kotlin.jvm.internal.<unsafe-coerce>() call", c)
1444+
return
1445+
}
1446+
1447+
if (c.typeArgumentsCount != 2) {
1448+
logger.warnElement(Severity.ErrorSevere, "Expected to find two type arguments for a kotlin.jvm.internal.<unsafe-coerce>() call", c)
1449+
return
1450+
}
1451+
1452+
val id = tw.getFreshIdLabel<DbUnsafecoerceexpr>()
1453+
val locId = tw.getLocation(c)
1454+
val type = useType(c.type)
1455+
tw.writeExprs_unsafecoerceexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
1456+
tw.writeHasLocation(id, locId)
1457+
tw.writeCallableEnclosingExpr(id, callable)
1458+
tw.writeStatementEnclosingExpr(id, enclosingStmt)
1459+
extractTypeAccess(c.getTypeArgument(1)!!, callable, id, 0, c, enclosingStmt)
1460+
extractExpressionExpr(c.getValueArgument(0)!!, callable, id, 1, enclosingStmt)
1461+
}
14401462
else -> {
14411463
extractMethodAccess(c.symbol.owner, true, true)
14421464
}

java/ql/lib/config/semmlecode.dbscheme

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,7 @@ case @expr.kind of
747747
| 83 = @stringtemplateexpr
748748
| 84 = @varargexpr
749749
| 85 = @notnullexpr
750+
| 86 = @unsafecoerceexpr
750751
;
751752

752753
/** Holds if this `when` expression was written as an `if` expression. */

java/ql/lib/semmle/code/java/Expr.qll

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,8 @@ class CastingExpr extends Expr {
11441144
this instanceof @safecastexpr or
11451145
this instanceof @implicitcastexpr or
11461146
this instanceof @implicitnotnullexpr or
1147-
this instanceof @implicitcoerciontounitexpr
1147+
this instanceof @implicitcoerciontounitexpr or
1148+
this instanceof @unsafecoerceexpr
11481149
}
11491150

11501151
/** Gets the target type of this casting expression. */
@@ -1194,6 +1195,14 @@ class ImplicitCoercionToUnitExpr extends CastingExpr, @implicitcoerciontounitexp
11941195
override string getAPrimaryQlClass() { result = "ImplicitCoercionToUnitExpr" }
11951196
}
11961197

1198+
/** An unsafe coerce expression. */
1199+
class UnsafeCoerceExpr extends CastingExpr, @unsafecoerceexpr {
1200+
/** Gets a printable representation of this expression. */
1201+
override string toString() { result = "<unsafe coerce>" }
1202+
1203+
override string getAPrimaryQlClass() { result = "UnsafeCoerceExpr" }
1204+
}
1205+
11971206
/** A class instance creation expression. */
11981207
class ClassInstanceExpr extends Expr, ConstructorCall, @classinstancexpr {
11991208
/** Gets the number of arguments provided to the constructor of the class instance creation expression. */

0 commit comments

Comments
 (0)