{"action":"created","issue":{"url":"https://api.github.com/repos/crystal-lang/crystal/issues/1692","repository_url":"https://api.github.com/repos/crystal-lang/crystal","labels_url":"https://api.github.com/repos/crystal-lang/crystal/issues/1692/labels{/name}","comments_url":"https://api.github.com/repos/crystal-lang/crystal/issues/1692/comments","events_url":"https://api.github.com/repos/crystal-lang/crystal/issues/1692/events","html_url":"https://github.com/crystal-lang/crystal/issues/1692","id":109717218,"number":1692,"title":"Can't pass an argument constrained by `if x.is_a?` to a matching, statically-typed parameter.","user":{"login":"Perelandric","id":1114646,"avatar_url":"https://avatars.githubusercontent.com/u/1114646?v=3","gravatar_id":"","url":"https://api.github.com/users/Perelandric","html_url":"https://github.com/Perelandric","followers_url":"https://api.github.com/users/Perelandric/followers","following_url":"https://api.github.com/users/Perelandric/following{/other_user}","gists_url":"https://api.github.com/users/Perelandric/gists{/gist_id}","starred_url":"https://api.github.com/users/Perelandric/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Perelandric/subscriptions","organizations_url":"https://api.github.com/users/Perelandric/orgs","repos_url":"https://api.github.com/users/Perelandric/repos","events_url":"https://api.github.com/users/Perelandric/events{/privacy}","received_events_url":"https://api.github.com/users/Perelandric/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/crystal-lang/crystal/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/crystal-lang/crystal/labels/compiler","name":"compiler","color":"fef2c0"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-10-05T01:17:38Z","updated_at":"2016-04-13T19:41:06Z","closed_at":"2016-04-13T19:41:06Z","body":"I don't know if this is a bug or just my lack of understanding, but I thought the `if x.is_a? Subset` would allow me to pass `x` to `def test_2(x : Subset)`. Instead I get the compile-time error noted below.\r\n\r\nIf I change `x` to be a definite `Sub1` or `Sub2` instance, it compiles.\r\n\r\n```\r\nclass Parent\r\nend\r\nclass Sub1 < Parent\r\nend\r\nclass Sub2 < Parent\r\nend\r\n\r\nalias Subset = (Sub1 | Sub2) # In actual code, this is a subset of the sub-classes of Parent\r\n\r\ndef test_2(x : Subset)\r\n  puts \"test\"\r\nend\r\n\r\ndef test()\r\n  x = true ? Sub1.new() : Sub2.new()\r\n\r\n  if x.is_a? Subset\r\n    test_2(x)\r\n  end\r\nend\r\n\r\ntest()\r\n```\r\n\r\n\r\n\r\n>Error in ./tester.cr:22: instantiating 'test()'\r\n\r\n>test()\r\n>^~~~\r\n\r\n>in ./parser.cr:18: no overload matches 'test_2' with types Parent+\r\n>Overloads are:\r\n> \\- test_2(x : Subset)\r\n\r\n>    test_2(x)\r\n>    ^~~~~~\r\n\r\n---\r\n\r\n>Crystal 0.8.0 [e363b63] (Sat Sep 19 12:00:17 UTC 2015)\r\n"},"comment":{"url":"https://api.github.com/repos/crystal-lang/crystal/issues/comments/209616760","html_url":"https://github.com/crystal-lang/crystal/issues/1692#issuecomment-209616760","issue_url":"https://api.github.com/repos/crystal-lang/crystal/issues/1692","id":209616760,"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":"2016-04-13T19:41:06Z","updated_at":"2016-04-13T19:41:06Z","body":"This seems to be working in 0.15.0 and above. I also remember improving a bit the type restriction handling regarding modules and aliases, so that must have fixed it."}}