Dart 1.9 hints

202 views
Skip to first unread message

Adam Lofts

unread,
Mar 28, 2015, 8:21:44 AM3/28/15
to mi...@dartlang.org
I've upgraded to Dart 1.9 and am happy to see a list of new hints and warnings to fix in my codebase. Always great to have better static analysis.

I have a bit of code like this:

Iterable l;
List outer = [];
for (Object _ in l) {
  outer.add([]);
}

This code now gives a hint:

The value of the local variable '_' is not used

Is there some way to tell the analysis server that I don't expect _ to be used? I realize that I could re-factor this code to a functional style but I think it is clearest with the for - in style loop.

Andreas Kirsch

unread,
Mar 28, 2015, 8:42:11 AM3/28/15
to mi...@dartlang.org
Maybe try: List outer = new List.filled(l.length, []);

--
For other discussions, see https://groups.google.com/a/dartlang.org/
 
For HOWTO questions, visit http://stackoverflow.com/tags/dart
 
To file a bug report or feature request, go to http://www.dartbug.com/new

To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.



--
Why is this e-mail so short? Answer: five.sentenc.es.

Jos Hirth

unread,
Mar 28, 2015, 10:24:07 AM3/28/15
to mi...@dartlang.org
On Saturday, March 28, 2015 at 1:42:11 PM UTC+1, Andreas Kirsch wrote:
Maybe try: List outer = new List.filled(l.length, []);

That would create a list filled with references to one particular list. The `List.generate` constructor does what you want.

Daniel Rubel

unread,
Mar 31, 2015, 9:52:19 AM3/31/15
to General Dart Discussion
It is a very common idiom to use '_' as a var name when a var name is required but ignored.
I think we need to enhance/fix the analyzer.

https://code.google.com/p/dart/issues/detail?id=23050
 

Filipe Morgado

unread,
Mar 31, 2015, 1:01:12 PM3/31/15
to mi...@dartlang.org
+1
Reply all
Reply to author
Forward
0 new messages