{"action":"created","issue":{"url":"https://api.github.com/repos/manastech/crystal/issues/1696","labels_url":"https://api.github.com/repos/manastech/crystal/issues/1696/labels{/name}","comments_url":"https://api.github.com/repos/manastech/crystal/issues/1696/comments","events_url":"https://api.github.com/repos/manastech/crystal/issues/1696/events","html_url":"https://github.com/manastech/crystal/issues/1696","id":109976712,"number":1696,"title":"invalid codegen resulting in segfault","user":{"login":"jreinert","id":1074324,"avatar_url":"https://avatars.githubusercontent.com/u/1074324?v=3","gravatar_id":"","url":"https://api.github.com/users/jreinert","html_url":"https://github.com/jreinert","followers_url":"https://api.github.com/users/jreinert/followers","following_url":"https://api.github.com/users/jreinert/following{/other_user}","gists_url":"https://api.github.com/users/jreinert/gists{/gist_id}","starred_url":"https://api.github.com/users/jreinert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jreinert/subscriptions","organizations_url":"https://api.github.com/users/jreinert/orgs","repos_url":"https://api.github.com/users/jreinert/repos","events_url":"https://api.github.com/users/jreinert/events{/privacy}","received_events_url":"https://api.github.com/users/jreinert/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/manastech/crystal/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/manastech/crystal/labels/compiler","name":"compiler","color":"fef2c0"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-10-06T10:10:23Z","updated_at":"2015-10-06T12:29:49Z","closed_at":null,"body":"following code raises segfault when run\r\n\r\n``` crystal\r\nrequire \"json\"\r\n\r\nclass Foo\r\n  def initialize\r\n    @handlers = {} of String => Hash(String, JSON::Type) ->\r\n    on(\"connected\") { |message| @session = message[\"session\"] as String }\r\n    connect\r\n  end\r\n\r\n  def on(message_type, &block : Hash(String, JSON::Type) ->)\r\n    @handlers[message_type] = block\r\n  end\r\n\r\n  private def connect(version = \"1\")\r\n    fields = { version: version, support: [\"1\"] }\r\n    @session.try { |session| fields[:session] = session }\r\n    puts fields # segfault\r\n\r\n    receive\r\n  end\r\n\r\n  def receive\r\n    message = JSON.parse(%({\"msg\": \"connected\", \"session\": \"foo\"})) as Hash\r\n    @handlers[message[\"msg\"]?]?.try { |handler| handler.call(message) }\r\n  end\r\nend\r\n\r\nFoo.new\r\n```"},"comment":{"url":"https://api.github.com/repos/manastech/crystal/issues/comments/145842017","html_url":"https://github.com/manastech/crystal/issues/1696#issuecomment-145842017","issue_url":"https://api.github.com/repos/manastech/crystal/issues/1696","id":145842017,"user":{"login":"asterite","id":209371,"avatar_url":"https://avatars.githubusercontent.com/u/209371?v=3","gravatar_id":"","url":"https://api.github.com/users/asterite","html_url":"https://github.com/asterite","followers_url":"https://api.github.com/users/asterite/followers","following_url":"https://api.github.com/users/asterite/following{/other_user}","gists_url":"https://api.github.com/users/asterite/gists{/gist_id}","starred_url":"https://api.github.com/users/asterite/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asterite/subscriptions","organizations_url":"https://api.github.com/users/asterite/orgs","repos_url":"https://api.github.com/users/asterite/repos","events_url":"https://api.github.com/users/asterite/events{/privacy}","received_events_url":"https://api.github.com/users/asterite/received_events","type":"User","site_admin":false},"created_at":"2015-10-06T12:29:49Z","updated_at":"2015-10-06T12:29:49Z","body":"Reduced:\r\n\r\n```crystal\r\ndef capture(&block)\r\n  block\r\nend\r\n\r\nclass Foo\r\n  def initialize\r\n    capture { @foo = 1 }\r\n  end\r\n\r\n  def foo\r\n    @foo\r\n  end\r\nend\r\n\r\nputs typeof(Foo.new.foo) #=> Int32 (instead of Int32 | Nil)\r\n```\r\n\r\nProblem: when a block is captured the analysis that instance variables assigned there are nilable isn't being done."}}