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

Bug 365712

Summary: [xtend] Unused local vars in for loops not recognized
Product: [Tools] Xtend Reporter: Sebastian Zarnekow <sebastian.zarnekow>
Component: CoreAssignee: Jan Koehnlein <jan>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P3 CC: jan, sven.efftinge
Version: 2.2.0   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:
Bug Depends on: 363685    
Bug Blocks:    

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.