Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 355781

Summary: [xbase] "return" are not correctly handled in expression blocks (if, try, etc)
Product: [Modeling] TMF Reporter: Daniel Simoes <ddsimoes>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: sebastian.zarnekow, sven.efftinge
Version: unspecifiedFlags: sven.efftinge: indigo+
Target Milestone: SR2   
Hardware: All   
OS: All   
Whiteboard:

Description Daniel Simoes CLA 2011-08-24 21:17:40 EDT
Build Identifier: I20110613-1736

The following code works as expected:

    print(if (true) {"true"} else {"false"})

And is generated as:

	public static void main(String[] args) {
		
		String _xifexpression = null;
		if (true) {
		  _xifexpression = "true";
		} else {
		  _xifexpression = "false";
		}
		InputOutput.<String>print(_xifexpression);
	}


but, the following code doesn't work:

    print(if (true) {return "true"} else {"false"})


as it generate this code:

	public static void main(String[] args) {
		
		String _xifexpression = null;
		if (true) {
		  return "true";
		} else {
		  _xifexpression = "false";
		}
		InputOutput.<String>print(_xifexpression);
	}



Reproducible: Always

Steps to Reproduce:
print(if (true) {return "true"} else {"false"})
Comment 1 Daniel Simoes CLA 2011-08-24 21:22:57 EDT
Just to be clear
Comment 2 Sebastian Zarnekow CLA 2011-08-25 03:37:26 EDT
I would expect an error marker on the return expression in a context that expects void as the return type. Daniel, does that meet your expectation, too?
Comment 3 Sven Efftinge CLA 2011-08-25 03:44:36 EDT
Agree if the context is void, but that's not clear for me since Daniel only posted the expression not the context. 
But it looks like he's referring to PureXbase, which should expect void but doesn't.
So this might be a bug in PureXbase.
Comment 4 Daniel Simoes CLA 2011-08-25 09:13:20 EDT
Yes, it was in the PureXBase. I typed the expression in a .xbase file in the XBase demo project, that comes with XText.
Comment 5 Sven Efftinge CLA 2011-08-25 09:23:09 EDT
Rather than expecting void in the type provider I think we should generate into a method with the return type Object. That way people will be able to play around with return expressions as well.
Comment 6 Sven Efftinge CLA 2011-08-25 09:35:14 EDT
pushed to master
Comment 7 Karsten Thoms CLA 2017-09-19 17:17:13 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 8 Karsten Thoms CLA 2017-09-19 17:28:34 EDT
Closing all bugs that were set to RESOLVED before Neon.0