Skip to content

Instantly share code, notes, and snippets.

@msgodf
Last active September 29, 2017 20:42
Show Gist options
  • Save msgodf/15d90ea62b86ef82c856bae56bd91445 to your computer and use it in GitHub Desktop.
Save msgodf/15d90ea62b86ef82c856bae56bd91445 to your computer and use it in GitHub Desktop.
Example of Eta code that gives `java.lang.VerifyError: Bad type on operand stack` error.
{-# LANGUAGE FlexibleContexts #-}
module Main where
import Java
import Java.Do
main :: IO ()
main = putStrLn $
mconcat $
fmap (\x -> let _ = x :: JInteger in show x) $
fromJava $
funApply2 (toJavaFun mkList) $ toJava (3 :: Int)
mkList :: JInteger -> (List JInteger)
mkList x = toJava [x]
foreign import java unsafe "@interface apply" funApply2 :: (Extends t Object, Extends r Object) => Function t r -> t -> r
@msgodf
Copy link
Author

msgodf commented Sep 29, 2017

This gives the following output:

Exception in thread "main" java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    main/Main$lvl3_sEQG.thunkEnter(Leta/runtime/stg/StgContext;)Leta/runtime/stg/Closure; @10: invokespecial
  Reason:
    Type 'java/lang/Object' (current frame, stack[2]) is not assignable to 'java/lang/Integer'
  Current Frame:
    bci: @10
    flags: { }
    locals: { 'main/Main$lvl3_sEQG', 'eta/runtime/stg/StgContext', 'java/lang/Object' }
    stack: { uninitialized 5, uninitialized 5, 'java/lang/Object' }
  Bytecode:
    0x0000000: 2ab4 0021 4dbb 0009 592c b700 294e bb00
    0x0000010: 0e59 2db8 002e b700 343a 042b 05b8 0037
    0x0000020: b600 3a2b 06b8 003e b600 3a2b 07b8 0041
    0x0000030: b600 3a2b 0819 04b6 003a b800 442b b600
    0x0000040: 473a 0519 05c0 0013 59b4 004a 3a06 57bb
    0x0000050: 0016 5919 06b7 004f 3a07 1907 b0

	at main.Main$main3.enter(Main.hs)
	at eta.runtime.apply.Function.applyP(Function.java:102)
	at eta.runtime.thunk.Ap2Upd.thunkEnter(Ap2Upd.java:18)
	at eta.runtime.thunk.UpdatableThunk.enter(UpdatableThunk.java:18)
	at eta.runtime.thunk.Thunk.applyO(Thunk.java:146)
	at base.java.TopHandler$runJava1.enter(TopHandler.hs)
	at base.java.TopHandler$runJava.enter(TopHandler.hs)
	at eta.runtime.apply.PAP.apply(PAP.java:31)
	at eta.runtime.apply.PAP.applyO(PAP.java:111)
	at eta.runtime.stg.Closures$EvalJava.enter(Closures.java:139)
	at eta.runtime.stg.Capability.schedule(Capability.java:153)
	at eta.runtime.stg.Capability.scheduleClosure(Capability.java:100)
	at eta.runtime.Runtime.evalJava(Runtime.java:201)
	at eta.java.util.function.Function$Eta.apply(Unknown Source)
	at main.Main$main2.thunkEnter(Main.hs)
	at eta.runtime.thunk.CAF.enter(CAF.java:31)
	at eta.runtime.stg.Closure.evaluate(Closure.java:24)
	at base.ghc.io.handle.Text$$wa7.enter(Text.hs)
	at base.ghc.io.handle.Text$hPutStr2.enter(Text.hs)
	at main.Main$main1.enter(Main.hs)
	at main.Main$DZCmain.enter(Main.hs)
	at eta.runtime.apply.Function.applyV(Function.java:16)
	at eta.runtime.stg.Closures$EvalLazyIO.enter(Closures.java:100)
	at eta.runtime.stg.Capability.schedule(Capability.java:153)
	at eta.runtime.stg.Capability.scheduleClosure(Capability.java:100)
	at eta.runtime.Runtime.evalLazyIO(Runtime.java:189)
	at eta.runtime.Runtime.main(Runtime.java:182)
	at eta.main.main(Unknown Source)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment