Skip to content

Commit 2e72ec7

Browse files
committed
Kotlin: add numeric unary operator test cases
1 parent 264d74f commit 2e72ec7

File tree

4 files changed

+192
-0
lines changed

4 files changed

+192
-0
lines changed

java/ql/test/kotlin/library-tests/exprs/CONSISTENCY/javaEquivalent.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Byte.toInt in java.lang.Byte |
1212
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Byte.toInt in java.lang.Byte |
1313
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Int.dec in java.lang.Integer |
14+
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Int.dec in java.lang.Integer |
15+
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Int.dec in java.lang.Integer |
16+
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Int.dec in java.lang.Integer |
17+
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Int.dec in java.lang.Integer |
18+
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Int.inc in java.lang.Integer |
19+
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Int.inc in java.lang.Integer |
20+
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Int.inc in java.lang.Integer |
21+
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Int.inc in java.lang.Integer |
1422
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Int.rangeTo in java.lang.Integer |
1523
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Int.rangeTo in java.lang.Integer |
1624
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Short.toInt in java.lang.Short |

java/ql/test/kotlin/library-tests/exprs/PrintAst.expected

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2855,6 +2855,106 @@ exprs.kt:
28552855
# 276| 1: [MethodAccess] getEnumValues(...)
28562856
# 276| -2: [TypeAccess] Color
28572857
# 276| -1: [TypeAccess] ExprsKt
2858+
# 279| 14: [Method] unaryExprs
2859+
# 279| 3: [TypeAccess] Unit
2860+
#-----| 4: (Parameters)
2861+
# 279| 0: [Parameter] i
2862+
# 279| 0: [TypeAccess] int
2863+
# 279| 1: [Parameter] d
2864+
# 279| 0: [TypeAccess] double
2865+
# 279| 5: [BlockStmt] { ... }
2866+
# 280| 0: [ExprStmt] <Expr>;
2867+
# 280| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
2868+
# 280| 0: [TypeAccess] Unit
2869+
# 281| 1: [ExprStmt] <Expr>;
2870+
# 281| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
2871+
# 281| 0: [TypeAccess] Unit
2872+
# 282| 2: [ExprStmt] <Expr>;
2873+
# 282| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
2874+
# 282| 0: [TypeAccess] Unit
2875+
# 283| 3: [ExprStmt] <Expr>;
2876+
# 283| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
2877+
# 283| 0: [TypeAccess] Unit
2878+
# 284| 4: [LocalVariableDeclStmt] var ...;
2879+
# 284| 1: [LocalVariableDeclExpr] i0
2880+
# 284| 0: [IntegerLiteral] 1
2881+
# 285| 5: [LocalVariableDeclStmt] var ...;
2882+
# 285| 1: [LocalVariableDeclExpr] i1
2883+
# 285| 0: [IntegerLiteral] 1
2884+
# 286| 6: [ExprStmt] <Expr>;
2885+
# 286| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
2886+
# 286| 0: [TypeAccess] Unit
2887+
# 286| 1: [StmtExpr] <Stmt>
2888+
# 286| 0: [BlockStmt] { ... }
2889+
# 286| 0: [LocalVariableDeclStmt] var ...;
2890+
# 286| 1: [LocalVariableDeclExpr] tmp0
2891+
# 286| 0: [VarAccess] i0
2892+
# 286| 1: [ExprStmt] <Expr>;
2893+
# 286| 0: [AssignExpr] ...=...
2894+
# 286| 0: [VarAccess] i0
2895+
# 286| 1: [MethodAccess] inc(...)
2896+
# 286| -1: [VarAccess] tmp0
2897+
# 286| 2: [ExprStmt] <Expr>;
2898+
# 286| 0: [VarAccess] tmp0
2899+
# 287| 7: [ExprStmt] <Expr>;
2900+
# 287| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
2901+
# 287| 0: [TypeAccess] Unit
2902+
# 287| 1: [StmtExpr] <Stmt>
2903+
# 287| 0: [BlockStmt] { ... }
2904+
# 287| 0: [ExprStmt] <Expr>;
2905+
# 287| 0: [AssignExpr] ...=...
2906+
# 287| 0: [VarAccess] i0
2907+
# 287| 1: [MethodAccess] inc(...)
2908+
# 287| -1: [VarAccess] i0
2909+
# 287| 1: [ExprStmt] <Expr>;
2910+
# 287| 0: [VarAccess] i0
2911+
# 288| 8: [ExprStmt] <Expr>;
2912+
# 288| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
2913+
# 288| 0: [TypeAccess] Unit
2914+
# 288| 1: [StmtExpr] <Stmt>
2915+
# 288| 0: [BlockStmt] { ... }
2916+
# 288| 0: [LocalVariableDeclStmt] var ...;
2917+
# 288| 1: [LocalVariableDeclExpr] tmp1
2918+
# 288| 0: [VarAccess] i0
2919+
# 288| 1: [ExprStmt] <Expr>;
2920+
# 288| 0: [AssignExpr] ...=...
2921+
# 288| 0: [VarAccess] i0
2922+
# 288| 1: [MethodAccess] dec(...)
2923+
# 288| -1: [VarAccess] tmp1
2924+
# 288| 2: [ExprStmt] <Expr>;
2925+
# 288| 0: [VarAccess] tmp1
2926+
# 289| 9: [ExprStmt] <Expr>;
2927+
# 289| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
2928+
# 289| 0: [TypeAccess] Unit
2929+
# 289| 1: [StmtExpr] <Stmt>
2930+
# 289| 0: [BlockStmt] { ... }
2931+
# 289| 0: [ExprStmt] <Expr>;
2932+
# 289| 0: [AssignExpr] ...=...
2933+
# 289| 0: [VarAccess] i0
2934+
# 289| 1: [MethodAccess] dec(...)
2935+
# 289| -1: [VarAccess] i0
2936+
# 289| 1: [ExprStmt] <Expr>;
2937+
# 289| 0: [VarAccess] i0
2938+
# 290| 10: [ExprStmt] <Expr>;
2939+
# 290| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
2940+
# 290| 0: [TypeAccess] Unit
2941+
# 290| 1: [MethodAccess] inc(...)
2942+
# 290| -1: [VarAccess] i0
2943+
# 291| 11: [ExprStmt] <Expr>;
2944+
# 291| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
2945+
# 291| 0: [TypeAccess] Unit
2946+
# 291| 1: [MethodAccess] dec(...)
2947+
# 291| -1: [VarAccess] i0
2948+
# 292| 12: [ExprStmt] <Expr>;
2949+
# 292| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
2950+
# 292| 0: [TypeAccess] Unit
2951+
# 292| 1: [MethodAccess] inc(...)
2952+
# 292| -1: [VarAccess] i1
2953+
# 293| 13: [ExprStmt] <Expr>;
2954+
# 293| 0: [ImplicitCoercionToUnitExpr] <implicit coercion to unit>
2955+
# 293| 0: [TypeAccess] Unit
2956+
# 293| 1: [MethodAccess] dec(...)
2957+
# 293| -1: [VarAccess] i1
28582958
# 142| 2: [Class] C
28592959
# 142| 1: [Constructor] C
28602960
#-----| 4: (Parameters)

