{"action":"created","issue":{"url":"https://api.github.com/repos/construct/construct/issues/266","repository_url":"https://api.github.com/repos/construct/construct","labels_url":"https://api.github.com/repos/construct/construct/issues/266/labels{/name}","comments_url":"https://api.github.com/repos/construct/construct/issues/266/comments","events_url":"https://api.github.com/repos/construct/construct/issues/266/events","html_url":"https://github.com/construct/construct/issues/266","id":187181304,"number":266,"title":"Referencing nested fields doesn't work when calculating size","user":{"login":"Schamper","id":1254028,"avatar_url":"https://avatars.githubusercontent.com/u/1254028?v=3","gravatar_id":"","url":"https://api.github.com/users/Schamper","html_url":"https://github.com/Schamper","followers_url":"https://api.github.com/users/Schamper/followers","following_url":"https://api.github.com/users/Schamper/following{/other_user}","gists_url":"https://api.github.com/users/Schamper/gists{/gist_id}","starred_url":"https://api.github.com/users/Schamper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Schamper/subscriptions","organizations_url":"https://api.github.com/users/Schamper/orgs","repos_url":"https://api.github.com/users/Schamper/repos","events_url":"https://api.github.com/users/Schamper/events{/privacy}","received_events_url":"https://api.github.com/users/Schamper/received_events","type":"User","site_admin":false},"labels":[{"id":4355518,"url":"https://api.github.com/repos/construct/construct/labels/bug%20found","name":"bug found","color":"cc0000","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-11-03T20:29:37Z","updated_at":"2016-11-25T12:16:13Z","closed_at":null,"body":"Let's say I have the following structs:\r\n```\r\nchild = 'child' / Struct(\r\n    'field_a' / Int16ub,\r\n    'field_b' / If(this.field_a)  # etc\r\n)\r\n\r\nparent = 'parent' / Struct(\r\n    'nested' / child,\r\n    'field_c' / If(this.nested.field_a)  # etc\r\n)\r\n```\r\n\r\nReferencing nested fields like this works as expected when building and parsing. The parent has to explicitly reference the complete \"path\" to the field, whereas the nested field can just reference its own fields. Quickly scanning over the code, this seems to be handled by the `_build` and `_parse` functions in the `Struct` class.\r\n\r\nHowever, say I want to use `.sizeof(container)` on `parent`. The container will be passed as context, but it won't be \"traversed\" correctly when it encounters nested structs. The `field_b` conditional will be called with the original \"parent\" container as context, so it can't find `this.field_a` (because it'll be under `this.nested.field_a`)."},"comment":{"url":"https://api.github.com/repos/construct/construct/issues/comments/262945156","html_url":"https://github.com/construct/construct/issues/266#issuecomment-262945156","issue_url":"https://api.github.com/repos/construct/construct/issues/266","id":262945156,"user":{"login":"arekbulski","id":5385838,"avatar_url":"https://avatars.githubusercontent.com/u/5385838?v=3","gravatar_id":"","url":"https://api.github.com/users/arekbulski","html_url":"https://github.com/arekbulski","followers_url":"https://api.github.com/users/arekbulski/followers","following_url":"https://api.github.com/users/arekbulski/following{/other_user}","gists_url":"https://api.github.com/users/arekbulski/gists{/gist_id}","starred_url":"https://api.github.com/users/arekbulski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arekbulski/subscriptions","organizations_url":"https://api.github.com/users/arekbulski/orgs","repos_url":"https://api.github.com/users/arekbulski/repos","events_url":"https://api.github.com/users/arekbulski/events{/privacy}","received_events_url":"https://api.github.com/users/arekbulski/received_events","type":"User","site_admin":false},"created_at":"2016-11-25T12:16:13Z","updated_at":"2016-11-25T12:16:13Z","body":"Your code wont work on an anonymous struct or a renamed renamed renamed struct. I will update your code and finally resolve this issue."}}
{"actor":{"display_login":"arekbulski"}}