I seem to have found some kind of bug in the JVM bytecode generator.
Here's a class that reproduces the issue if I run it:
class TestBug
{
**
** Split a string in the format hostname:port into
** its parts and pass them to the given closure.
**
** Typically that closure will store them into
** local variables for later use in the calling
** method.
**
static Bool splitHostPort(Str hostname, |Str,Int| func)
{
parts := hostname.split(':')
if(parts.size > 1)
{
port := Int.fromStr(parts.removeAt(-1))
hostname = parts.join(":")
func(hostname, port)
return true
}
return false
}
new make(Str host)
{
Int port := 0
Str hostname := host
if(splitHostPort(host, |h,p|{port = p ; hostname = h}))
{
echo("Yay")
}
}
static Void main()
{
t := TestBug("localhost:80")
echo("$t")
}
}
The error I get is:
java.lang.VerifyError: (class: fan/bug/TestBug, method: splitHostPort signature:
(Ljava/lang/String;Lfan/sys/Func;)Z) Expecting to find long on stack
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2308)
at java.lang.Class.getDeclaredFields(Class.java:1760)
at fan.sys.ClassType.finishSlots(ClassType.java:588)
at fan.sys.ClassType.finish(ClassType.java:550)
at fan.sys.Method$MethodFunc.isStatic(Method.java:475)
at fan.sys.Method$MethodFunc.callList(Method.java:191)
at fan.sys.Method.callList(Method.java:138)
at fanx.tools.Fan.callMain(Fan.java:173)
at fanx.tools.Fan.executeType(Fan.java:140)
at fanx.tools.Fan.execute(Fan.java:41)
at fanx.tools.Fan.run(Fan.java:298)
at fanx.tools.Fan.main(Fan.java:336)
sys::Err: Method not mapped to java.lang.reflect correctly bug::TestBug.main
fan.sys.Method$MethodFunc.isStatic (Method.java:482)
fan.sys.Method$MethodFunc.callList (Method.java:191)
fan.sys.Method.callList (Method.java:138)
fanx.tools.Fan.callMain (Fan.java:173)
fanx.tools.Fan.executeType (Fan.java:140)
fanx.tools.Fan.execute (Fan.java:41)
fanx.tools.Fan.run (Fan.java:298)
fanx.tools.Fan.main (Fan.java:336)
dobesvSun 18 Mar 2012
Workaround: if I use Str.toInt() instead of Int.fromStr() then it works.
i.e.:
port := parts.removeAt(-1).toInt(10, true)
brianMon 19 Mar 2012
What version of Fantom and JRE are you running? Because that program works in my environment (which would be unusual for verification bug).
Can anyone else reproduce that?
KevinKelleyMon 19 Mar 2012
Can't reproduce here... fan.version 1.0.62, java version "1.6.0_26" (x64)
dobesvTue 20 Mar 2012
Hmmm on further investigation the error only shows up if the code is compiled and run from the F4 IDE. If I run it from the command line I cannot reproduce the problem either, how peculiar.
There must be something the F4 IDE is doing differently when it runs Fantom but I can't quite tell what that is.
SlimerDudeTue 20 Mar 2012
F4 (unless you've configured it differently) uses an older Fantom 1.0.60.
dobesvTue 20 Mar 2012
Well I did configure it to use my latest installation of Fantom but maybe internally it is still using that older 1.0.60 to compile.
dobesv Sun 18 Mar 2012
I seem to have found some kind of bug in the JVM bytecode generator.
Here's a class that reproduces the issue if I run it:
The error I get is:
dobesv Sun 18 Mar 2012
Workaround: if I use Str.toInt() instead of Int.fromStr() then it works.
i.e.:
brian Mon 19 Mar 2012
What version of Fantom and JRE are you running? Because that program works in my environment (which would be unusual for verification bug).
Can anyone else reproduce that?
KevinKelley Mon 19 Mar 2012
Can't reproduce here... fan.version 1.0.62, java version "1.6.0_26" (x64)
dobesv Tue 20 Mar 2012
Hmmm on further investigation the error only shows up if the code is compiled and run from the F4 IDE. If I run it from the command line I cannot reproduce the problem either, how peculiar.
There must be something the F4 IDE is doing differently when it runs Fantom but I can't quite tell what that is.
SlimerDude Tue 20 Mar 2012
F4 (unless you've configured it differently) uses an older Fantom 1.0.60.
dobesv Tue 20 Mar 2012
Well I did configure it to use my latest installation of Fantom but maybe internally it is still using that older 1.0.60 to compile.