{"action":"opened","issue":{"url":"https://api.github.com/repos/crystal-lang/crystal/issues/2458","repository_url":"https://api.github.com/repos/crystal-lang/crystal","labels_url":"https://api.github.com/repos/crystal-lang/crystal/issues/2458/labels{/name}","comments_url":"https://api.github.com/repos/crystal-lang/crystal/issues/2458/comments","events_url":"https://api.github.com/repos/crystal-lang/crystal/issues/2458/events","html_url":"https://github.com/crystal-lang/crystal/issues/2458","id":148511734,"number":2458,"title":"Inherit class variable types from ancestor","user":{"login":"ysbaddaden","id":47380,"avatar_url":"https://avatars.githubusercontent.com/u/47380?v=3","gravatar_id":"","url":"https://api.github.com/users/ysbaddaden","html_url":"https://github.com/ysbaddaden","followers_url":"https://api.github.com/users/ysbaddaden/followers","following_url":"https://api.github.com/users/ysbaddaden/following{/other_user}","gists_url":"https://api.github.com/users/ysbaddaden/gists{/gist_id}","starred_url":"https://api.github.com/users/ysbaddaden/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ysbaddaden/subscriptions","organizations_url":"https://api.github.com/users/ysbaddaden/orgs","repos_url":"https://api.github.com/users/ysbaddaden/repos","events_url":"https://api.github.com/users/ysbaddaden/events{/privacy}","received_events_url":"https://api.github.com/users/ysbaddaden/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-04-14T23:33:51Z","updated_at":"2016-04-14T23:33:51Z","closed_at":null,"body":"As explained in https://github.com/crystal-lang/crystal/pull/2443#issuecomment-209008322 the class variable types aren't inherited by descendants. Here is an example use case from Frost:\r\n\r\n```crystal\r\nclass Frost::Record\r\n  @@table_name : String\r\n\r\n  def self.table_name\r\n    @@table_name ||= name.tableize\r\n  end\r\nend\r\n\r\nclass User < Frost::Record\r\nend\r\n\r\nputs User.table_name # => undefined class variable '@@table_name' of User\r\n```\r\n\r\nA workaround is to use macro inherited:\r\n\r\n```crystal\r\nclass Frost::Record\r\n  macro inherited\r\n    @@table_name : String\r\n  end\r\n\r\n  def self.table_name\r\n    @@table_name ||= name.tableize\r\n  end\r\nend\r\n```"}}