Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 350576 - Check for pure expressions in "side-effects"-only context
Summary: Check for pure expressions in "side-effects"-only context
Status: CLOSED FIXED
Alias: None
Product: Xtend
Classification: Tools
Component: Core (show other bugs)
Version: 2.2.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: RC2   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-28 09:13 EDT by Dietmar Stoll CLA
Modified: 2017-10-31 10:58 EDT (History)
2 users (show)

See Also:
sven.efftinge: juno+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dietmar Stoll CLA 2011-06-28 09:13:47 EDT
Build Identifier: 

Maybe a warning or an error should be issued for the following

xtend file:

override void doGenerate(Resource resource, IFileSystemAccess fsa) {
    generate(resource, fsa)
    "returns a string but void is return type"
}

generated Java code:

  public void doGenerate(final Resource resource, final IFileSystemAccess fsa) throws RuntimeException {
    {
      this.generate(resource, fsa);/*"returns a string but void is return type"*/;
    }
  }        

expected: no generated Java code with error or a warning message

I am using Xtext/Xtend 2.0.1.v201106261503

Reproducible: Always
Comment 1 Sven Efftinge CLA 2012-01-31 06:09:30 EST
The Xtend code and the generated Java code looks good to me. Why do you think it should result in a validation error?
Comment 2 Sebastian Zarnekow CLA 2012-01-31 06:15:30 EST
I think there is already a warniong for expressions which don't cause any side effects but it is not triggered for the last expression, e.g.

def void foo2() {
	"first"
	"second"
}

"first" will be flagged with 
"The expression does not cause any side effects and therefore doesn't do anything in this context."
Comment 3 Dietmar Stoll CLA 2012-01-31 10:40:31 EST
Thanks for looking into this. Sven, in my example, the user's last expression returns a string, but he erroneously declared the method to return "void" instead of "String".

Sebastian, I agree. I would consider the issue fixed if the warning "The expression does not cause any side effects and therefore doesn't do anything in this context." was also triggered on the last expression.
Comment 4 Sven Efftinge CLA 2012-05-23 03:17:53 EDT
pushed to master
Comment 5 Eclipse Webmaster CLA 2017-10-31 10:47:38 EDT
Requested via bug 522520.

-M.
Comment 6 Eclipse Webmaster CLA 2017-10-31 10:58:41 EDT
Requested via bug 522520.

-M.