Merge pull request #11089 from tamasvajk/kotlin-enum-ctor-call

Kotlin: Extract missing arguments of enum constructor calls
This commit is contained in:
Tamás Vajk
2022-11-07 12:55:27 +01:00
committed by GitHub
8 changed files with 59 additions and 10 deletions

View File

@@ -0,0 +1,9 @@
import java
from Call call, Callable c
where
count(call.getAnArgument()) != c.getNumberOfParameters() and
call.getCallee() = c and
not exists(Parameter p | c.getAParameter() = p and p.isVarargs()) and
call.getFile().isKotlinSourceFile()
select call, c, count(call.getAnArgument()), c.getNumberOfParameters()

View File

@@ -69,6 +69,8 @@ class Element extends @element, Top {
i = 10 and result = "Forwarder for Kotlin calls that need default arguments filling in"
or
i = 11 and result = "Forwarder for a Kotlin class inheriting an interface default method"
or
i = 12 and result = "Argument for enum constructor call"
)
}
}

View File

@@ -174,6 +174,8 @@ classes.kt:
# 49| 0: [ClassInstanceExpr] new Enum(...)
# 49| -3: [TypeAccess] Enum<Direction>
# 49| 0: [TypeAccess] Direction
# 49| 0: [NullLiteral] null
# 49| 1: [IntegerLiteral] 0
# 49| 1: [BlockStmt] { ... }
# 50| 5: [FieldDeclaration] Direction NORTH;
# 50| -1: [TypeAccess] Direction
@@ -209,6 +211,8 @@ classes.kt:
# 53| 0: [ClassInstanceExpr] new Enum(...)
# 53| -3: [TypeAccess] Enum<Color>
# 53| 0: [TypeAccess] Color
# 53| 0: [NullLiteral] null
# 53| 1: [IntegerLiteral] 0
# 53| 1: [BlockStmt] { ... }
# 53| 0: [ExprStmt] <Expr>;
# 53| 0: [KtInitializerAssignExpr] ...=...

View File

@@ -3358,6 +3358,8 @@ exprs.kt:
# 174| 0: [ClassInstanceExpr] new Enum(...)
# 174| -3: [TypeAccess] Enum<Direction>
# 174| 0: [TypeAccess] Direction
# 174| 0: [NullLiteral] null
# 174| 1: [IntegerLiteral] 0
# 174| 1: [BlockStmt] { ... }
# 175| 5: [FieldDeclaration] Direction NORTH;
# 175| -1: [TypeAccess] Direction
@@ -3393,6 +3395,8 @@ exprs.kt:
# 178| 0: [ClassInstanceExpr] new Enum(...)
# 178| -3: [TypeAccess] Enum<Color>
# 178| 0: [TypeAccess] Color
# 178| 0: [NullLiteral] null
# 178| 1: [IntegerLiteral] 0
# 178| 1: [BlockStmt] { ... }
# 178| 0: [ExprStmt] <Expr>;
# 178| 0: [KtInitializerAssignExpr] ...=...

View File

