{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/20487","repository_url":"https://api.github.com/repos/JuliaLang/julia","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/20487/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/20487/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/20487/events","html_url":"https://github.com/JuliaLang/julia/issues/20487","id":205819847,"number":20487,"title":"current_module() gives unexpected result inside of __init__()","user":{"login":"staticfloat","id":130920,"avatar_url":"https://avatars.githubusercontent.com/u/130920?v=3","gravatar_id":"","url":"https://api.github.com/users/staticfloat","html_url":"https://github.com/staticfloat","followers_url":"https://api.github.com/users/staticfloat/followers","following_url":"https://api.github.com/users/staticfloat/following{/other_user}","gists_url":"https://api.github.com/users/staticfloat/gists{/gist_id}","starred_url":"https://api.github.com/users/staticfloat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/staticfloat/subscriptions","organizations_url":"https://api.github.com/users/staticfloat/orgs","repos_url":"https://api.github.com/users/staticfloat/repos","events_url":"https://api.github.com/users/staticfloat/events{/privacy}","received_events_url":"https://api.github.com/users/staticfloat/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-02-07T08:30:42Z","updated_at":"2017-02-07T10:51:47Z","closed_at":null,"body":"When trying to test if a particular value had been set within `deps.jl`, I discovered that `__init__()` is run inside the `Main` module (e.g. `current_module()` returns `Main`) which causes fun strangeness like the following:\r\n\r\n\r\n```julia\r\n# module_test.jl\r\nmodule Foo\r\n\r\nconst bar = 1\r\nfunction __init__()\r\n    if isdefined(:bar)\r\n        println(\"bar is defined!\")\r\n    else\r\n        println(\"bar is undefined!\")\r\n    end\r\n\r\n    println(\"Value of bar: $bar\")\r\nend\r\nend # module Foo\r\n\r\nusing Foo\r\n```\r\n```\r\n$ julia module_test.jl\r\nbar is undefined!\r\nValue of bar: 1\r\n```\r\n\r\nThis can be easily remedied by using `isdefined(Foo, :bar)`, but it seems to me that having a situation where `isdefined()` fails to resolve scope the same way as the actual compiler is a bug."},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/277964267","html_url":"https://github.com/JuliaLang/julia/issues/20487#issuecomment-277964267","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/20487","id":277964267,"user":{"login":"amitmurthy","id":117461,"avatar_url":"https://avatars.githubusercontent.com/u/117461?v=3","gravatar_id":"","url":"https://api.github.com/users/amitmurthy","html_url":"https://github.com/amitmurthy","followers_url":"https://api.github.com/users/amitmurthy/followers","following_url":"https://api.github.com/users/amitmurthy/following{/other_user}","gists_url":"https://api.github.com/users/amitmurthy/gists{/gist_id}","starred_url":"https://api.github.com/users/amitmurthy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amitmurthy/subscriptions","organizations_url":"https://api.github.com/users/amitmurthy/orgs","repos_url":"https://api.github.com/users/amitmurthy/repos","events_url":"https://api.github.com/users/amitmurthy/events{/privacy}","received_events_url":"https://api.github.com/users/amitmurthy/received_events","type":"User","site_admin":false},"created_at":"2017-02-07T10:51:47Z","updated_at":"2017-02-07T10:51:47Z","body":"The doctstring for `current_module` is pretty explicit about its behavior - http://docs.julialang.org/en/latest/stdlib/base.html#Base.current_module. Maybe we should just add the above code as an example? "}}
{"actor":{"display_login":"amitmurthy"}}