{"action":"created","issue":{"url":"https://api.github.com/repos/opal/opal/issues/761","labels_url":"https://api.github.com/repos/opal/opal/issues/761/labels{/name}","comments_url":"https://api.github.com/repos/opal/opal/issues/761/comments","events_url":"https://api.github.com/repos/opal/opal/issues/761/events","html_url":"https://github.com/opal/opal/issues/761","id":62552333,"number":761,"title":"BUG in while loop (perhaps more)","user":{"login":"catmando","id":63146,"avatar_url":"https://avatars.githubusercontent.com/u/63146?v=3","gravatar_id":"","url":"https://api.github.com/users/catmando","html_url":"https://github.com/catmando","followers_url":"https://api.github.com/users/catmando/followers","following_url":"https://api.github.com/users/catmando/following{/other_user}","gists_url":"https://api.github.com/users/catmando/gists{/gist_id}","starred_url":"https://api.github.com/users/catmando/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/catmando/subscriptions","organizations_url":"https://api.github.com/users/catmando/orgs","repos_url":"https://api.github.com/users/catmando/repos","events_url":"https://api.github.com/users/catmando/events{/privacy}","received_events_url":"https://api.github.com/users/catmando/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-03-18T00:47:56Z","updated_at":"2015-03-18T12:51:49Z","closed_at":null,"body":"Just discovered this... looks like if you drop off the end of a method, and the last statement was a while, it returns javascript undefined.  \r\n\r\nHere is a simple test that runs in opal-rspec\r\n\r\n    class Test\r\n        \r\n        def busted_while(x, y)\r\n          while x < 10\r\n            return true if x==y\r\n            x += 1\r\n          end\r\n        end\r\n        \r\n      end\r\n      \r\n      describe \"a busted while loop 1\" do\r\n        it \"works if returning explicitly\" do\r\n          expect(Test.new.busted_while(7, 8)).to be_truthy\r\n        end\r\n        it \"fails if there is no explicit return\" do\r\n          result = Test.new.busted_while(7, 5)\r\n          expect(!result).to be_truthy\r\n        end\r\n      end\r\n\r\nThe second test bombs with \"Cannot read property '$!' of undefined\"\r\n\r\nit you put any statement between the end of the while, and the end of the method all will be fine."},"comment":{"url":"https://api.github.com/repos/opal/opal/issues/comments/82955465","html_url":"https://github.com/opal/opal/issues/761#issuecomment-82955465","issue_url":"https://api.github.com/repos/opal/opal/issues/761","id":82955465,"user":{"login":"adambeynon","id":68938,"avatar_url":"https://avatars.githubusercontent.com/u/68938?v=3","gravatar_id":"","url":"https://api.github.com/users/adambeynon","html_url":"https://github.com/adambeynon","followers_url":"https://api.github.com/users/adambeynon/followers","following_url":"https://api.github.com/users/adambeynon/following{/other_user}","gists_url":"https://api.github.com/users/adambeynon/gists{/gist_id}","starred_url":"https://api.github.com/users/adambeynon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adambeynon/subscriptions","organizations_url":"https://api.github.com/users/adambeynon/orgs","repos_url":"https://api.github.com/users/adambeynon/repos","events_url":"https://api.github.com/users/adambeynon/events{/privacy}","received_events_url":"https://api.github.com/users/adambeynon/received_events","type":"User","site_admin":false},"created_at":"2015-03-18T12:51:49Z","updated_at":"2015-03-18T12:51:49Z","body":"@vais The compiler has a returns method:\r\n\r\nhttps://github.com/opal/opal/blob/master/lib/opal/compiler.rb#L302\r\n\r\nThis examines special case nodes which need to be handled in a certain way. For example, it makes sure an if-else expression returns its true or false case if it needs to. For some reason, a while expression has its special case commented out:\r\n\r\nhttps://github.com/opal/opal/blob/master/lib/opal/compiler.rb#L346\r\n\r\nThis would ensure its value gets returned. Im not sure why it is commented out however, it must have been buggy at some point and never actually fixed. Its a bit of a mess the way it works, so I can take a look. A while expression might need some special extra work, Im not sure on the MRI semantics - does it return the last truth value, for example? Or always nil? (currently away from a laptop to test)."}}