Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 365712 - [xtend] Unused local vars in for loops not recognized
Summary: [xtend] Unused local vars in for loops not recognized
Status: NEW
Alias: None
Product: Xtend
Classification: Tools
Component: Core (show other bugs)
Version: 2.2.0   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Jan Koehnlein CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 363685
Blocks:
  Show dependency tree
 
Reported: 2011-12-06 07:12 EST by Sebastian Zarnekow CLA
Modified: 2014-11-13 07:23 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sebastian Zarnekow CLA 2011-12-06 07:12:12 EST
for(c: s.toCharArray) {
}

I'd expect a warning like 'The value of 'c' is never used'
Comment 1 Sven Efftinge CLA 2012-01-31 05:51:22 EST
This should wait until we have configurable severities.
Comment 2 Jan Koehnlein CLA 2014-11-04 05:21:20 EST
Also applies to switch parameters.

Pushed to review.
Comment 3 Sven Efftinge CLA 2014-11-04 08:48:05 EST
A quick offline discussion revealed the following thoughts:
A 'for' loop doesn't leave the user the option to declare a variable or not. So in case you want to iterate and don't use the variable you cannot easily get rid of the warning. Support for @SuppressWarnings would help but still it is questionable which practical programming problems could be revealed by this.

Generally speaking the validation of the foreach-loop var seems to be more similar to the 'unused parameters' validation when implementing methods as the regular 'unsed local vars' validation.

Therefore we decided to not have that warning, at least until we have full support for @SuppressWarnings.

But still we should do it for 'switch' and 'traditional for' as there you have the choice.
Comment 4 Sebastian Zarnekow CLA 2014-11-04 08:54:25 EST
+1

Unused locals in for-each and catch clauses deserve an own issue code with the same message. The preference page should have a checkbox like 'also mark in for-each loops and ..'.
Without SuppressWarnings it's not too useful, though.
Comment 5 Jan Koehnlein CLA 2014-11-04 09:44:04 EST
Pushed changes for switch only.