Open danissimo opened 1 month ago
String concat is handled in the backend. Variants that induce Uncurry to lift the try will work.
Other superficially similar ops such as * 2
will work.
Welcome to Scala 2.13.14 (OpenJDK 64-Bit Server VM, Java 21.0.2).
Type in expressions for evaluation. Or try :help.
scala> def f() = (try "try" catch { case _: Throwable => "catch" }).toString + "nope"
java.lang.VerifyError: Inconsistent stackmap frames at branch target 20
Exception Details:
Location:
f()Ljava/lang/String; @17: goto
Reason:
Current frame's stack size doesn't match stackmap.
Current Frame:
bci: @17
flags: { }
locals: { '$iw' }
stack: { 'java/lang/String' }
Stackmap Frame:
bci: @20
flags: { }
locals: { '$iw' }
stack: { 'java/lang/Object', 'java/lang/String' }
Bytecode:
0000000: bb00 1259 1213 b700 1712 19a7 0009 5712
0000010: 1ba7 0003 b600 20b6 0024 1226 b600 24b6
0000020: 0027 b0
Exception Handler Table:
bci [9, 11] => handler: 14
Stackmap Table:
same_locals_1_stack_item_frame(@14,Object[#16])
full_frame(@20,{Object[#2]},{Object[#4],Object[#29]})
... 29 elided
scala>
just for fun
scala> object X { def f() = (try "try" catch (_ => "catch")).toString + "nope" }
-- [E008] Not Found Error: ---------------------------------------------------------------------------------------------
1 |object X { def f() = (try "try" catch (_ => "catch")).toString + "nope" }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| value toString is not a member of ?{ toString: ? }, but could be made available as an extension method.
|
| The following import might fix the problem:
|
| import scala.reflect.Selectable.reflectiveSelectable
|
1 error found
I guess we could fix this by backporting https://github.com/scala/scala3/pull/18619
Reproduction steps
Java: Oracle HotSpot 17.0.6+9-LTS-190, OpenJDK Temurin-17.0.8+7. Scala versions: 2.13.10, 2.13.14.
I faced the behaviour using spray json ("io.spray" %% "spray-json" % "1.3.6"), and I couldn't minimise the snippet to clean scala, but the hint to the nature of the bug is the two workarounds at the bottom of this report.
Problem
It gets compiled successfully, but when I run I get
But it goes away when I rewrite the source code as
or even when I drop the last addition of the "\n" string:
The both snippets above yield
with and without the last newline respectively.