@@ -1470,9 +1470,11 @@
| exprs.kt:170:9:170:17 | r2.height | exprs.kt:165:1:172:1 | foo | VarAccess |
| exprs.kt:170:9:170:21 | ...=... | exprs.kt:165:1:172:1 | foo | AssignExpr |
| exprs.kt:170:21:170:21 | 3 | exprs.kt:165:1:172:1 | foo | IntegerLiteral |
| exprs.kt:174:1:176:1 | 0 | exprs.kt:174:6:176:1 | Direction | IntegerLiteral |
| exprs.kt:174:1:176:1 | Direction | exprs.kt:174:6:176:1 | Direction | TypeAccess |
| exprs.kt:174:1:176:1 | Enum<Direction> | exprs.kt:174:6:176:1 | Direction | TypeAccess |
| exprs.kt:174:1:176:1 | new Enum(...) | exprs.kt:174:6:176:1 | Direction | ClassInstanceExpr |
| exprs.kt:174:1:176:1 | null | exprs.kt:174:6:176:1 | Direction | NullLiteral |
| exprs.kt:175:5:175:10 | ...=... | exprs.kt:0:0:0:0 | <clinit> | KtInitializerAssignExpr |
| exprs.kt:175:5:175:10 | Direction | exprs.kt:0:0:0:0 | <clinit> | TypeAccess |
| exprs.kt:175:5:175:10 | Direction | exprs.kt:0:0:0:0 | <clinit> | TypeAccess |
@@ -1497,9 +1499,11 @@
| exprs.kt:175:25:175:28 | Direction | file://:0:0:0:0 | <none> | TypeAccess |
| exprs.kt:175:25:175:28 | Direction.EAST | exprs.kt:0:0:0:0 | <clinit> | VarAccess |
| exprs.kt:175:25:175:28 | new Direction(...) | exprs.kt:0:0:0:0 | <clinit> | ClassInstanceExpr |
| exprs.kt:178:1:182:1 | 0 | exprs.kt:178:6:182:1 | Color | IntegerLiteral |
| exprs.kt:178:1:182:1 | Color | exprs.kt:178:6:182:1 | Color | TypeAccess |
| exprs.kt:178:1:182:1 | Enum<Color> | exprs.kt:178:6:182:1 | Color | TypeAccess |
| exprs.kt:178:1:182:1 | new Enum(...) | exprs.kt:178:6:182:1 | Color | ClassInstanceExpr |
| exprs.kt:178:1:182:1 | null | exprs.kt:178:6:182:1 | Color | NullLiteral |
| exprs.kt:178:18:178:29 | ...=... | exprs.kt:178:6:182:1 | Color | KtInitializerAssignExpr |
| exprs.kt:178:18:178:29 | int | file://:0:0:0:0 | <none> | TypeAccess |
| exprs.kt:178:18:178:29 | int | file://:0:0:0:0 | <none> | TypeAccess |

View File

@@ -88,6 +88,8 @@ A.kt:
# 23| 0: [ClassInstanceExpr] new Enum(...)
# 23| -3: [TypeAccess] Enum<Enu>
# 23| 0: [TypeAccess] Enu
# 23| 0: [NullLiteral] null
# 23| 1: [IntegerLiteral] 0
# 23| 1: [BlockStmt] { ... }
# 24| 5: [FieldDeclaration] Enu A;
# 24| -1: [TypeAccess] Enu

View File

@@ -231,9 +231,11 @@
| enumClass.kt:0:0:0:0 | EnumWithFunctions[] | TypeAccess |
| enumClass.kt:0:0:0:0 | String | TypeAccess |
| enumClass.kt:0:0:0:0 | String | TypeAccess |
| enumClass.kt:1:1:4:1 | 0 | IntegerLiteral |
| enumClass.kt:1:1:4:1 | Enum<EnumClass> | TypeAccess |
| enumClass.kt:1:1:4:1 | EnumClass | TypeAccess |
| enumClass.kt:1:1:4:1 | new Enum(...) | ClassInstanceExpr |
| enumClass.kt:1:1:4:1 | null | NullLiteral |
| enumClass.kt:1:22:1:31 | ...=... | KtInitializerAssignExpr |
| enumClass.kt:1:22:1:31 | int | TypeAccess |
| enumClass.kt:1:22:1:31 | int | TypeAccess |
@@ -256,9 +258,11 @@
| enumClass.kt:3:5:3:12 | EnumClass.enum2 | VarAccess |
| enumClass.kt:3:5:3:12 | new EnumClass(...) | ClassInstanceExpr |
| enumClass.kt:3:11:3:11 | 1 | IntegerLiteral |
| enumClass.kt:6:1:16:1 | 0 | IntegerLiteral |
| enumClass.kt:6:1:16:1 | Enum<EnumWithFunctions> | TypeAccess |
| enumClass.kt:6:1:16:1 | EnumWithFunctions | TypeAccess |
| enumClass.kt:6:1:16:1 | new Enum(...) | ClassInstanceExpr |
| enumClass.kt:6:1:16:1 | null | NullLiteral |
| enumClass.kt:8:3:11:4 | ...=... | KtInitializerAssignExpr |
| enumClass.kt:8:3:11:4 | <implicit coercion to unit> | ImplicitCoercionToUnitExpr |
| enumClass.kt:8:3:11:4 | EnumWithFunctions | TypeAccess |