java/ql/test/kotlin/library-tests/exprs/exprs.expected

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,6 +1738,73 @@
17381738
| exprs.kt:276:5:276:26 | ExprsKt | exprs.kt:274:1:277:1 | callToEnumValues | TypeAccess |
17391739
| exprs.kt:276:5:276:26 | Unit | exprs.kt:274:1:277:1 | callToEnumValues | TypeAccess |
17401740
| exprs.kt:276:5:276:26 | getEnumValues(...) | exprs.kt:274:1:277:1 | callToEnumValues | MethodAccess |
1741+
| exprs.kt:279:1:294:1 | Unit | file://:0:0:0:0 | <none> | TypeAccess |
1742+
| exprs.kt:279:16:279:21 | int | file://:0:0:0:0 | <none> | TypeAccess |
1743+
| exprs.kt:279:24:279:32 | double | file://:0:0:0:0 | <none> | TypeAccess |
1744+
| exprs.kt:280:5:280:6 | <implicit coercion to unit> | exprs.kt:279:1:294:1 | unaryExprs | ImplicitCoercionToUnitExpr |
1745+
| exprs.kt:280:5:280:6 | Unit | exprs.kt:279:1:294:1 | unaryExprs | TypeAccess |
1746+
| exprs.kt:281:5:281:6 | <implicit coercion to unit> | exprs.kt:279:1:294:1 | unaryExprs | ImplicitCoercionToUnitExpr |
1747+
| exprs.kt:281:5:281:6 | Unit | exprs.kt:279:1:294:1 | unaryExprs | TypeAccess |
1748+
| exprs.kt:282:5:282:6 | <implicit coercion to unit> | exprs.kt:279:1:294:1 | unaryExprs | ImplicitCoercionToUnitExpr |
1749+
| exprs.kt:282:5:282:6 | Unit | exprs.kt:279:1:294:1 | unaryExprs | TypeAccess |
1750+
| exprs.kt:283:5:283:6 | <implicit coercion to unit> | exprs.kt:279:1:294:1 | unaryExprs | ImplicitCoercionToUnitExpr |
1751+
| exprs.kt:283:5:283:6 | Unit | exprs.kt:279:1:294:1 | unaryExprs | TypeAccess |
1752+
| exprs.kt:284:5:284:14 | i0 | exprs.kt:279:1:294:1 | unaryExprs | LocalVariableDeclExpr |
1753+
| exprs.kt:284:14:284:14 | 1 | exprs.kt:279:1:294:1 | unaryExprs | IntegerLiteral |
1754+
| exprs.kt:285:5:285:14 | i1 | exprs.kt:279:1:294:1 | unaryExprs | LocalVariableDeclExpr |
1755+
| exprs.kt:285:14:285:14 | 1 | exprs.kt:279:1:294:1 | unaryExprs | IntegerLiteral |
1756+
| exprs.kt:286:5:286:6 | i0 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
1757+
| exprs.kt:286:5:286:6 | i0 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
1758+
| exprs.kt:286:5:286:8 | ...=... | exprs.kt:279:1:294:1 | unaryExprs | AssignExpr |
1759+
| exprs.kt:286:5:286:8 | <Stmt> | exprs.kt:279:1:294:1 | unaryExprs | StmtExpr |
1760+
| exprs.kt:286:5:286:8 | <implicit coercion to unit> | exprs.kt:279:1:294:1 | unaryExprs | ImplicitCoercionToUnitExpr |
1761+
| exprs.kt:286:5:286:8 | Unit | exprs.kt:279:1:294:1 | unaryExprs | TypeAccess |
1762+
| exprs.kt:286:5:286:8 | inc(...) | exprs.kt:279:1:294:1 | unaryExprs | MethodAccess |
1763+
| exprs.kt:286:5:286:8 | tmp0 | exprs.kt:279:1:294:1 | unaryExprs | LocalVariableDeclExpr |
1764+
| exprs.kt:286:5:286:8 | tmp0 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
1765+
| exprs.kt:286:5:286:8 | tmp0 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
1766+
| exprs.kt:287:5:287:8 | <Stmt> | exprs.kt:279:1:294:1 | unaryExprs | StmtExpr |
1767+
| exprs.kt:287:5:287:8 | <implicit coercion to unit> | exprs.kt:279:1:294:1 | unaryExprs | ImplicitCoercionToUnitExpr |
1768+
| exprs.kt:287:5:287:8 | Unit | exprs.kt:279:1:294:1 | unaryExprs | TypeAccess |
1769+
| exprs.kt:287:5:287:8 | inc(...) | exprs.kt:279:1:294:1 | unaryExprs | MethodAccess |
1770+
| exprs.kt:287:7:287:8 | ...=... | exprs.kt:279:1:294:1 | unaryExprs | AssignExpr |
1771+
| exprs.kt:287:7:287:8 | i0 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
1772+
| exprs.kt:287:7:287:8 | i0 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
1773+
| exprs.kt:287:7:287:8 | i0 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
1774+
| exprs.kt:288:5:288:6 | i0 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
1775+
| exprs.kt:288:5:288:6 | i0 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
1776+
| exprs.kt:288:5:288:8 | ...=... | exprs.kt:279:1:294:1 | unaryExprs | AssignExpr |
1777+
| exprs.kt:288:5:288:8 | <Stmt> | exprs.kt:279:1:294:1 | unaryExprs | StmtExpr |
1778+
| exprs.kt:288:5:288:8 | <implicit coercion to unit> | exprs.kt:279:1:294:1 | unaryExprs | ImplicitCoercionToUnitExpr |
1779+
| exprs.kt:288:5:288:8 | Unit | exprs.kt:279:1:294:1 | unaryExprs | TypeAccess |
1780+
| exprs.kt:288:5:288:8 | dec(...) | exprs.kt:279:1:294:1 | unaryExprs | MethodAccess |
1781+
| exprs.kt:288:5:288:8 | tmp1 | exprs.kt:279:1:294:1 | unaryExprs | LocalVariableDeclExpr |
1782+
| exprs.kt:288:5:288:8 | tmp1 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
1783+
| exprs.kt:288:5:288:8 | tmp1 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
1784+
| exprs.kt:289:5:289:8 | <Stmt> | exprs.kt:279:1:294:1 | unaryExprs | StmtExpr |
1785+
| exprs.kt:289:5:289:8 | <implicit coercion to unit> | exprs.kt:279:1:294:1 | unaryExprs | ImplicitCoercionToUnitExpr |
1786+
| exprs.kt:289:5:289:8 | Unit | exprs.kt:279:1:294:1 | unaryExprs | TypeAccess |
1787+
| exprs.kt:289:5:289:8 | dec(...) | exprs.kt:279:1:294:1 | unaryExprs | MethodAccess |
1788+
| exprs.kt:289:7:289:8 | ...=... | exprs.kt:279:1:294:1 | unaryExprs | AssignExpr |
1789+
| exprs.kt:289:7:289:8 | i0 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
1790+
| exprs.kt:289:7:289:8 | i0 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
1791+
| exprs.kt:289:7:289:8 | i0 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
1792+
| exprs.kt:290:5:290:6 | i0 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
1793+
| exprs.kt:290:8:290:12 | <implicit coercion to unit> | exprs.kt:279:1:294:1 | unaryExprs | ImplicitCoercionToUnitExpr |
1794+
| exprs.kt:290:8:290:12 | Unit | exprs.kt:279:1:294:1 | unaryExprs | TypeAccess |
1795+
| exprs.kt:290:8:290:12 | inc(...) | exprs.kt:279:1:294:1 | unaryExprs | MethodAccess |
1796+
| exprs.kt:291:5:291:6 | i0 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
1797+
| exprs.kt:291:8:291:12 | <implicit coercion to unit> | exprs.kt:279:1:294:1 | unaryExprs | ImplicitCoercionToUnitExpr |
1798+
| exprs.kt:291:8:291:12 | Unit | exprs.kt:279:1:294:1 | unaryExprs | TypeAccess |
1799+
| exprs.kt:291:8:291:12 | dec(...) | exprs.kt:279:1:294:1 | unaryExprs | MethodAccess |
1800+
| exprs.kt:292:5:292:6 | i1 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
1801+
| exprs.kt:292:8:292:12 | <implicit coercion to unit> | exprs.kt:279:1:294:1 | unaryExprs | ImplicitCoercionToUnitExpr |
1802+
| exprs.kt:292:8:292:12 | Unit | exprs.kt:279:1:294:1 | unaryExprs | TypeAccess |
1803+
| exprs.kt:292:8:292:12 | inc(...) | exprs.kt:279:1:294:1 | unaryExprs | MethodAccess |
1804+
| exprs.kt:293:5:293:6 | i1 | exprs.kt:279:1:294:1 | unaryExprs | VarAccess |
1805+
| exprs.kt:293:8:293:12 | <implicit coercion to unit> | exprs.kt:279:1:294:1 | unaryExprs | ImplicitCoercionToUnitExpr |
1806+
| exprs.kt:293:8:293:12 | Unit | exprs.kt:279:1:294:1 | unaryExprs | TypeAccess |
1807+
| exprs.kt:293:8:293:12 | dec(...) | exprs.kt:279:1:294:1 | unaryExprs | MethodAccess |
17411808
| funcExprs.kt:1:1:1:46 | Unit | file://:0:0:0:0 | <none> | TypeAccess |
17421809
| funcExprs.kt:1:26:1:37 | Function0<Integer> | file://:0:0:0:0 | <none> | TypeAccess |
17431810
| funcExprs.kt:1:26:1:37 | Integer | file://:0:0:0:0 | <none> | TypeAccess |

java/ql/test/kotlin/library-tests/exprs/exprs.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,20 @@ fun callToEnumValues() {
275275
enumValues<Color>()
276276
getEnumValues<Color>()
277277
}
278+
279+
fun unaryExprs(i: Int, d: Double) {
280+
-i
281+
+i
282+
-d
283+
+d
284+
var i0 = 1
285+
val i1 = 1
286+
i0++
287+
++i0
288+
i0--
289+
--i0
290+
i0.inc()
291+
i0.dec()
292+
i1.inc()
293+
i1.dec()
294+
}

0 commit comments

Comments
 (0)