{"action":"created","issue":{"url":"https://api.github.com/repos/cincheo/jsweet/issues/198","repository_url":"https://api.github.com/repos/cincheo/jsweet","labels_url":"https://api.github.com/repos/cincheo/jsweet/issues/198/labels{/name}","comments_url":"https://api.github.com/repos/cincheo/jsweet/issues/198/comments","events_url":"https://api.github.com/repos/cincheo/jsweet/issues/198/events","html_url":"https://github.com/cincheo/jsweet/issues/198","id":196510166,"number":198,"title":"Expression expected when creating new generic instance of jsweet.lang.Array","user":{"login":"chrismiddleton","id":6965252,"avatar_url":"https://avatars2.githubusercontent.com/u/6965252?v=4","gravatar_id":"","url":"https://api.github.com/users/chrismiddleton","html_url":"https://github.com/chrismiddleton","followers_url":"https://api.github.com/users/chrismiddleton/followers","following_url":"https://api.github.com/users/chrismiddleton/following{/other_user}","gists_url":"https://api.github.com/users/chrismiddleton/gists{/gist_id}","starred_url":"https://api.github.com/users/chrismiddleton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrismiddleton/subscriptions","organizations_url":"https://api.github.com/users/chrismiddleton/orgs","repos_url":"https://api.github.com/users/chrismiddleton/repos","events_url":"https://api.github.com/users/chrismiddleton/events{/privacy}","received_events_url":"https://api.github.com/users/chrismiddleton/received_events","type":"User","site_admin":false},"labels":[{"id":198570991,"url":"https://api.github.com/repos/cincheo/jsweet/labels/bug","name":"bug","color":"fc2929","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-12-19T20:16:17Z","updated_at":"2017-07-24T15:07:33Z","closed_at":"2017-07-24T15:07:33Z","body":"I was getting an error of \"expression expected\" in my code and could not find any issue with the Java itself. When trying to make a MWE of the problem, I managed to get this to fail:\r\n\r\nThe following code gives an error during (I think) the TypeScript compilation phase:\r\n\r\n\timport jsweet.lang.Array;\r\n\r\n\tpublic class Vector<E> {\r\n\r\n\t\tclass ArrayEnumeration<E> {\r\n\t\t\tprivate Array<E> a;\r\n\t\t\tprivate int s;\r\n\t\t\tpublic ArrayEnumeration (Array<E> a, int s) {\r\n\t\t\t}\r\n\t\t\tpublic void print () {\r\n\t\t\t\tSystem.out.println(a.$get(0));\r\n\t\t\t}\r\n\t\t}\r\n\t\r\n\t\tprivate Array<E> arr;\r\n\t\tprivate int size;\r\n\t\r\n\t\tpublic Vector () {\r\n\t\t\tarr = new Array<>();\r\n\t\t\tsize++;\r\n\t\t}\r\n\t\r\n\t\tpublic void add (E e) {\r\n\t\t\tarr.push(e);\r\n\t\t}\r\n\t\r\n\t\tpublic void demo () {\r\n\t\t\tArrayEnumeration<E> ae = elements();\r\n\t\t\tae.print();\r\n\t\t}\r\n\t\r\n\t\tpublic ArrayEnumeration<E> elements () {\r\n\t\t\treturn new ArrayEnumeration<E>(new Array<E>(arr.slice()), size);\r\n\t\t}\r\n\t\r\n\t\tpublic static void main () {\r\n\t\t\tVector v = new Vector<String>();\r\n\t\t\tv.add(\"Hello, world\");\r\n\t\t\tv.demo();\r\n\t\t}\r\n\t\r\n\t}\r\n\r\nIf you run the above in the jsweet sandbox, you'll see what I mean.\r\n\r\nThe error message is also a little confusing, as it gives the error line as the line that the class itself starts on, whereas the error appears to originate on this line, when running the output through the TypeScript compiler:\r\n\r\n    return new ArrayEnumeration<E>(new Array<E>(arr.slice()), size);\r\n\r\nThe resulting TypeScript looks similar to this:\r\n\r\n                return <any>(new Vector.ArrayEnumeration<E>(this, <any>new (__Function.prototype.bind.apply(Array<E>, [null].concat(<any[]>this.arr.slice()))), this.sz));\r\n\r\n\r\nThe error says that there should be an expression after \"Array<E>\" (the one in the .bind.apply part).\r\n\r\n** UPDATE **\r\n\r\nI discovered that the problem occurs when trying to create a new generic instance with a non-empty diamond operator. That is, `new Array<E>(...)` gives an error but `new Array<>(...)` doesn't. So I have a workaround - maybe it's an issue in the Java to TS transpiler portion? Or something that TS should accept maybe?"},"comment":{"url":"https://api.github.com/repos/cincheo/jsweet/issues/comments/317453384","html_url":"https://github.com/cincheo/jsweet/issues/198#issuecomment-317453384","issue_url":"https://api.github.com/repos/cincheo/jsweet/issues/198","id":317453384,"user":{"login":"renaudpawlak","id":6288061,"avatar_url":"https://avatars1.githubusercontent.com/u/6288061?v=4","gravatar_id":"","url":"https://api.github.com/users/renaudpawlak","html_url":"https://github.com/renaudpawlak","followers_url":"https://api.github.com/users/renaudpawlak/followers","following_url":"https://api.github.com/users/renaudpawlak/following{/other_user}","gists_url":"https://api.github.com/users/renaudpawlak/gists{/gist_id}","starred_url":"https://api.github.com/users/renaudpawlak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/renaudpawlak/subscriptions","organizations_url":"https://api.github.com/users/renaudpawlak/orgs","repos_url":"https://api.github.com/users/renaudpawlak/repos","events_url":"https://api.github.com/users/renaudpawlak/events{/privacy}","received_events_url":"https://api.github.com/users/renaudpawlak/received_events","type":"User","site_admin":false},"created_at":"2017-07-24T15:07:33Z","updated_at":"2017-07-24T15:07:33Z","body":"Actually testing with the current version, I have not been able to reproduce that bug, simply because ``new Array<E>(arr.slice())`` does not compile in Java. It makes sense to me, so maybe it was a flaw in the v1 API. I have added [your code as a test](https://github.com/cincheo/jsweet/blob/master/transpiler/src/test/java/source/generics/SliceOfArrays.java), so you can check it it makes sense to you too... I am closing this bug (to be reopened if not fixed in v2)."}}
{"actor":{"display_login":"renaudpawlak"}}