{"action":"created","issue":{"url":"https://api.github.com/repos/chapel-lang/chapel/issues/3728","repository_url":"https://api.github.com/repos/chapel-lang/chapel","labels_url":"https://api.github.com/repos/chapel-lang/chapel/issues/3728/labels{/name}","comments_url":"https://api.github.com/repos/chapel-lang/chapel/issues/3728/comments","events_url":"https://api.github.com/repos/chapel-lang/chapel/issues/3728/events","html_url":"https://github.com/chapel-lang/chapel/pull/3728","id":148777965,"number":3728,"title":"Move PRIM_NEW handling to resolution","user":{"login":"mppf","id":3653132,"avatar_url":"https://avatars.githubusercontent.com/u/3653132?v=3","gravatar_id":"","url":"https://api.github.com/users/mppf","html_url":"https://github.com/mppf","followers_url":"https://api.github.com/users/mppf/followers","following_url":"https://api.github.com/users/mppf/following{/other_user}","gists_url":"https://api.github.com/users/mppf/gists{/gist_id}","starred_url":"https://api.github.com/users/mppf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mppf/subscriptions","organizations_url":"https://api.github.com/users/mppf/orgs","repos_url":"https://api.github.com/users/mppf/repos","events_url":"https://api.github.com/users/mppf/events{/privacy}","received_events_url":"https://api.github.com/users/mppf/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/chapel-lang/chapel/labels/work%20in%20progress","name":"work in progress","color":"006b75"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-04-15T21:51:17Z","updated_at":"2016-04-15T21:54:04Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/chapel-lang/chapel/pulls/3728","html_url":"https://github.com/chapel-lang/chapel/pull/3728","diff_url":"https://github.com/chapel-lang/chapel/pull/3728.diff","patch_url":"https://github.com/chapel-lang/chapel/pull/3728.patch"},"body":"This is to fix code such as\r\n\r\n      proc createClassInstance(type X) where isClassType(X) {\r\n         var x = new X();\r\n         return x;\r\n      }\r\n      var foo = createClassInstance(Foo);\r\n\r\nIn my initial investigated, I identified call_constructor_for_class in\r\nnormalize.cpp as doing some transformations that can't possibly be done\r\nbefore function resolution - at least for a generic case like the above.\r\n\r\nThen, I discovered that functionResolution.cpp already has a resolveNew\r\nfunction to handle PRIM_NEW.  So, I moved the logic finding the name of\r\nthe constructor to call from call_constructor_for_class  in normalize to\r\nresolveNew in function resolution.\r\n\r\nOne problem came up: resolution resolves expressions in postorder, the\r\nCallExpr within the PRIM_NEW was getting resolved first and not getting\r\nspecial treatment.\r\n\r\nTherefore, I adjusted call_constructor_for_class to rewrite PRIM_NEW to\r\nnot use a nested call - instead, PRIM_NEW now uses a different style\r\nafter normalization than before.\r\n\r\nBefore normalization:\r\n\r\n      PRIM_NEW (CallExpr SomeType args ...)\r\n\r\nAfter normalization\r\n\r\n      PRIM_NEW SomeType args...\r\n\r\nI felt that adjusting normalize in this way was better than further\r\ncomplicating the basic call resolution logic in functionResolution.cpp,\r\nbut certainly another approach could have worked.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/chapel-lang/chapel/issues/comments/210661577","html_url":"https://github.com/chapel-lang/chapel/pull/3728#issuecomment-210661577","issue_url":"https://api.github.com/repos/chapel-lang/chapel/issues/3728","id":210661577,"user":{"login":"mppf","id":3653132,"avatar_url":"https://avatars.githubusercontent.com/u/3653132?v=3","gravatar_id":"","url":"https://api.github.com/users/mppf","html_url":"https://github.com/mppf","followers_url":"https://api.github.com/users/mppf/followers","following_url":"https://api.github.com/users/mppf/following{/other_user}","gists_url":"https://api.github.com/users/mppf/gists{/gist_id}","starred_url":"https://api.github.com/users/mppf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mppf/subscriptions","organizations_url":"https://api.github.com/users/mppf/orgs","repos_url":"https://api.github.com/users/mppf/repos","events_url":"https://api.github.com/users/mppf/events{/privacy}","received_events_url":"https://api.github.com/users/mppf/received_events","type":"User","site_admin":false},"created_at":"2016-04-15T21:54:04Z","updated_at":"2016-04-15T21:54:04Z","body":"I'm still testing this PR."}}