{"action":"created","issue":{"url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/5358","repository_url":"https://api.github.com/repos/HaxeFoundation/haxe","labels_url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/5358/labels{/name}","comments_url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/5358/comments","events_url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/5358/events","html_url":"https://github.com/HaxeFoundation/haxe/issues/5358","id":159530886,"number":5358,"title":"[hl] Don't know how to cast void to #Example","user":{"login":"sebthom","id":426959,"avatar_url":"https://avatars.githubusercontent.com/u/426959?v=3","gravatar_id":"","url":"https://api.github.com/users/sebthom","html_url":"https://github.com/sebthom","followers_url":"https://api.github.com/users/sebthom/followers","following_url":"https://api.github.com/users/sebthom/following{/other_user}","gists_url":"https://api.github.com/users/sebthom/gists{/gist_id}","starred_url":"https://api.github.com/users/sebthom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sebthom/subscriptions","organizations_url":"https://api.github.com/users/sebthom/orgs","repos_url":"https://api.github.com/users/sebthom/repos","events_url":"https://api.github.com/users/sebthom/events{/privacy}","received_events_url":"https://api.github.com/users/sebthom/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"Simn","id":634365,"avatar_url":"https://avatars.githubusercontent.com/u/634365?v=3","gravatar_id":"","url":"https://api.github.com/users/Simn","html_url":"https://github.com/Simn","followers_url":"https://api.github.com/users/Simn/followers","following_url":"https://api.github.com/users/Simn/following{/other_user}","gists_url":"https://api.github.com/users/Simn/gists{/gist_id}","starred_url":"https://api.github.com/users/Simn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Simn/subscriptions","organizations_url":"https://api.github.com/users/Simn/orgs","repos_url":"https://api.github.com/users/Simn/repos","events_url":"https://api.github.com/users/Simn/events{/privacy}","received_events_url":"https://api.github.com/users/Simn/received_events","type":"User","site_admin":false},"assignees":[{"login":"Simn","id":634365,"avatar_url":"https://avatars.githubusercontent.com/u/634365?v=3","gravatar_id":"","url":"https://api.github.com/users/Simn","html_url":"https://github.com/Simn","followers_url":"https://api.github.com/users/Simn/followers","following_url":"https://api.github.com/users/Simn/following{/other_user}","gists_url":"https://api.github.com/users/Simn/gists{/gist_id}","starred_url":"https://api.github.com/users/Simn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Simn/subscriptions","organizations_url":"https://api.github.com/users/Simn/orgs","repos_url":"https://api.github.com/users/Simn/repos","events_url":"https://api.github.com/users/Simn/events{/privacy}","received_events_url":"https://api.github.com/users/Simn/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/HaxeFoundation/haxe/milestones/11","html_url":"https://github.com/HaxeFoundation/haxe/milestones/3.3.0","labels_url":"https://api.github.com/repos/HaxeFoundation/haxe/milestones/11/labels","id":1599225,"number":11,"title":"3.3.0","description":"","creator":{"login":"Simn","id":634365,"avatar_url":"https://avatars.githubusercontent.com/u/634365?v=3","gravatar_id":"","url":"https://api.github.com/users/Simn","html_url":"https://github.com/Simn","followers_url":"https://api.github.com/users/Simn/followers","following_url":"https://api.github.com/users/Simn/following{/other_user}","gists_url":"https://api.github.com/users/Simn/gists{/gist_id}","starred_url":"https://api.github.com/users/Simn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Simn/subscriptions","organizations_url":"https://api.github.com/users/Simn/orgs","repos_url":"https://api.github.com/users/Simn/repos","events_url":"https://api.github.com/users/Simn/events{/privacy}","received_events_url":"https://api.github.com/users/Simn/received_events","type":"User","site_admin":false},"open_issues":20,"closed_issues":29,"state":"open","created_at":"2016-02-23T09:11:44Z","updated_at":"2016-07-19T13:15:18Z","due_on":"2016-06-18T22:00:00Z","closed_at":null},"comments":13,"created_at":"2016-06-09T23:28:54Z","updated_at":"2016-07-22T06:53:54Z","closed_at":null,"body":"The following code doesn't compile when targeting HL but throws the error `characters 25-51 : Don't know how to cast void to #Example`.\r\n```haxe\r\nabstract Either2<A,B>(haxe.ds.Either<A,B>) {\r\n\tpublic function new(value:haxe.ds.Either<A,B>) this = value;\r\n\t@:from static function fromA<A,B>(value:A):Either2<A,B> return new Either2(Left(value));\r\n}\r\n\r\nclass Example {\r\n\r\n    inline\r\n    public static function createExample(value:Either2<String, Int> = null):Example {\r\n        if (value == null) return null;\r\n        return new Example();\r\n    }\r\n    \r\n    function new() {}\r\n}\r\n\r\nclass Test {\r\n\r\n    static var example = Example.createExample(\"g\");\r\n\r\n    public static function main() {\r\n        trace(example);\r\n    }\r\n}\r\n```\r\nThe example contains only the minimum number of statements from my project to reproduce the error.\r\n\r\nIt compiles if I remove \r\n* the `inline` keyword from the `createExample` function, or\r\n* the `static` keyword from the `Test.example` field, or\r\n* the if statement from the `createExample` function\r\n\r\nWhen targeting C# and Java the Compiler Warning `Type Example is being cast to the unrelated type Void` is reported but compilation proceeds and the code works. All dynamic targets work fine too.\r\n\r\nTargeting CPP fails with\r\n```\r\n./src/Test.cpp: In static member function 'static void hx::strings::TestRunner_obj::__boot()':\r\n./src/Test.cpp:390:25: error: expected primary-expression before 'if'\r\n HXDLIN(  43)  example = if (_hx_tmp) {\r\n                         ^\r\n./src/Test.cpp:393:15: error: 'else' without a previous 'if'\r\n               else {\r\n               ^\r\nError: Build failed\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/comments/234468457","html_url":"https://github.com/HaxeFoundation/haxe/issues/5358#issuecomment-234468457","issue_url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/5358","id":234468457,"user":{"login":"Simn","id":634365,"avatar_url":"https://avatars.githubusercontent.com/u/634365?v=3","gravatar_id":"","url":"https://api.github.com/users/Simn","html_url":"https://github.com/Simn","followers_url":"https://api.github.com/users/Simn/followers","following_url":"https://api.github.com/users/Simn/following{/other_user}","gists_url":"https://api.github.com/users/Simn/gists{/gist_id}","starred_url":"https://api.github.com/users/Simn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Simn/subscriptions","organizations_url":"https://api.github.com/users/Simn/orgs","repos_url":"https://api.github.com/users/Simn/repos","events_url":"https://api.github.com/users/Simn/events{/privacy}","received_events_url":"https://api.github.com/users/Simn/received_events","type":"User","site_admin":false},"created_at":"2016-07-22T06:53:54Z","updated_at":"2016-07-22T06:53:54Z","body":"Sure we type it with WithType, just as we do something like this:\r\n\r\n```haxe\r\nvar x = if (e1) e2 else e3\r\n```\r\n\r\nThis is transformed:\r\n\r\n```haxe\r\nvar x;\r\nif (e1) x = e2\r\nelse x = e3\r\n```\r\n\r\nAt this stage the if-expression is typed as Void, so we effectively discard the type that originally came from the WithType. Depending on the complexity of e1, e2 and e3 we might then reconstruct the original expression.\r\n\r\nNow imagine the same thing without the assignment. We obviously end up with this:\r\n\r\n```haxe\r\nif (e1) e2\r\nelse e3\r\n```\r\n\r\nAnd again the if-expression is typed as Void. This case is indistinguishable from the former, the only difference is the context because the latter is actually assigned to a static field."}}
{"actor":{"display_login":"Simn"}}