{"action":"created","issue":{"url":"https://api.github.com/repos/eclipse/xtext-extras/issues/237","repository_url":"https://api.github.com/repos/eclipse/xtext-extras","labels_url":"https://api.github.com/repos/eclipse/xtext-extras/issues/237/labels{/name}","comments_url":"https://api.github.com/repos/eclipse/xtext-extras/issues/237/comments","events_url":"https://api.github.com/repos/eclipse/xtext-extras/issues/237/events","html_url":"https://github.com/eclipse/xtext-extras/issues/237","id":304731124,"number":237,"title":"Invalid generation of variable declarations against lambda declaration","user":{"login":"gallandarakhneorg","id":4200154,"avatar_url":"https://avatars3.githubusercontent.com/u/4200154?v=4","gravatar_id":"","url":"https://api.github.com/users/gallandarakhneorg","html_url":"https://github.com/gallandarakhneorg","followers_url":"https://api.github.com/users/gallandarakhneorg/followers","following_url":"https://api.github.com/users/gallandarakhneorg/following{/other_user}","gists_url":"https://api.github.com/users/gallandarakhneorg/gists{/gist_id}","starred_url":"https://api.github.com/users/gallandarakhneorg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gallandarakhneorg/subscriptions","organizations_url":"https://api.github.com/users/gallandarakhneorg/orgs","repos_url":"https://api.github.com/users/gallandarakhneorg/repos","events_url":"https://api.github.com/users/gallandarakhneorg/events{/privacy}","received_events_url":"https://api.github.com/users/gallandarakhneorg/received_events","type":"User","site_admin":false},"labels":[{"id":454954790,"url":"https://api.github.com/repos/eclipse/xtext-extras/labels/confirmed","name":"confirmed","color":"128a8a","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-03-13T11:45:03Z","updated_at":"2018-03-14T07:19:17Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"Let the DSL code:\r\n```xtend\r\nimport java.util.UUID\r\nclass MyClass {\r\n\tdef void fct2((UUID) => boolean lambda) {\r\n\t}\r\n\tdef void fct() {\r\n\t\tvar UUID id\r\n\t\tid = UUID.randomUUID\r\n\r\n\t\tfct2 [it == id]\r\n\t}\r\n}\r\n```\r\n\r\nThe generated Java code causes the error: `Java problem: Local variable id defined in an enclosing scope must be final or effectively final`.\r\n\r\nThe expected behavior is: no error.\r\n\r\nThe generated Java code for the `fct` function is:\r\n```java\r\nUUID id = null;\r\nid = UUID.randomUUID();\r\nfinal Function1<UUID, Boolean> _function = (UUID it) -> {\r\n   return Boolean.valueOf(Objects.equal(it, id));\r\n};\r\nthis.fct2(_function);\r\n```\r\n\r\nThe expected Java code is:\r\n```java\r\nUUID id;\r\nid = UUID.randomUUID();\r\nfinal Function1<UUID, Boolean> _function = (UUID it) -> {\r\n   return Boolean.valueOf(Objects.equal(it, id));\r\n};\r\nthis.fct2(_function);\r\n```\r\n\r\nThe initialization to `null` of the local variable `id` is invalid within the Java code.\r\nAnd, it is not expected because it is not specified into the DSL code.\r\n\r\n\r\nPossible solution: avoid the `XbaseCompiler` to generate initialization to the default value when declaring a local variable."},"comment":{"url":"https://api.github.com/repos/eclipse/xtext-extras/issues/comments/372926871","html_url":"https://github.com/eclipse/xtext-extras/issues/237#issuecomment-372926871","issue_url":"https://api.github.com/repos/eclipse/xtext-extras/issues/237","id":372926871,"user":{"login":"gallandarakhneorg","id":4200154,"avatar_url":"https://avatars3.githubusercontent.com/u/4200154?v=4","gravatar_id":"","url":"https://api.github.com/users/gallandarakhneorg","html_url":"https://github.com/gallandarakhneorg","followers_url":"https://api.github.com/users/gallandarakhneorg/followers","following_url":"https://api.github.com/users/gallandarakhneorg/following{/other_user}","gists_url":"https://api.github.com/users/gallandarakhneorg/gists{/gist_id}","starred_url":"https://api.github.com/users/gallandarakhneorg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gallandarakhneorg/subscriptions","organizations_url":"https://api.github.com/users/gallandarakhneorg/orgs","repos_url":"https://api.github.com/users/gallandarakhneorg/repos","events_url":"https://api.github.com/users/gallandarakhneorg/events{/privacy}","received_events_url":"https://api.github.com/users/gallandarakhneorg/received_events","type":"User","site_admin":false},"created_at":"2018-03-14T07:19:17Z","updated_at":"2018-03-14T07:19:17Z","author_association":"CONTRIBUTOR","body":"The DSL code is valid, and follows the rules from Java: when the variable is not initialized in the XVariableDeclaration, the variable is considered a final and could be used within lambda.\r\n\r\nBecause XBasecompiler adds the initialization into the Java code, this code becomes invalid.\r\n\r\nI agree to add specific error messages related to the usage of the variables within lambdas, but the example within the first post of this message should compile. That is not the case with the current XbaseCompiler implementation."}}
{"actor":{"display_login":"gallandarakhneorg"}}