{"action":"created","issue":{"url":"https://api.github.com/repos/fish-shell/fish-shell/issues/5054","repository_url":"https://api.github.com/repos/fish-shell/fish-shell","labels_url":"https://api.github.com/repos/fish-shell/fish-shell/issues/5054/labels{/name}","comments_url":"https://api.github.com/repos/fish-shell/fish-shell/issues/5054/comments","events_url":"https://api.github.com/repos/fish-shell/fish-shell/issues/5054/events","html_url":"https://github.com/fish-shell/fish-shell/issues/5054","id":333122143,"node_id":"MDU6SXNzdWUzMzMxMjIxNDM=","number":5054,"title":"Script-local variables not correctly substituted when functions are called","user":{"login":"mqudsi","id":606923,"node_id":"MDQ6VXNlcjYwNjkyMw==","avatar_url":"https://avatars3.githubusercontent.com/u/606923?v=4","gravatar_id":"","url":"https://api.github.com/users/mqudsi","html_url":"https://github.com/mqudsi","followers_url":"https://api.github.com/users/mqudsi/followers","following_url":"https://api.github.com/users/mqudsi/following{/other_user}","gists_url":"https://api.github.com/users/mqudsi/gists{/gist_id}","starred_url":"https://api.github.com/users/mqudsi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mqudsi/subscriptions","organizations_url":"https://api.github.com/users/mqudsi/orgs","repos_url":"https://api.github.com/users/mqudsi/repos","events_url":"https://api.github.com/users/mqudsi/events{/privacy}","received_events_url":"https://api.github.com/users/mqudsi/received_events","type":"User","site_admin":false},"labels":[{"id":4724780,"node_id":"MDU6TGFiZWw0NzI0Nzgw","url":"https://api.github.com/repos/fish-shell/fish-shell/labels/question","name":"question","color":"f9d0c4","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-06-18T03:17:44Z","updated_at":"2018-06-19T05:18:03Z","closed_at":"2018-06-19T05:18:03Z","author_association":"CONTRIBUTOR","body":"I'll preface this right off the bat with \"I don't know if this is by design, but I sure am confused.\"\r\n\r\n```fish\r\nset -l foo\r\n\r\nfunction print_foo\r\n\techo \"Evaluating print_foo\"\r\n\techo \"inner foo: $foo\"\r\nend\r\n\r\nset foo \"foo\"\r\necho \"setting foo to \\\"$foo\\\"\"\r\nprint_foo\r\n```\r\n\r\nThis prints the following:\r\n```\r\nsetting foo to \"foo\"\r\nEvaluating print_foo\r\ninner foo: \r\n```\r\n\r\nAs I understand it, the first line of the script defines a variable local to the script named `foo`.  While a function block defines a scope, the declaration of a new scope does not wipe out variables defined in the parent scope.\r\n\r\nI can understand if the variable `foo` is not defined if I were to call `print_foo` from outside this script (after sourcing it), though I would consider that a bug since a \"reference\" to that variable still exists and therefore it shouldn't be garbage cleaned. But I don't understand why when `print_foo` is called from within the same script file that `print_foo` is defined in, the value is not retained.\r\n\r\nAdditionally, I am vexed because the behavior below differs:\r\n\r\n```fish\r\nset -l foo \"foo\"\r\nfor i in \"\"\r\n    echo \"Inner foo: \\\"$foo\\\"\"\r\nend\r\n```\r\n\r\nprints `Inner foo: \"foo\"`, even though the `for` block also defines a new scope just like the `function` block does."},"comment":{"url":"https://api.github.com/repos/fish-shell/fish-shell/issues/comments/398277103","html_url":"https://github.com/fish-shell/fish-shell/issues/5054#issuecomment-398277103","issue_url":"https://api.github.com/repos/fish-shell/fish-shell/issues/5054","id":398277103,"node_id":"MDEyOklzc3VlQ29tbWVudDM5ODI3NzEwMw==","user":{"login":"mqudsi","id":606923,"node_id":"MDQ6VXNlcjYwNjkyMw==","avatar_url":"https://avatars3.githubusercontent.com/u/606923?v=4","gravatar_id":"","url":"https://api.github.com/users/mqudsi","html_url":"https://github.com/mqudsi","followers_url":"https://api.github.com/users/mqudsi/followers","following_url":"https://api.github.com/users/mqudsi/following{/other_user}","gists_url":"https://api.github.com/users/mqudsi/gists{/gist_id}","starred_url":"https://api.github.com/users/mqudsi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mqudsi/subscriptions","organizations_url":"https://api.github.com/users/mqudsi/orgs","repos_url":"https://api.github.com/users/mqudsi/repos","events_url":"https://api.github.com/users/mqudsi/events{/privacy}","received_events_url":"https://api.github.com/users/mqudsi/received_events","type":"User","site_admin":false},"created_at":"2018-06-19T05:18:02Z","updated_at":"2018-06-19T05:18:02Z","author_association":"CONTRIBUTOR","body":"Awesome, thanks guys."}}
{"actor":{"display_login":"mqudsi"}}