mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
Merge pull request #10506 from tamasvajk/kotlin-enum-type-access
Kotlin: Fix type access expressions in enum constructor calls
This commit is contained in:
@@ -2498,11 +2498,23 @@ open class KotlinFileExtractor(
|
||||
|
||||
if (e is IrConstructorCall) {
|
||||
extractConstructorTypeAccess(eType, typeAccessType, e.symbol, locId, id, -3, callable, enclosingStmt)
|
||||
} else {
|
||||
val typeAccessId =
|
||||
extractTypeAccess(typeAccessType, locId, id, -3, callable, enclosingStmt)
|
||||
} else if (e is IrEnumConstructorCall) {
|
||||
val enumClass = e.symbol.owner.parent as? IrClass
|
||||
if (enumClass == null) {
|
||||
logger.warnElement("Couldn't find declaring class of enum constructor call", e)
|
||||
return
|
||||
}
|
||||
|
||||
extractTypeArguments(e, typeAccessId, callable, enclosingStmt)
|
||||
val args = (0 until e.typeArgumentsCount).map { e.getTypeArgument(it) }.requireNoNullsOrNull()
|
||||
if (args == null) {
|
||||
logger.warnElement("Found null type argument in enum constructor call", e)
|
||||
return
|
||||
}
|
||||
|
||||
val enumType = enumClass.typeWith(args)
|
||||
extractConstructorTypeAccess(enumType, useType(enumType), e.symbol, locId, id, -3, callable, enclosingStmt)
|
||||
} else {
|
||||
logger.errorElement("Unexpected constructor call type: ${e.javaClass}", e)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ classes.kt:
|
||||
# 49| 5: [BlockStmt] { ... }
|
||||
# 49| 0: [ExprStmt] <Expr>;
|
||||
# 49| 0: [ClassInstanceExpr] new Enum(...)
|
||||
# 49| -3: [TypeAccess] Unit
|
||||
# 49| -3: [TypeAccess] Enum<Direction>
|
||||
# 49| 0: [TypeAccess] Direction
|
||||
# 49| 1: [BlockStmt] { ... }
|
||||
# 50| 5: [FieldDeclaration] Direction NORTH;
|
||||
@@ -193,7 +193,7 @@ classes.kt:
|
||||
# 53| 5: [BlockStmt] { ... }
|
||||
# 53| 0: [ExprStmt] <Expr>;
|
||||
# 53| 0: [ClassInstanceExpr] new Enum(...)
|
||||
# 53| -3: [TypeAccess] Unit
|
||||
# 53| -3: [TypeAccess] Enum<Color>
|
||||
# 53| 0: [TypeAccess] Color
|
||||
# 53| 1: [BlockStmt] { ... }
|
||||
# 53| 0: [ExprStmt] <Expr>;
|
||||
|
||||
@@ -2909,7 +2909,7 @@ exprs.kt:
|
||||
# 168| 5: [BlockStmt] { ... }
|
||||
# 168| 0: [ExprStmt] <Expr>;
|
||||
# 168| 0: [ClassInstanceExpr] new Enum(...)
|
||||
# 168| -3: [TypeAccess] Unit
|
||||
# 168| -3: [TypeAccess] Enum<Direction>
|
||||
# 168| 0: [TypeAccess] Direction
|
||||
# 168| 1: [BlockStmt] { ... }
|
||||
# 169| 5: [FieldDeclaration] Direction NORTH;
|
||||
@@ -2944,7 +2944,7 @@ exprs.kt:
|
||||
# 172| 5: [BlockStmt] { ... }
|
||||
# 172| 0: [ExprStmt] <Expr>;
|
||||
# 172| 0: [ClassInstanceExpr] new Enum(...)
|
||||
# 172| -3: [TypeAccess] Unit
|
||||
# 172| -3: [TypeAccess] Enum<Color>
|
||||
# 172| 0: [TypeAccess] Color
|
||||
# 172| 1: [BlockStmt] { ... }
|
||||
# 172| 0: [ExprStmt] <Expr>;
|
||||
|
||||
@@ -1446,7 +1446,7 @@
|
||||
| exprs.kt:164:9:164:21 | ...=... | exprs.kt:159:1:166:1 | foo | AssignExpr |
|
||||
| exprs.kt:164:21:164:21 | 3 | exprs.kt:159:1:166:1 | foo | IntegerLiteral |
|
||||
| exprs.kt:168:1:170:1 | Direction | exprs.kt:168:6:170:1 | Direction | TypeAccess |
|
||||
| exprs.kt:168:1:170:1 | Unit | exprs.kt:168:6:170:1 | Direction | TypeAccess |
|
||||
| exprs.kt:168:1:170:1 | Enum<Direction> | exprs.kt:168:6:170:1 | Direction | TypeAccess |
|
||||
| exprs.kt:168:1:170:1 | new Enum(...) | exprs.kt:168:6:170:1 | Direction | ClassInstanceExpr |
|
||||
| exprs.kt:169:5:169:10 | ...=... | exprs.kt:0:0:0:0 | <clinit> | KtInitializerAssignExpr |
|
||||
| exprs.kt:169:5:169:10 | Direction | exprs.kt:0:0:0:0 | <clinit> | TypeAccess |
|
||||
@@ -1473,7 +1473,7 @@
|
||||
| exprs.kt:169:25:169:28 | Direction.EAST | exprs.kt:0:0:0:0 | <clinit> | VarAccess |
|
||||
| exprs.kt:169:25:169:28 | new Direction(...) | exprs.kt:0:0:0:0 | <clinit> | ClassInstanceExpr |
|
||||
| exprs.kt:172:1:176:1 | Color | exprs.kt:172:6:176:1 | Color | TypeAccess |
|
||||
| exprs.kt:172:1:176:1 | Unit | exprs.kt:172:6:176:1 | Color | TypeAccess |
|
||||
| exprs.kt:172:1:176:1 | Enum<Color> | exprs.kt:172:6:176:1 | Color | TypeAccess |
|
||||
| exprs.kt:172:1:176:1 | new Enum(...) | exprs.kt:172:6:176:1 | Color | ClassInstanceExpr |
|
||||
| exprs.kt:172:18:172:29 | ...=... | exprs.kt:172:6:176:1 | Color | KtInitializerAssignExpr |
|
||||
| exprs.kt:172:18:172:29 | int | file://:0:0:0:0 | <none> | TypeAccess |
|
||||
|
||||
@@ -86,7 +86,7 @@ A.kt:
|
||||
# 23| 5: [BlockStmt] { ... }
|
||||
# 23| 0: [ExprStmt] <Expr>;
|
||||
# 23| 0: [ClassInstanceExpr] new Enum(...)
|
||||
# 23| -3: [TypeAccess] Unit
|
||||
# 23| -3: [TypeAccess] Enum<Enu>
|
||||
# 23| 0: [TypeAccess] Enu
|
||||
# 23| 1: [BlockStmt] { ... }
|
||||
# 24| 5: [FieldDeclaration] Enu A;
|
||||
|
||||
@@ -199,8 +199,8 @@
|
||||
| enumClass.kt:0:0:0:0 | EnumClass | TypeAccess |
|
||||
| enumClass.kt:0:0:0:0 | EnumClass[] | TypeAccess |
|
||||
| enumClass.kt:0:0:0:0 | String | TypeAccess |
|
||||
| enumClass.kt:1:1:4:1 | Enum<EnumClass> | TypeAccess |
|
||||
| enumClass.kt:1:1:4:1 | EnumClass | TypeAccess |
|
||||
| enumClass.kt:1:1:4:1 | Unit | TypeAccess |
|
||||
| enumClass.kt:1:1:4:1 | new Enum(...) | ClassInstanceExpr |
|
||||
| enumClass.kt:1:22:1:31 | ...=... | KtInitializerAssignExpr |
|
||||
| enumClass.kt:1:22:1:31 | int | TypeAccess |
|
||||
|
||||
Reference in New Issue
Block a user