Fix analyzer warning / bug: Iterable was treated as if it has sublist()

R=sgjesse@google.com

Review URL: https://chromiumcodereview.appspot.com//1024553002
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c1d564d..0ab91dd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,6 @@
+## 0.3.5+3
+ * Bugfix for `setRange()`: Do not assume Iterable has a `sublist()` method.
+
 ## 0.3.5+2
  * Simplify some types used in is checks and correct PbList to match the
  * signature of the List setRange method.
diff --git a/lib/src/protobuf/pb_list.dart b/lib/src/protobuf/pb_list.dart
index e2b518d..46644e5 100644
--- a/lib/src/protobuf/pb_list.dart
+++ b/lib/src/protobuf/pb_list.dart
@@ -88,7 +88,9 @@
    * not extendable.
    */
   void setRange(int start, int end, Iterable<E> from, [int skipCount = 0]) {
-    from.sublist(skipCount, skipCount + end - start).forEach(_validate);
+    // NOTE: In case `take()` returns less than `end - start` elements, the
+    // _wrappedList will fail with a `StateError`.
+    from.skip(skipCount).take(end - start).forEach(_validate);
     _wrappedList.setRange(start, end, from, skipCount);
   }
 
diff --git a/pubspec.yaml b/pubspec.yaml
index 6e9c38e..9950f51 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
 name: protobuf
-version: 0.3.5+2
+version: 0.3.5+3
 author: Dart Team <misc@dartlang.org>
 description: Runtime library for protobuf support.
 homepage: https://github.com/dart-lang/dart-protobuf
diff --git a/test/pb_list_test.dart b/test/pb_list_test.dart
index 40a5b53..ce9fa09 100755
--- a/test/pb_list_test.dart
+++ b/test/pb_list_test.dart
@@ -61,6 +61,21 @@
     lb2.removeRange(5, 8);
     expect(lb2, [1, 2, 3, 9, 8, 9]);
 
+    expect(() => lb2.setRange(5, 7, [88, 99].take(2)), throwsRangeError);
+    expect(lb2, [1, 2, 3, 9, 8, 9]);
+
+    expect(() => lb2.setRange(5, 7, [88, 99].take(2), 1), throwsRangeError);
+    expect(lb2, [1, 2, 3, 9, 8, 9]);
+
+    expect(() => lb2.setRange(4, 6, [88, 99].take(1), 1), throwsStateError);
+    expect(lb2, [1, 2, 3, 9, 8, 9]);
+
+    lb2.setRange(5, 6, [88, 99].take(2));
+    expect(lb2, [1, 2, 3, 9, 8, 88]);
+
+    lb2.setRange(5, 6, [88, 99].take(2), 1);
+    expect(lb2, [1, 2, 3, 9, 8, 99]);
+
     expect(() { (new PbList<int>() as dynamic).add('hello'); }, throws);
 
     PbSint32List listSint32 = new PbSint32List();