{"action":"created","issue":{"url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/7459","repository_url":"https://api.github.com/repos/HaxeFoundation/haxe","labels_url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/7459/labels{/name}","comments_url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/7459/comments","events_url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/7459/events","html_url":"https://github.com/HaxeFoundation/haxe/issues/7459","id":362719194,"node_id":"MDU6SXNzdWUzNjI3MTkxOTQ=","number":7459,"title":"Defining a parametrised typedef in a macro","user":{"login":"Aurel300","id":1102162,"node_id":"MDQ6VXNlcjExMDIxNjI=","avatar_url":"https://avatars1.githubusercontent.com/u/1102162?v=4","gravatar_id":"","url":"https://api.github.com/users/Aurel300","html_url":"https://github.com/Aurel300","followers_url":"https://api.github.com/users/Aurel300/followers","following_url":"https://api.github.com/users/Aurel300/following{/other_user}","gists_url":"https://api.github.com/users/Aurel300/gists{/gist_id}","starred_url":"https://api.github.com/users/Aurel300/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Aurel300/subscriptions","organizations_url":"https://api.github.com/users/Aurel300/orgs","repos_url":"https://api.github.com/users/Aurel300/repos","events_url":"https://api.github.com/users/Aurel300/events{/privacy}","received_events_url":"https://api.github.com/users/Aurel300/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-09-21T18:01:14Z","updated_at":"2018-09-21T18:13:45Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"I am trying to reproduce the `typedef` in the following snippet using a macro:\r\n\r\n```haxe\r\ntypedef NumericVector<T:Float> = haxe.ds.Vector<T>;\r\n\r\nclass Main {\r\n  public static function main():Void {\r\n    var vec:NumericVector<Float> = haxe.ds.Vector.fromArrayCopy([1.0, 2, 3]);\r\n    trace(\"my numeric vector: \" + vec);\r\n  }\r\n}\r\n```\r\n\r\nIf I dump the module types using `haxe.macro.Context.getModule`, I get:\r\n\r\n    [TType(NumericVector,[TInst(NumericVector.T,[])]),TInst(Main,[])]\r\n\r\nWhich seems to indicate that `T` is not a real type and is only present in the `params` array of the `NumericVector` type definition. And indeed, if I create a type without actually using the type parameter on the \"right-hand side\", i.e. to reproduce the following:\r\n\r\n```haxe\r\ntypedef MacroVector<T:Float> = Bool;\r\n```\r\n\r\nThen the following macro works fine:\r\n\r\n```haxe\r\npublic static function defineMacroVector():Void {\r\n  Context.defineModule(\"MacroVector\", [{\r\n       fields: []\r\n      ,kind: TDAlias(TPath({name: \"Bool\", pack: []}))\r\n      ,name: \"MacroVector\"\r\n      ,pack: []\r\n      ,params: [\r\n          {name: \"T\", constraints: [TPath({name: \"Float\", pack: []})]}\r\n        ]\r\n      ,pos: Context.currentPos()\r\n    }]);\r\n}\r\n```\r\n\r\nIf I dump the module defined with the above, I get:\r\n\r\n    [TType(MacroVector,[TInst(MacroVector.T,[])])]\r\n\r\nBut if I want to use the type parameter:\r\n\r\n```haxe\r\npublic static function defineMacroVector():Void {\r\n  Context.defineModule(\"MacroVector\", [{\r\n       fields: []\r\n      ,kind: TDAlias(TPath({name: \"Vector\", pack: [\"haxe\", \"ds\"], params: [\r\n          TPType(TPath({name: \"MacroVector\", pack: [], sub: \"T\"}))\r\n        ]}))\r\n      ,name: \"MacroVector\"\r\n      ,pack: []\r\n      ,params: [\r\n          {name: \"T\", constraints: [TPath({name: \"Float\", pack: []})]}\r\n        ]\r\n      ,pos: Context.currentPos()\r\n    }]);\r\n}\r\n```\r\n\r\nThen I get the error:\r\n\r\n    --macro:1: character 0 : Module MacroVector does not define type T\r\n\r\nIs this intended behaviour? Should the type system recognise that the typedef's type parameters are valid types when resolving types? Should I define a stub type `T`?"},"comment":{"url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/comments/423626479","html_url":"https://github.com/HaxeFoundation/haxe/issues/7459#issuecomment-423626479","issue_url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/7459","id":423626479,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMzYyNjQ3OQ==","user":{"login":"nadako","id":49749,"node_id":"MDQ6VXNlcjQ5NzQ5","avatar_url":"https://avatars0.githubusercontent.com/u/49749?v=4","gravatar_id":"","url":"https://api.github.com/users/nadako","html_url":"https://github.com/nadako","followers_url":"https://api.github.com/users/nadako/followers","following_url":"https://api.github.com/users/nadako/following{/other_user}","gists_url":"https://api.github.com/users/nadako/gists{/gist_id}","starred_url":"https://api.github.com/users/nadako/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nadako/subscriptions","organizations_url":"https://api.github.com/users/nadako/orgs","repos_url":"https://api.github.com/users/nadako/repos","events_url":"https://api.github.com/users/nadako/events{/privacy}","received_events_url":"https://api.github.com/users/nadako/received_events","type":"User","site_admin":false},"created_at":"2018-09-21T18:13:45Z","updated_at":"2018-09-21T18:13:45Z","author_association":"MEMBER","body":"I see why it can be confusing, but remember, everythin in `haxe.macro.Expr` is pure syntax, so `TPath({name: \"MacroVector\", pack: [], sub: \"T\"})` is literally the same as if you'd type `MacroVector.T`, which I think will give you the same error. Try doing `TPath({name: \"T\", pack: []})`, or simply `macro : T`"}}
{"actor":{"display_login":"nadako"}}