Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 352681 - XBaseTypeProvider returns always void for XReturnExpression regardless of optional expression
Summary: XBaseTypeProvider returns always void for XReturnExpression regardless of opt...
Status: CLOSED WONTFIX
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-20 17:12 EDT by Ingo Meyer CLA
Modified: 2017-09-19 17:47 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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