Test for sync* checks

dart2js has a bug where the sync* method entry type tests are placed in the iterator instead of the iterable.

Change-Id: Iea46c1fa31e80c6364b8405167d036cd59afcba2
Reviewed-on: https://dart-review.googlesource.com/53862
Reviewed-by: Jenny Messerly <jmesserly@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
diff --git a/tests/language_2/async_covariant_type_test.dart b/tests/language_2/async_covariant_type_test.dart
new file mode 100644
index 0000000..c619673
--- /dev/null
+++ b/tests/language_2/async_covariant_type_test.dart
@@ -0,0 +1,20 @@
+// Copyright (c) 2018, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Test that TypeErrors happen for async methods without using returned Future.
+
+import 'dart:async';
+import 'package:expect/expect.dart';
+
+class D<T> {
+  // Parametric covariance check is usually compiled into method.
+  Future<T> add(T n) async {
+    return n;
+  }
+}
+
+main() async {
+  D<num> d = new D<int>();
+  Expect.throwsTypeError(() => d.add(4.6));
+}
diff --git a/tests/language_2/async_dcall_type_test.dart b/tests/language_2/async_dcall_type_test.dart
new file mode 100644
index 0000000..b3ffbe6
--- /dev/null
+++ b/tests/language_2/async_dcall_type_test.dart
@@ -0,0 +1,30 @@
+// Copyright (c) 2018, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Test that TypeErrors happen for async methods without using returned Future.
+
+import 'dart:async';
+import 'package:expect/expect.dart';
+
+Future<int> iota(int n) async {
+  await null;
+  return n;
+}
+
+class C {
+  Future<int> add(int n) async {
+    await null;
+    return n;
+  }
+}
+
+main() async {
+  dynamic f = iota;
+  Expect.throwsTypeError(() => f('ten'));
+  Expect.throwsTypeError(() => f(4.7));
+
+  dynamic o = new C();
+  Expect.throwsTypeError(() => o.add('ten'));
+  Expect.throwsTypeError(() => o.add(4.7));
+}
diff --git a/tests/language_2/asyncstar_covariant_type_test.dart b/tests/language_2/asyncstar_covariant_type_test.dart
new file mode 100644
index 0000000..836daf0
--- /dev/null
+++ b/tests/language_2/asyncstar_covariant_type_test.dart
@@ -0,0 +1,20 @@
+// Copyright (c) 2018, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Test that TypeErrors for async* methods happen without using returned Stream.
+
+import 'dart:async';
+import 'package:expect/expect.dart';
+
+class D<T> {
+  // Parametric covariance check is usually compiled into method.
+  Stream<T> add(T n) async* {
+    yield n;
+  }
+}
+
+main() async {
+  D<num> d = new D<int>();
+  Expect.throwsTypeError(() => d.add(4.6));
+}
diff --git a/tests/language_2/asyncstar_dcall_type_test.dart b/tests/language_2/asyncstar_dcall_type_test.dart
new file mode 100644
index 0000000..1330a6d
--- /dev/null
+++ b/tests/language_2/asyncstar_dcall_type_test.dart
@@ -0,0 +1,28 @@
+// Copyright (c) 2018, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Test that TypeErrors for async* methods happen without using returned Stream.
+
+import 'dart:async';
+import 'package:expect/expect.dart';
+
+Stream<int> iota(int n) async* {
+  yield n;
+}
+
+class C {
+  Stream<int> add(int n) async* {
+    yield n;
+  }
+}
+
+main() async {
+  dynamic f = iota;
+  Expect.throwsTypeError(() => f('ten'));
+  Expect.throwsTypeError(() => f(4.7));
+
+  dynamic o = new C();
+  Expect.throwsTypeError(() => o.add('ten'));
+  Expect.throwsTypeError(() => o.add(4.7));
+}
diff --git a/tests/language_2/language_2_dart2js.status b/tests/language_2/language_2_dart2js.status
index 9a340bb..ee3ad7d 100644
--- a/tests/language_2/language_2_dart2js.status
+++ b/tests/language_2/language_2_dart2js.status
@@ -146,6 +146,8 @@
 function_type/function_type9_test: RuntimeError # Issue 30476
 function_type_alias2_test: RuntimeError
 function_type_alias4_test: RuntimeError
+syncstar_covariant_type_test: RuntimeError # dart2js misplaces check in Iterator, not Iterable.
+syncstar_dcall_type_test: RuntimeError # dart2js misplaces check in Iterator, not Iterable.
 
 [ $compiler == dart2js && $runtime == safari ]
 field_override_optimization_test: RuntimeError
@@ -532,11 +534,17 @@
 type_variable_scope_test/03: Crash # Internal Error: Unexpected type variable in static context.
 
 [ $compiler == dart2js && !$checked ]
+async_covariant_type_test: RuntimeError # checked / strong mode test
+async_dcall_type_test: RuntimeError # checked / strong mode test
+asyncstar_covariant_type_test: RuntimeError # checked / strong mode test
+asyncstar_dcall_type_test: RuntimeError # checked / strong mode test
 covariance_field_test/01: RuntimeError
 covariance_field_test/02: RuntimeError
 covariance_field_test/03: RuntimeError
 covariance_field_test/04: RuntimeError
 covariance_field_test/05: RuntimeError
