{"action":"closed","issue":{"url":"https://api.github.com/repos/ghcjs/ghcjs/issues/380","labels_url":"https://api.github.com/repos/ghcjs/ghcjs/issues/380/labels{/name}","comments_url":"https://api.github.com/repos/ghcjs/ghcjs/issues/380/comments","events_url":"https://api.github.com/repos/ghcjs/ghcjs/issues/380/events","html_url":"https://github.com/ghcjs/ghcjs/issues/380","id":98586858,"number":380,"title":"panic! (the 'impossible' happened) in splitTyConApp a1_a2IY","user":{"login":"wuzzeb","id":461189,"avatar_url":"https://avatars.githubusercontent.com/u/461189?v=3","gravatar_id":"","url":"https://api.github.com/users/wuzzeb","html_url":"https://github.com/wuzzeb","followers_url":"https://api.github.com/users/wuzzeb/followers","following_url":"https://api.github.com/users/wuzzeb/following{/other_user}","gists_url":"https://api.github.com/users/wuzzeb/gists{/gist_id}","starred_url":"https://api.github.com/users/wuzzeb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wuzzeb/subscriptions","organizations_url":"https://api.github.com/users/wuzzeb/orgs","repos_url":"https://api.github.com/users/wuzzeb/repos","events_url":"https://api.github.com/users/wuzzeb/events{/privacy}","received_events_url":"https://api.github.com/users/wuzzeb/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-08-02T05:44:48Z","updated_at":"2015-08-31T05:25:05Z","closed_at":"2015-08-31T05:25:05Z","body":"I'm using the released GHC 7.10.2 and the improved-base branch of ghcjs (using the following commands)\r\n\r\n```\r\n$ git clone https://github.com/ghcjs/ghcjs.git\r\n$ cd ghcjs\r\n$ git checkout improved-base\r\n$ cabal install\r\n$ ghcjs-boot --dev --ghcjs-boot-dev-branch improved-base --shims-dev-branch improved-base\r\n```\r\n\r\nI was then writing some code trying to decode an Export inside a callback, and when compiling with cabal received\r\n\r\n```\r\n<no location info>:\r\n    ghcjs-0.1.0-7.10.2.bin: panic! (the 'impossible' happened)\r\n  (GHC version 7.10.2 for x86_64-unknown-linux):\r\n\tsplitTyConApp a1_i8KE\r\n```\r\n\r\nI eventually reduced it to this small test case:\r\n\r\n```\r\nmodule A where\r\n\r\nimport Data.Typeable (Typeable)\r\nimport GHCJS.Types (JSRef)\r\nimport GHCJS.Foreign.Export (Export, derefExport)\r\nimport GHCJS.Foreign.Callback\r\n\r\nnewtype Foo a = Foo (JSRef ())\r\nnewtype Bar = Bar (JSRef ())\r\n\r\nbaz :: Typeable a => (a -> Bar) -> IO (Foo a)\r\nbaz f = do\r\n    cb <- syncCallback1 ThrowWouldBlock $ \\argRef -> do\r\n        let arg = CbArgs argRef\r\n\r\n        aExport <- js_CbGetA arg\r\n        ma <- derefExport aExport\r\n        a <- maybe (error \"Hello world\") return ma\r\n\r\n        let bar = f a\r\n\r\n        js_SetBar arg bar\r\n\r\n    js_SetCb cb\r\n\r\nnewtype CbArgs = CbArgs (JSRef ())\r\n\r\nforeign import javascript unsafe\r\n    \"$1.aaa\"\r\n    js_CbGetA :: CbArgs -> IO (Export a)\r\n\r\nforeign import javascript unsafe\r\n    \"$1.bar = $2\"\r\n    js_SetBar :: CbArgs -> Bar ->  IO ()\r\n\r\n-- | Create a class with no state.\r\nforeign import javascript unsafe\r\n    \"null\"\r\n    js_SetCb :: Callback (JSRef () -> IO ()) -> IO (Foo a)\r\n```\r\n\r\nWhen just running `ghcjs A.hs`, there is no error.  But when running `ghcjs -O A.hs`, the panic occurs.  Since cabal defaults to using `-O`, it panics.  So it is something with optimization.  But it also seems to be releated to the foreign import javascript.  If I comment out the `js_CbGetA` function and replace it with\r\n\r\n```\r\njs_CbGetA :: CbArgs -> IO (Export a)\r\njs_CbGetA = undefined\r\n```\r\n\r\nI can compile without a panic.\r\n\r\nFor reference, I am using 7a718363ee1584e9ae43b49679b560099df79f86 of ghcjs repo and 7d4dac56cd338d0a37de4558d77c90b4f7c854f4 of ghcjs-base repo"}}