{"action":"created","issue":{"url":"https://api.github.com/repos/elixir-lang/elixir/issues/4126","labels_url":"https://api.github.com/repos/elixir-lang/elixir/issues/4126/labels{/name}","comments_url":"https://api.github.com/repos/elixir-lang/elixir/issues/4126/comments","events_url":"https://api.github.com/repos/elixir-lang/elixir/issues/4126/events","html_url":"https://github.com/elixir-lang/elixir/issues/4126","id":124284664,"number":4126,"title":"#put_in function with structs raises UndefinedFunctionError (get_and_update), macro form is fine","user":{"login":"coryodaniel","id":11587,"avatar_url":"https://avatars.githubusercontent.com/u/11587?v=3","gravatar_id":"","url":"https://api.github.com/users/coryodaniel","html_url":"https://github.com/coryodaniel","followers_url":"https://api.github.com/users/coryodaniel/followers","following_url":"https://api.github.com/users/coryodaniel/following{/other_user}","gists_url":"https://api.github.com/users/coryodaniel/gists{/gist_id}","starred_url":"https://api.github.com/users/coryodaniel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coryodaniel/subscriptions","organizations_url":"https://api.github.com/users/coryodaniel/orgs","repos_url":"https://api.github.com/users/coryodaniel/repos","events_url":"https://api.github.com/users/coryodaniel/events{/privacy}","received_events_url":"https://api.github.com/users/coryodaniel/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-12-29T23:58:18Z","updated_at":"2015-12-30T05:56:09Z","closed_at":null,"body":"The method ```put_in``` when used with structs raises an ```UndefinedFuntionError``` ```get_and_update```. Using ```put_in``` on a map works fine, and using it in its macro form works fine. \r\n\r\nA little setup:\r\n```elixir\r\ndefmodule BugReport do\r\n  defstruct owner: %{}, details: \"\", severity: 1\r\nend\r\ndefmodule Customer do\r\n  defstruct name: \"\", company: \"\"\r\nend\r\n```\r\n\r\nAnd reproducing it:\r\n```elixir\r\nstruct_example = %BugReport{\r\n  owner: %Customer{ name: \"Rufus the Dufus\", company: \"Int'l Conspiracy Corp\"},\r\n  details: \"OMG\",\r\n  severity: 99999\r\n}\r\n\r\nmap_example = %{\r\n  owner: %{\r\n    name: \"Rufus the Dufus\"\r\n  }\r\n}\r\n\r\nmap_example    = put_in(map_example, [:owner, :name], \"Cory\")\r\n#=> map_example.owner.name == \"Cory\"\r\n\r\nstruct_example = put_in(struct_example.owner.name, \"Cory\") \r\n#=> struct_example.owner.name == \"Cory\"\r\n\r\nstruct_example = put_in(struct_example, [:owner, :name], \"Cory\")\r\n** (UndefinedFunctionError) undefined function BugReport.get_and_update/3\r\n         BugReport.get_and_update(%BugReport{details: \"THE SSOFWAR EDOESNT EVEN WERK!!?!1111!!\", owner: %Customer{company: \"Int'l Conspiracy Corp\", name: \"Rufus the Dufus\"}, severity: 99999}, :owner, #Function<17.51792600/1 in Kernel.get_and_update_in/3>)\r\n(elixir) lib/kernel.ex:1721: Kernel.put_in/3\r\n```\r\n\r\nI am on the 1.2-rc1 branch"},"comment":{"url":"https://api.github.com/repos/elixir-lang/elixir/issues/comments/167941892","html_url":"https://github.com/elixir-lang/elixir/issues/4126#issuecomment-167941892","issue_url":"https://api.github.com/repos/elixir-lang/elixir/issues/4126","id":167941892,"user":{"login":"coryodaniel","id":11587,"avatar_url":"https://avatars.githubusercontent.com/u/11587?v=3","gravatar_id":"","url":"https://api.github.com/users/coryodaniel","html_url":"https://github.com/coryodaniel","followers_url":"https://api.github.com/users/coryodaniel/followers","following_url":"https://api.github.com/users/coryodaniel/following{/other_user}","gists_url":"https://api.github.com/users/coryodaniel/gists{/gist_id}","starred_url":"https://api.github.com/users/coryodaniel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coryodaniel/subscriptions","organizations_url":"https://api.github.com/users/coryodaniel/orgs","repos_url":"https://api.github.com/users/coryodaniel/repos","events_url":"https://api.github.com/users/coryodaniel/events{/privacy}","received_events_url":"https://api.github.com/users/coryodaniel/received_events","type":"User","site_admin":false},"created_at":"2015-12-30T05:56:09Z","updated_at":"2015-12-30T05:56:09Z","body":"Got it. Sorry working from an old version of the prag prog book but using a newer version of elixir!\n\nThanks for the link.\n\nSent from my iPhone\n\n> On Dec 29, 2015, at 4:06 PM, José Valim <notifications@github.com> wrote:\n> \n> Another way to think about this is as follows:\n> \n> put_in(struct_example.owner.name, \"Cory\")\n> translates to something like:\n> \n> put_in(struct_example, [Access.field(:owner), Access.field(:name)], \"Cory\")\n> while:\n> \n> put_in(struct_example, [Access.key(:owner), Access.key(:name)], \"Cory\")\n> They are different access rules. And a struct has fields but it does not have keys generally speaking like a map or a keyword list would. Issue #4009 is about making all of this a bit more explicit.\n> \n> —\n> Reply to this email directly or view it on GitHub.\n> \n"}}