Bug 442317 - Multiple name declarations with a single var or val statement
Summary: Multiple name declarations with a single var or val statement
Status: NEW
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: triaged
Depends on:
Blocks:
 
Reported: 2014-08-21 15:41 EDT by Stephane Galland CLA
Modified: 2016-10-14 06:03 EDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephane Galland CLA 2014-08-21 15:41:49 EDT
Is it relevant to enable multiple name declaration with a single "var" or "val" statement?

For example:  var String a, b



The grammar rule could be update to:

    XVariableDeclaration returns XExpression:
	{XVariableDeclaration}
	(writeable?='var'|'val')
        names+=XVariableDeclarationUnit
	(',' names+=XVariableDeclarationUnit)*
    ;

    XVariableDeclarationUnit:
	(=>(name=ValidID ':' type=JvmTypeReference) | name=ValidID)
	('=' right=XExpression)?
    ;
Comment 1 Christian Dietrich CLA 2016-08-25 04:08:20 EDT
*** Bug 404140 has been marked as a duplicate of this bug. ***
Comment 2 Christian Dietrich CLA 2016-08-25 04:09:01 EDT
same for members in xtend classes
Comment 3 Lorenzo Bettini CLA 2016-08-25 06:54:29 EDT
I did something similar for Jbase, so I can work on that, but in September. 

The proposed change, though, would break existing languages. I implemented that using additional declarations, reusing the same type.
Comment 4 Lorenzo Bettini CLA 2016-10-14 03:37:32 EDT
I could work on that in the near future, but I'd like to know which form should we implement:

val {type} {i} = {e}, {type} {i} = {e}, ...

or

val {type} {i} = {2}, {i} = {e}, ...

I mean, should the declared type optionally appear only in the first declaration, or also in the other declarations?

If no type is declared, should the following declarations respect the inferred type of the first declaration?

Other ideas?
Comment 5 Stephane Galland CLA 2016-10-14 06:03:29 EDT
My opinion is if the type is specified, it should be applied to the following declarations.

For example:
    var int a = 45, b = 47

means that a and b are both int.

    var a = 45, b = 45.0

means that the types of a and b are inferred from the expressions.


I'm not convince about the specification of the type in the comma list, e.g.:
    var int a = 45, double b = 47

I think it include less readable code.