mirror of
https://github.com/github/codeql.git
synced 2026-04-28 02:05:14 +02:00
Kotlin: Extract error expression for enumValues<T> calls
This commit is contained in:
@@ -1778,13 +1778,34 @@ open class KotlinFileExtractor(
|
||||
return
|
||||
}
|
||||
|
||||
val func = ((c.getTypeArgument(0) as? IrSimpleType)?.classifier?.owner as? IrClass)?.declarations?.findSubType<IrFunction> { it.name.asString() == fnName }
|
||||
if (func == null) {
|
||||
logger.errorElement("Couldn't find function $fnName on enum type", c)
|
||||
val enumType = (c.getTypeArgument(0) as? IrSimpleType)?.classifier?.owner
|
||||
if (enumType == null) {
|
||||
logger.errorElement("Couldn't find type of enum type", c)
|
||||
return
|
||||
}
|
||||
|
||||
extractMethodAccess(func, false)
|
||||
if (enumType is IrClass) {
|
||||
val func = enumType.declarations.findSubType<IrFunction> { it.name.asString() == fnName }
|
||||
if (func == null) {
|
||||
logger.errorElement("Couldn't find function $fnName on enum type", c)
|
||||
return
|
||||
}
|
||||
|
||||
extractMethodAccess(func, false)
|
||||
} else if (enumType is IrTypeParameter && enumType.isReified) {
|
||||
// A call to `enumValues<T>()` is being extracted, where `T` is a reified type parameter of an `inline` function.
|
||||
// We can't generate a valid expression here, because we would need to know the type of T on the call site.
|
||||
val id = tw.getFreshIdLabel<DbErrorexpr>()
|
||||
val type = useType(c.type)
|
||||
|
||||
tw.writeExprs_errorexpr(id, type.javaResult.id, parent, idx)
|
||||
tw.writeExprsKotlinType(id, type.kotlinResult.id)
|
||||
tw.writeHasLocation(id, tw.getLocation(c))
|
||||
tw.writeCallableEnclosingExpr(id, callable)
|
||||
tw.writeStatementEnclosingExpr(id, enclosingStmt)
|
||||
} else {
|
||||
logger.errorElement("Unexpected enum type rep ${enumType.javaClass}", c)
|
||||
}
|
||||
}
|
||||
|
||||
fun binopReceiver(id: Label<out DbExpr>, receiver: IrExpression?, receiverDescription: String) {
|
||||
|
||||
@@ -2839,6 +2839,7 @@ exprs.kt:
|
||||
# 272| 0: [TypeAccess] T
|
||||
# 272| 5: [BlockStmt] { ... }
|
||||
# 272| 0: [ReturnStmt] return ...
|
||||
# 272| 0: [ErrorExpr] <error expr>
|
||||
# 274| 13: [Method] callToEnumValues
|
||||
# 274| 3: [TypeAccess] Unit
|
||||
# 274| 5: [BlockStmt] { ... }
|
||||
|
||||
@@ -1725,6 +1725,7 @@
|
||||
| exprs.kt:268:14:268:14 | 1 | exprs.kt:261:1:270:1 | inPlaceOperators | IntegerLiteral |
|
||||
| exprs.kt:272:8:272:66 | T | file://:0:0:0:0 | <none> | TypeAccess |
|
||||
| exprs.kt:272:8:272:66 | T[] | file://:0:0:0:0 | <none> | TypeAccess |
|
||||
| exprs.kt:272:52:272:66 | <error expr> | exprs.kt:272:8:272:66 | getEnumValues | ErrorExpr |
|
||||
| exprs.kt:274:1:277:1 | Unit | file://:0:0:0:0 | <none> | TypeAccess |
|
||||
| exprs.kt:275:5:275:23 | <implicit coercion to unit> | exprs.kt:274:1:277:1 | callToEnumValues | ImplicitCoercionToUnitExpr |
|
||||
| exprs.kt:275:5:275:23 | Color | exprs.kt:274:1:277:1 | callToEnumValues | TypeAccess |
|
||||
|
||||
Reference in New Issue
Block a user