From 608f99bd0d7bb36f2a26261b4b981aee9c492e46 Mon Sep 17 00:00:00 2001 From: Tamas Vajk Date: Mon, 5 Sep 2022 10:05:08 +0200 Subject: [PATCH] Kotlin: Add test case for various array `set` operator overloads --- .../operator-overloads/PrintAst.expected | 68 ++++++++++++++----- .../operator-overloads/test.expected | 2 + .../library-tests/operator-overloads/test.kt | 5 ++ 3 files changed, 57 insertions(+), 18 deletions(-) diff --git a/java/ql/test/kotlin/library-tests/operator-overloads/PrintAst.expected b/java/ql/test/kotlin/library-tests/operator-overloads/PrintAst.expected index 4664710cd04..8bcfc4ec183 100644 --- a/java/ql/test/kotlin/library-tests/operator-overloads/PrintAst.expected +++ b/java/ql/test/kotlin/library-tests/operator-overloads/PrintAst.expected @@ -30,30 +30,62 @@ test.kt: # 4| -1: [VarAccess] mt # 4| 0: [IntegerLiteral] 1 # 4| 1: [IntegerLiteral] 2 -# 7| 2: [ExtensionMethod] get -# 7| 3: [TypeAccess] String +# 6| 3: [ExprStmt] ; +# 6| 0: [ImplicitCoercionToUnitExpr] +# 6| 0: [TypeAccess] Unit +# 7| 4: [ExprStmt] ; +# 7| 0: [ImplicitCoercionToUnitExpr] +# 7| 0: [TypeAccess] Unit +# 10| 2: [ExtensionMethod] get +# 10| 3: [TypeAccess] String #-----| 4: (Parameters) -# 7| 0: [Parameter] -# 7| 0: [TypeAccess] byte[] -# 7| 1: [Parameter] i -# 7| 0: [TypeAccess] int -# 7| 2: [Parameter] j -# 7| 0: [TypeAccess] int -# 7| 5: [BlockStmt] { ... } -# 7| 0: [ReturnStmt] return ... -# 7| 0: [StringLiteral] -# 10| 2: [Class] C -# 10| 1: [Constructor] C +# 10| 0: [Parameter] +# 10| 0: [TypeAccess] byte[] +# 10| 1: [Parameter] i +# 10| 0: [TypeAccess] int +# 10| 2: [Parameter] j +# 10| 0: [TypeAccess] int # 10| 5: [BlockStmt] { ... } -# 10| 0: [SuperConstructorInvocationStmt] super(...) -# 10| 1: [BlockStmt] { ... } -# 11| 2: [Method] get +# 10| 0: [ReturnStmt] return ... +# 10| 0: [StringLiteral] +# 11| 3: [ExtensionMethod] set # 11| 3: [TypeAccess] String #-----| 4: (Parameters) -# 11| 0: [Parameter] i +# 11| 0: [Parameter] +# 11| 0: [TypeAccess] byte[] +# 11| 1: [Parameter] i # 11| 0: [TypeAccess] int -# 11| 1: [Parameter] j +# 11| 2: [Parameter] j +# 11| 0: [TypeAccess] int +# 11| 3: [Parameter] k # 11| 0: [TypeAccess] int # 11| 5: [BlockStmt] { ... } # 11| 0: [ReturnStmt] return ... # 11| 0: [StringLiteral] +# 12| 4: [ExtensionMethod] set +# 12| 3: [TypeAccess] String +#-----| 4: (Parameters) +# 12| 0: [Parameter] +# 12| 0: [TypeAccess] byte[] +# 12| 1: [Parameter] i +# 12| 0: [TypeAccess] int +# 12| 2: [Parameter] c +# 12| 0: [TypeAccess] C +# 12| 5: [BlockStmt] { ... } +# 12| 0: [ReturnStmt] return ... +# 12| 0: [StringLiteral] +# 15| 2: [Class] C +# 15| 1: [Constructor] C +# 15| 5: [BlockStmt] { ... } +# 15| 0: [SuperConstructorInvocationStmt] super(...) +# 15| 1: [BlockStmt] { ... } +# 16| 2: [Method] get +# 16| 3: [TypeAccess] String +#-----| 4: (Parameters) +# 16| 0: [Parameter] i +# 16| 0: [TypeAccess] int +# 16| 1: [Parameter] j +# 16| 0: [TypeAccess] int +# 16| 5: [BlockStmt] { ... } +# 16| 0: [ReturnStmt] return ... +# 16| 0: [StringLiteral] diff --git a/java/ql/test/kotlin/library-tests/operator-overloads/test.expected b/java/ql/test/kotlin/library-tests/operator-overloads/test.expected index e69de29bb2d..afe544b0e6e 100644 --- a/java/ql/test/kotlin/library-tests/operator-overloads/test.expected +++ b/java/ql/test/kotlin/library-tests/operator-overloads/test.expected @@ -0,0 +1,2 @@ +| test.kt:6:5:6:13 | Unexpected Array.set function signature | +| test.kt:7:5:7:10 | Unexpected Array.set function signature | diff --git a/java/ql/test/kotlin/library-tests/operator-overloads/test.kt b/java/ql/test/kotlin/library-tests/operator-overloads/test.kt index 950b0914fe0..d332c995148 100644 --- a/java/ql/test/kotlin/library-tests/operator-overloads/test.kt +++ b/java/ql/test/kotlin/library-tests/operator-overloads/test.kt @@ -2,9 +2,14 @@ fun fn(arr: ByteArray, mt: C) { arr[1] arr[1, 2] mt[1, 2] + + arr[1, 2] = 3 + arr[1] = C() } public operator fun ByteArray.get(i: Int, j: Int) = "" +public operator fun ByteArray.set(i: Int, j: Int, k: Int) = "" +public operator fun ByteArray.set(i: Int, c: C) = "" public class C {