bugfix: elvis + throw
This commit is contained in:
parent
95c1da60ed
commit
fb6e2aa49e
@ -203,6 +203,10 @@ class Compiler(
|
|||||||
val rvalue = parseExpressionLevel(level + 1)
|
val rvalue = parseExpressionLevel(level + 1)
|
||||||
?: throw ScriptError(opToken.pos, "Expecting expression")
|
?: throw ScriptError(opToken.pos, "Expecting expression")
|
||||||
|
|
||||||
|
if( op.tokenType == Token.Type.ELVIS) {
|
||||||
|
println("elvis!!")
|
||||||
|
}
|
||||||
|
|
||||||
lvalue = op.generate(opToken.pos, lvalue!!, rvalue)
|
lvalue = op.generate(opToken.pos, lvalue!!, rvalue)
|
||||||
}
|
}
|
||||||
return lvalue
|
return lvalue
|
||||||
@ -378,7 +382,9 @@ class Compiler(
|
|||||||
|
|
||||||
"throw" -> {
|
"throw" -> {
|
||||||
val s = parseThrowStatement()
|
val s = parseThrowStatement()
|
||||||
operand = Accessor { s.execute(it).asReadonly }
|
operand = Accessor {
|
||||||
|
s.execute(it).asReadonly
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> operand?.let { left ->
|
else -> operand?.let { left ->
|
||||||
@ -1973,7 +1979,15 @@ class Compiler(
|
|||||||
Operator.simple(Token.Type.IS, lastPriority) { _, a, b -> ObjBool(a.isInstanceOf(b)) },
|
Operator.simple(Token.Type.IS, lastPriority) { _, a, b -> ObjBool(a.isInstanceOf(b)) },
|
||||||
Operator.simple(Token.Type.NOTIS, lastPriority) { _, a, b -> ObjBool(!a.isInstanceOf(b)) },
|
Operator.simple(Token.Type.NOTIS, lastPriority) { _, a, b -> ObjBool(!a.isInstanceOf(b)) },
|
||||||
|
|
||||||
Operator.simple(Token.Type.ELVIS, ++lastPriority) { _, a, b -> if (a == ObjNull) b else a },
|
Operator(Token.Type.ELVIS, ++lastPriority, 2) { _: Pos, a: Accessor, b: Accessor ->
|
||||||
|
Accessor {
|
||||||
|
val aa = a.getter(it).value
|
||||||
|
(
|
||||||
|
if (aa != ObjNull) aa
|
||||||
|
else b.getter(it).value
|
||||||
|
).asReadonly
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
// shuttle <=> 6
|
// shuttle <=> 6
|
||||||
Operator.simple(Token.Type.SHUTTLE, ++lastPriority) { c, a, b ->
|
Operator.simple(Token.Type.SHUTTLE, ++lastPriority) { c, a, b ->
|
||||||
|
@ -2971,6 +2971,16 @@ class ScriptTest {
|
|||||||
""".trimIndent())
|
""".trimIndent())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testElvisAndThrow2() = runTest {
|
||||||
|
eval("""
|
||||||
|
val t = "112"
|
||||||
|
val x = t ?: run { throw "testx" }
|
||||||
|
}
|
||||||
|
assertEquals( "112", x)
|
||||||
|
""".trimIndent())
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testElvisAndRunThrow() = runTest {
|
fun testElvisAndRunThrow() = runTest {
|
||||||
eval("""
|
eval("""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user