{"action":"created","issue":{"url":"https://api.github.com/repos/ghcjs/ghcjs/issues/307","labels_url":"https://api.github.com/repos/ghcjs/ghcjs/issues/307/labels{/name}","comments_url":"https://api.github.com/repos/ghcjs/ghcjs/issues/307/comments","events_url":"https://api.github.com/repos/ghcjs/ghcjs/issues/307/events","html_url":"https://github.com/ghcjs/ghcjs/issues/307","id":58441918,"number":307,"title":"FFI passes unevaluated thunk to JavaScript","user":{"login":"ryantrinkle","id":1156448,"avatar_url":"https://avatars.githubusercontent.com/u/1156448?v=3","gravatar_id":"","url":"https://api.github.com/users/ryantrinkle","html_url":"https://github.com/ryantrinkle","followers_url":"https://api.github.com/users/ryantrinkle/followers","following_url":"https://api.github.com/users/ryantrinkle/following{/other_user}","gists_url":"https://api.github.com/users/ryantrinkle/gists{/gist_id}","starred_url":"https://api.github.com/users/ryantrinkle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ryantrinkle/subscriptions","organizations_url":"https://api.github.com/users/ryantrinkle/orgs","repos_url":"https://api.github.com/users/ryantrinkle/repos","events_url":"https://api.github.com/users/ryantrinkle/events{/privacy}","received_events_url":"https://api.github.com/users/ryantrinkle/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-02-21T04:27:18Z","updated_at":"2015-08-18T10:49:58Z","closed_at":"2015-06-18T22:55:26Z","body":"The following program should produce 3 checkboxes: `[ ]  [X]  [ ]`.  It does this correctly under GHC and under GHCJS with -O1 or -O2.  However, under GHCJS with -O0, it produces `[ ] [X] [X]`.  This appears to be due to an unevaluated thunk being passed into JavaScript via htmlInputElementSetChecked.  Since the thunk is an object, it is \"truthy\" in JavaScript.\r\n\r\n```haskell\r\nimport GHCJS.DOM\r\nimport GHCJS.DOM.Element\r\nimport GHCJS.DOM.Document\r\nimport GHCJS.DOM.HTMLInputElement\r\nimport GHCJS.DOM.Node\r\nimport GHCJS.DOM.Types hiding (Event)\r\n\r\nmain :: IO ()\r\nmain = runWebGUI $ \\webView -> do\r\n  Just doc <- fmap (fmap castToHTMLDocument) $ webViewGetDomDocument webView\r\n  Just body <- documentGetBody doc\r\n  let testCheckbox x = do\r\n        Just e <- fmap (fmap castToHTMLInputElement) $ documentCreateElement doc \"input\"\r\n        elementSetAttribute e \"type\" \"checkbox\"\r\n        htmlInputElementSetChecked e x\r\n        _ <- nodeAppendChild body $ Just e\r\n        return ()\r\n  testCheckbox False\r\n  testCheckbox True\r\n  testCheckbox $ id False\r\n```"},"comment":{"url":"https://api.github.com/repos/ghcjs/ghcjs/issues/comments/132170118","html_url":"https://github.com/ghcjs/ghcjs/issues/307#issuecomment-132170118","issue_url":"https://api.github.com/repos/ghcjs/ghcjs/issues/307","id":132170118,"user":{"login":"quyse","id":416215,"avatar_url":"https://avatars.githubusercontent.com/u/416215?v=3","gravatar_id":"","url":"https://api.github.com/users/quyse","html_url":"https://github.com/quyse","followers_url":"https://api.github.com/users/quyse/followers","following_url":"https://api.github.com/users/quyse/following{/other_user}","gists_url":"https://api.github.com/users/quyse/gists{/gist_id}","starred_url":"https://api.github.com/users/quyse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quyse/subscriptions","organizations_url":"https://api.github.com/users/quyse/orgs","repos_url":"https://api.github.com/users/quyse/repos","events_url":"https://api.github.com/users/quyse/events{/privacy}","received_events_url":"https://api.github.com/users/quyse/received_events","type":"User","site_admin":false},"created_at":"2015-08-18T10:49:58Z","updated_at":"2015-08-18T10:49:58Z","body":"I think I just hit this. Unfortunately it's a lot of code, I tried to extract small code snippet for repro, with no luck. So, here is the [code file](https://github.com/quyse/flaw/blob/a4e3b5bb7c3d65c59f63fd77f447a205faa93826/flaw-webgl/Flaw/Graphics/WebGL.hs), and the chunk in the end of `webglUpdateContext` function:\r\n\r\n```Haskell\r\nlet normalized n = case n of\r\n\tNonNormalized -> False\r\n\tNormalized -> True\r\nlet stn q = case q of\r\n\tATFloat32 -> (1, webgl_FLOAT, False)\r\n\tATInt32 n -> (1, webgl_INT, normalized n)\r\n\tATInt16 n -> (1, webgl_SHORT, normalized n)\r\n\tATInt8 n -> (1, webgl_BYTE, normalized n)\r\n\tATUint32 n -> (1, webgl_UNSIGNED_INT, normalized n)\r\n\tATUint16 n -> (1, webgl_UNSIGNED_SHORT, normalized n)\r\n\tATUint8 n -> (1, webgl_UNSIGNED_BYTE, normalized n)\r\n\tATVec1 a -> let (_, t, n) = stn a in (1, t, n)\r\n\tATVec2 a -> let (_, t, n) = stn a in (2, t, n)\r\n\tATVec3 a -> let (_, t, n) = stn a in (3, t, n)\r\n\tATVec4 a -> let (_, t, n) = stn a in (4, t, n)\r\n\t_ -> error $ show (\"wrong WebGL attribute type\", at)\r\nlet (aSize, aType, aNormalized) = stn at\r\njs_vertexAttribPointer jsContext i aSize aType aNormalized stride offset\r\n```\r\nHere `aNormalized` is a `Bool` variable, and canvas tracer in Firefox shows that it's an Object sent to `vertexAttribPointer`, which is interpreted as `true` and screws up rendering. If I change the last lines to this:\r\n```Haskell\r\nlet (aSize, aType, aNormalized) = stn at\r\nnnn <- evaluate aNormalized\r\njs_vertexAttribPointer jsContext i aSize aType nnn stride offset\r\n```\r\nit works as intended, and tracer correctly shows `false`.\r\nI'm on latest improved-base e7b3b0099258d0739e46b1dcefb2d2793dbbc8fd. Optimization level is -O2.\r\nMaybe you can get something from this. I'll try to make a small reproducible case."}}