[cfe] Add test for issue42607

This verifies that we no longer emit spurious errors/warnings in opted out
libraries when trying to compile with sound null safety.

Closes #42607

Change-Id: I89063003fb5140d9cd0a3ce937017976e2fdd1c7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169740
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
diff --git a/pkg/front_end/testcases/nnbd/issue42607.dart b/pkg/front_end/testcases/nnbd/issue42607.dart
new file mode 100644
index 0000000..91f7d49
--- /dev/null
+++ b/pkg/front_end/testcases/nnbd/issue42607.dart
@@ -0,0 +1,13 @@
+// Copyright (c) 2020, 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.
+
+// @dart = 2.6
+
+test() {
+  int x = 3;
+  x?.isEven;
+  x = null;
+}
+
+main() {}
diff --git a/pkg/front_end/testcases/nnbd/issue42607.dart.outline.expect b/pkg/front_end/testcases/nnbd/issue42607.dart.outline.expect
new file mode 100644
index 0000000..67a3569
--- /dev/null
+++ b/pkg/front_end/testcases/nnbd/issue42607.dart.outline.expect
@@ -0,0 +1,14 @@
+library;
+//
+// Problems in library:
+//
+// pkg/front_end/testcases/nnbd/issue42607.dart:5:1: Error: A library can't opt out of null safety by default, when using sound null safety.
+// // @dart = 2.6
+// ^^^^^^^^^^^^^^
+//
+import self as self;
+
+static method test() → dynamic
+  ;
+static method main() → dynamic
+  ;
diff --git a/pkg/front_end/testcases/nnbd/issue42607.dart.strong.expect b/pkg/front_end/testcases/nnbd/issue42607.dart.strong.expect
new file mode 100644
index 0000000..f1a2bdd
--- /dev/null
+++ b/pkg/front_end/testcases/nnbd/issue42607.dart.strong.expect
@@ -0,0 +1,17 @@
+library;
+//
+// Problems in library:
+//
+// pkg/front_end/testcases/nnbd/issue42607.dart:5:1: Error: A library can't opt out of null safety by default, when using sound null safety.
+// // @dart = 2.6
+// ^^^^^^^^^^^^^^
+//
+import self as self;
+import "dart:core" as core;
+
+static method test() → dynamic {
+  core::int* x = 3;
+  let final core::int* #t1 = x in #t1.{core::num::==}(null) ?{core::bool*} null : #t1.{core::int::isEven};
+  x = null;
+}
+static method main() → dynamic {}
diff --git a/pkg/front_end/testcases/nnbd/issue42607.dart.strong.transformed.expect b/pkg/front_end/testcases/nnbd/issue42607.dart.strong.transformed.expect
new file mode 100644
index 0000000..f1a2bdd
--- /dev/null
+++ b/pkg/front_end/testcases/nnbd/issue42607.dart.strong.transformed.expect
@@ -0,0 +1,17 @@
+library;
+//
+// Problems in library:
+//
+// pkg/front_end/testcases/nnbd/issue42607.dart:5:1: Error: A library can't opt out of null safety by default, when using sound null safety.
+// // @dart = 2.6
+// ^^^^^^^^^^^^^^
+//
+import self as self;
+import "dart:core" as core;
+
+static method test() → dynamic {
+  core::int* x = 3;
+  let final core::int* #t1 = x in #t1.{core::num::==}(null) ?{core::bool*} null : #t1.{core::int::isEven};
+  x = null;
+}
+static method main() → dynamic {}
diff --git a/pkg/front_end/testcases/nnbd/issue42607.dart.textual_outline.expect b/pkg/front_end/testcases/nnbd/issue42607.dart.textual_outline.expect
new file mode 100644
index 0000000..5cf5db8
--- /dev/null
+++ b/pkg/front_end/testcases/nnbd/issue42607.dart.textual_outline.expect
@@ -0,0 +1,3 @@
+// @dart = 2.6
+test() {}
+main() {}
diff --git a/pkg/front_end/testcases/nnbd/issue42607.dart.textual_outline_modelled.expect b/pkg/front_end/testcases/nnbd/issue42607.dart.textual_outline_modelled.expect
new file mode 100644
index 0000000..94295cd
--- /dev/null
+++ b/pkg/front_end/testcases/nnbd/issue42607.dart.textual_outline_modelled.expect
@@ -0,0 +1,3 @@
+// @dart = 2.6
+main() {}
+test() {}
diff --git a/pkg/front_end/testcases/nnbd/issue42607.dart.weak.expect b/pkg/front_end/testcases/nnbd/issue42607.dart.weak.expect
new file mode 100644
index 0000000..2678d44
--- /dev/null
+++ b/pkg/front_end/testcases/nnbd/issue42607.dart.weak.expect
@@ -0,0 +1,10 @@
+library;
+import self as self;
+import "dart:core" as core;
+
+static method test() → dynamic {
+  core::int* x = 3;
+  let final core::int* #t1 = x in #t1.{core::num::==}(null) ?{core::bool*} null : #t1.{core::int::isEven};
+  x = null;
+}
+static method main() → dynamic {}
diff --git a/pkg/front_end/testcases/nnbd/issue42607.dart.weak.transformed.expect b/pkg/front_end/testcases/nnbd/issue42607.dart.weak.transformed.expect
new file mode 100644
index 0000000..2678d44
--- /dev/null
+++ b/pkg/front_end/testcases/nnbd/issue42607.dart.weak.transformed.expect
@@ -0,0 +1,10 @@
+library;
+import self as self;
+import "dart:core" as core;
+
+static method test() → dynamic {
+  core::int* x = 3;
+  let final core::int* #t1 = x in #t1.{core::num::==}(null) ?{core::bool*} null : #t1.{core::int::isEven};
+  x = null;
+}
+static method main() → dynamic {}