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

Bug 352681

Summary: XBaseTypeProvider returns always void for XReturnExpression regardless of optional expression
Product: [Modeling] TMF Reporter: Ingo Meyer <ingo.meyer>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: f.quadt, ingo.meyer, sebastian.zarnekow
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Ingo Meyer CLA 2011-07-20 17:12:41 EDT
Build Identifier: 20110609-2236

In the grammar of Xbase there is an optional expression after the return keyword:

XReturnExpression returns XExpression :
	{XReturnExpression} 'return' (=>expression=XExpression)?;

But in the TypeProvider this is never evaluated:

protected JvmTypeReference _type(XReturnExpression object, boolean rawType) {
		final JvmTypeReference typeForName = getPrimitiveVoid(object);
		return typeForName;
	}

Better do it like this:

protected JvmTypeReference _type(
	final XReturnExpression object,
	final boolean rawType )
{
	final JvmTypeReference typeForName;
	if (object.getExpression() == null)
		typeForName = getPrimitiveVoid( object );
	else
		typeForName = getType( object.getExpression() );
	return typeForName;
}


Reproducible: Always
Comment 1 Sebastian Zarnekow CLA 2011-07-20 17:28:48 EDT
The type of a return expression is always void, e.g you cannot use it in an assignment like this:

var x = return 1;

The "return type" of a return expression is what you are looking for.
Comment 2 Ingo Meyer CLA 2011-07-20 17:40:29 EDT
Ah ok, thought this is something for the validation and not for the typesystem...

But what do you mean by "The "return type" of a return expression"?
Which method of the TypeProvider gives me the "wanted" type?
Comment 3 Sebastian Zarnekow CLA 2011-07-21 00:48:02 EDT
It's org.eclipse.xtext.xbase.typing.ITypeProvider.getCommonReturnType(XExpression, boolean)
Comment 4 Ingo Meyer CLA 2011-07-21 04:09:14 EDT
Thanks, that is a nice method.
Sorry for the blocker then :(
Comment 5 Sebastian Zarnekow CLA 2011-07-21 04:12:48 EDT
(In reply to comment #4)
> Sorry for the blocker then :(

No problem.
Comment 6 Karsten Thoms CLA 2017-09-19 17:36:52 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 7 Karsten Thoms CLA 2017-09-19 17:47:48 EDT
Closing all bugs that were set to RESOLVED before Neon.0