+syncstar_covariant_type_test: RuntimeError # checked / strong mode test
+syncstar_dcall_type_test: RuntimeError # checked / strong mode test
 
 [ $compiler == dart2js && !$checked && !$enable_asserts ]
 assertion_test: RuntimeError, OK
diff --git a/tests/language_2/language_2_dartdevc.status b/tests/language_2/language_2_dartdevc.status
index f9327c2..b35d2ef 100644
--- a/tests/language_2/language_2_dartdevc.status
+++ b/tests/language_2/language_2_dartdevc.status
@@ -640,9 +640,11 @@
 [ $compiler == dartdevc || $compiler == dartdevk ]
 abstract_override_adds_optional_args_concrete_subclass_test: MissingCompileTimeError # Issue #30568
 abstract_override_adds_optional_args_concrete_test: MissingCompileTimeError # Issue #30568
+async_covariant_type_test: RuntimeError # Check too late
 async_star_cancel_while_paused_test: RuntimeError # Issue 29920; Uncaught Expect.listEquals(list length, expected: <4>, actual: <3>) fails: Next element <*3>
 async_star_pause_test: RuntimeError # Uncaught Expect.listEquals(at index 2, expected: <0+>, actual: <0!>) fails
 async_star_test/02: RuntimeError
+asyncstar_covariant_type_test: RuntimeError # Check too late
 asyncstar_throw_in_catch_test: Skip # Times out. Issue 29920
 bit_operations_test: RuntimeError # No bigints on web.; Expect.equals(expected: <-25>, actual: <4294967271>) fails.
 bit_operations_test/01: MissingCompileTimeError
@@ -710,8 +712,8 @@
 least_upper_bound_expansive_test/none: RuntimeError # 30908; Uncaught RangeError: Maximum call stack size exceeded
 left_shift_test: RuntimeError # Ints and doubles are unified.; Expect.equals(expected: <1>, actual: <-4294967295>) fails.
 library_env_test/has_io_support: RuntimeError, OK # Intended to fail, bool.fromEnvironment("dart.library.async") is false
-library_env_test/has_mirror_support: RuntimeError, OK  # Intended to fail, bool.fromEnvironment("dart.library.async") is false
-library_env_test/has_no_html_support: RuntimeError, OK  # Intended to fail, bool.fromEnvironment("dart.library.async") is false
+library_env_test/has_mirror_support: RuntimeError, OK # Intended to fail, bool.fromEnvironment("dart.library.async") is false
+library_env_test/has_no_html_support: RuntimeError, OK # Intended to fail, bool.fromEnvironment("dart.library.async") is false
 local_function2_test/none: RuntimeError # ReferenceError: TToNull is not defined
 local_function3_test/none: RuntimeError # Expect.equals(expected: <true>, actual: <false>) fails.
 local_function_test/none: RuntimeError # Expect.equals(expected: <true>, actual: <false>) fails.
@@ -746,6 +748,7 @@
 switch_label2_test: RuntimeError # Issue 29920; UnimplementedError: node <ShadowContinueSwitchStatement> see https://github.com/dart-lang/sdk/issues/29352 `continue #L1;
 switch_label_test: RuntimeError # Issue 29920; UnimplementedError: node <ShadowContinueSwitchStatement> see https://github.com/dart-lang/sdk/issues/29352 `continue #L1;
 switch_try_catch_test: RuntimeError # Issue 29920; Expect.throws: Unexpected 'UnimplementedError: node <ShadowContinueSwitchStatement> see https://github.com/dart-lang/sdk/issues/29352 `continue #L1;
+syncstar_covariant_type_test: RuntimeError # Check too late
 syntax_test/60: MissingCompileTimeError
 syntax_test/61: MissingCompileTimeError
 truncdiv_test: RuntimeError # Issue 29920; Expect.throws fails: Did not throw
diff --git a/tests/language_2/syncstar_covariant_type_test.dart b/tests/language_2/syncstar_covariant_type_test.dart
new file mode 100644
index 0000000..efae12a
--- /dev/null
+++ b/tests/language_2/syncstar_covariant_type_test.dart
@@ -0,0 +1,19 @@
+// Copyright (c) 2018, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Test that TypeErrors happen for sync* methods without creating iterator.
+
+import 'package:expect/expect.dart';
+
+class D<T> {
+  // Parametric covariance check is usually compiled into method.
+  Iterable<T> add(T n) sync* {
+    yield n;
+  }
+}
+
+main() {
+  D<num> d = new D<int>();
+  Expect.throwsTypeError(() => d.add(4.6));
+}
diff --git a/tests/language_2/syncstar_dcall_type_test.dart b/tests/language_2/syncstar_dcall_type_test.dart
new file mode 100644
index 0000000..5561419
--- /dev/null
+++ b/tests/language_2/syncstar_dcall_type_test.dart
@@ -0,0 +1,27 @@
+// Copyright (c) 2018, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Test that TypeErrors happen for sync* methods without creating iterator.
+
+import 'package:expect/expect.dart';
+
+Iterable<int> iota(int n) sync* {
+  for (int i = 0; i < n; i++) yield i;
+}
+
+class C {
+  Iterable<int> add(int n) sync* {
+    yield n;
+  }
+}
+
+main() {
+  dynamic f = iota;
+  Expect.throwsTypeError(() => f('ten'));
+  Expect.throwsTypeError(() => f(4.7));
+
+  dynamic o = new C();
+  Expect.throwsTypeError(() => o.add('ten'));
+  Expect.throwsTypeError(() => o.add(4.7));
+}