{"action":"created","issue":{"url":"https://api.github.com/repos/micropython/micropython/issues/1104","labels_url":"https://api.github.com/repos/micropython/micropython/issues/1104/labels{/name}","comments_url":"https://api.github.com/repos/micropython/micropython/issues/1104/comments","events_url":"https://api.github.com/repos/micropython/micropython/issues/1104/events","html_url":"https://github.com/micropython/micropython/issues/1104","id":56906543,"number":1104,"title":"Confusing line number reporting for exceptions in loops","user":{"login":"pfalcon","id":500451,"avatar_url":"https://avatars.githubusercontent.com/u/500451?v=3","gravatar_id":"","url":"https://api.github.com/users/pfalcon","html_url":"https://github.com/pfalcon","followers_url":"https://api.github.com/users/pfalcon/followers","following_url":"https://api.github.com/users/pfalcon/following{/other_user}","gists_url":"https://api.github.com/users/pfalcon/gists{/gist_id}","starred_url":"https://api.github.com/users/pfalcon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pfalcon/subscriptions","organizations_url":"https://api.github.com/users/pfalcon/orgs","repos_url":"https://api.github.com/users/pfalcon/repos","events_url":"https://api.github.com/users/pfalcon/events{/privacy}","received_events_url":"https://api.github.com/users/pfalcon/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/micropython/micropython/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-02-07T10:31:40Z","updated_at":"2015-02-15T13:51:10Z","closed_at":null,"body":"Testcase:\r\n\r\n~~~~\r\nl = [\"-foo\", \"-bar\"]\r\n\r\ni = 0\r\nwhile l[i][0] == \"-\":\r\n    print(\"iter\")\r\n    i += 1\r\n~~~~\r\n\r\nSo, error happens in line 4, however uPy backtrace:\r\n\r\n~~~~\r\n$ micropython test.py \r\niter\r\niter\r\nTraceback (most recent call last):\r\n  File \"test.py\", line 6, in <module>\r\nIndexError: list index out of range\r\n~~~~\r\n\r\nIn real-world use, the loop body is much bigger, and line number refers not to last statement in loop body, but to statement after the loop, which makes it even more confusing.\r\n"},"comment":{"url":"https://api.github.com/repos/micropython/micropython/issues/comments/74418140","html_url":"https://github.com/micropython/micropython/issues/1104#issuecomment-74418140","issue_url":"https://api.github.com/repos/micropython/micropython/issues/1104","id":74418140,"user":{"login":"dpgeorge","id":6187689,"avatar_url":"https://avatars.githubusercontent.com/u/6187689?v=3","gravatar_id":"","url":"https://api.github.com/users/dpgeorge","html_url":"https://github.com/dpgeorge","followers_url":"https://api.github.com/users/dpgeorge/followers","following_url":"https://api.github.com/users/dpgeorge/following{/other_user}","gists_url":"https://api.github.com/users/dpgeorge/gists{/gist_id}","starred_url":"https://api.github.com/users/dpgeorge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dpgeorge/subscriptions","organizations_url":"https://api.github.com/users/dpgeorge/orgs","repos_url":"https://api.github.com/users/dpgeorge/repos","events_url":"https://api.github.com/users/dpgeorge/events{/privacy}","received_events_url":"https://api.github.com/users/dpgeorge/received_events","type":"User","site_admin":false},"created_at":"2015-02-15T13:51:10Z","updated_at":"2015-02-15T13:51:10Z","body":"Problem comes about because of the following 2 facts:\r\n1. While loops are optimised in the standard way by putting the condition test after the body (eliminates an unconditional jump).\r\n2. Line number encoding assumes a monotonic map between bytecode offset and line number.\r\n\r\nTo fix this issue we need to change one of the above."}}