Skip to content

Commit

Permalink
Bug with local variables creation #165
Browse files Browse the repository at this point in the history
  • Loading branch information
lehvolk committed Sep 5, 2023
1 parent ad73140 commit 78c395c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ package org.jacodb.testing.cfg
import org.jacodb.api.ext.findClass
import org.jacodb.testing.WithDB
import org.jacodb.testing.ir.DoubleComparison
import org.jacodb.testing.ir.InvokeMethodWithException
import org.jacodb.testing.ir.WhenExpr
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class ReverseIRTest : BaseInstructionsTest() {
Expand All @@ -30,13 +31,21 @@ class ReverseIRTest : BaseInstructionsTest() {
fun comparison() {
val clazz = testAndLoadClass(cp.findClass<DoubleComparison>())
val m = clazz.declaredMethods.first { it.name == "box" }
Assertions.assertEquals("OK", m.invoke(null))
assertEquals("OK", m.invoke(null))
}

@Test
fun `when`() {
val clazz = testAndLoadClass(cp.findClass<WhenExpr>())
val m = clazz.declaredMethods.first { it.name == "box" }
Assertions.assertEquals("OK", m.invoke(null))
assertEquals("OK", m.invoke(null))
}

@Test
fun `local vars`() {
val clazz = testAndLoadClass(cp.findClass<InvokeMethodWithException>())
val m = clazz.declaredMethods.first { it.name == "box" }
assertEquals("OK", m.invoke(null))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,28 @@ object WhenExpr {
else -> "Fail: $y"
}

}

object InvokeMethodWithException {

class A {
fun lol(a: Int): Int {
return 888/a
}
}

@JvmStatic
fun box():String {
val method = A::class.java.getMethod("lol", Int::class.java)
var failed = false
try {
method.invoke(null, 0)
}
catch(e: Exception) {
failed = true
}

return if (!failed) "fail" else "OK"
}

}

0 comments on commit 78c395c

Please sign in to comment.