Migrate samples/sample_extension to null safety
Closes https://github.com/dart-lang/sdk/issues/43711
Change-Id: I7628e4a6192efb26a12f8051b4fa87dfafabab9c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/180960
Reviewed-by: RĂ©gis Crelier <regis@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
diff --git a/samples/sample_extension/sample_asynchronous_extension.dart b/samples/sample_extension/sample_asynchronous_extension.dart
index 541652d..7d18902 100644
--- a/samples/sample_extension/sample_asynchronous_extension.dart
+++ b/samples/sample_extension/sample_asynchronous_extension.dart
@@ -2,8 +2,6 @@
// 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.9
-
library sample_asynchronous_extension;
import 'dart:async';
@@ -12,15 +10,12 @@
// A class caches the native port used to call an asynchronous extension.
class RandomArray {
- static SendPort _port;
+ static SendPort? _port;
Future<List<int>> randomArray(int seed, int length) {
var completer = new Completer<List<int>>();
var replyPort = new RawReceivePort();
- var args = new List(3);
- args[0] = seed;
- args[1] = length;
- args[2] = replyPort.sendPort;
+ var args = [seed, length, replyPort.sendPort];
_servicePort.send(args);
replyPort.handler = (result) {
replyPort.close();
@@ -37,7 +32,7 @@
if (_port == null) {
_port = _newServicePort();
}
- return _port;
+ return _port!;
}
SendPort _newServicePort() native "RandomArray_ServicePort";
diff --git a/samples/sample_extension/sample_synchronous_extension.dart b/samples/sample_extension/sample_synchronous_extension.dart
index e5ad660..727cd4c 100644
--- a/samples/sample_extension/sample_synchronous_extension.dart
+++ b/samples/sample_extension/sample_synchronous_extension.dart
@@ -2,8 +2,6 @@
// 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.9
-
library sample_synchronous_extension;
import 'dart-ext:sample_extension';
diff --git a/samples/sample_extension/test/sample_extension_app_snapshot_test.dart b/samples/sample_extension/test/sample_extension_app_snapshot_test.dart
index b2eb204..558b108 100644
--- a/samples/sample_extension/test/sample_extension_app_snapshot_test.dart
+++ b/samples/sample_extension/test/sample_extension_app_snapshot_test.dart
@@ -4,8 +4,6 @@
//
// Dart test program for testing native extensions.
-// @dart = 2.9
-
// OtherResources=../sample_synchronous_extension.dart
// OtherResources=../sample_asynchronous_extension.dart
// OtherResources=../test_sample_synchronous_extension.dart
diff --git a/samples/sample_extension/test/sample_extension_test.dart b/samples/sample_extension/test/sample_extension_test.dart
index 393463b..4311ff5 100644
--- a/samples/sample_extension/test/sample_extension_test.dart
+++ b/samples/sample_extension/test/sample_extension_test.dart
@@ -4,8 +4,6 @@
//
// Dart test program for testing native extensions.
-// @dart = 2.9
-
import 'sample_extension_test_helper.dart';
void main() {
diff --git a/samples/sample_extension/test/sample_extension_test_helper.dart b/samples/sample_extension/test/sample_extension_test_helper.dart
index 9c701bf..d4cae3d 100644
--- a/samples/sample_extension/test/sample_extension_test_helper.dart
+++ b/samples/sample_extension/test/sample_extension_test_helper.dart
@@ -4,8 +4,6 @@
//
// Dart test program for testing native extensions.
-// @dart = 2.9
-
import 'dart:async';
import 'dart:io';
import 'dart:isolate';
@@ -26,7 +24,7 @@
result = await Process.run('cmd.exe', ['/C', 'copy $src $dst']);
break;
default:
- Expect.fail('Unknown operating system ${Platform.operatingSystem}');
+ throw 'Unknown operating system ${Platform.operatingSystem}';
}
if (result.exitCode != 0) {
print(result.stdout);
@@ -46,7 +44,7 @@
}
}
-Future testNativeExtensions(String snapshotKind) async {
+Future testNativeExtensions(String? snapshotKind) async {
String buildDirectory = dirname(Platform.executable);
Directory tempDirectory =
Directory.systemTemp.createTempSync('sample_extension_');
diff --git a/samples/sample_extension/test_sample_asynchronous_extension.dart b/samples/sample_extension/test_sample_asynchronous_extension.dart
index 5ceb7c8..b1fd419 100644
--- a/samples/sample_extension/test_sample_asynchronous_extension.dart
+++ b/samples/sample_extension/test_sample_asynchronous_extension.dart
@@ -2,8 +2,6 @@
// 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.9
-
library test_sample_extension;
import 'sample_asynchronous_extension.dart';
@@ -32,16 +30,16 @@
void checkNormal(List l) {
// Count how many times each byte value occurs. Assert that the counts
// are all within a reasonable (six-sigma) range.
- List counts = new List<int>.filled(256, 0);
+ List<int> counts = new List<int>.filled(256, 0);
for (var e in l) {
counts[e]++;
}
new RandomArray().randomArray(18, 256000).then(checkCorrelation(counts));
}
-Function checkCorrelation(List counts) {
- return (List l) {
- List counts_2 = new List<int>.filled(256, 0);
+dynamic Function(List<int>) checkCorrelation(List<int> counts) {
+ return (List<int> l) {
+ List<int> counts_2 = new List<int>.filled(256, 0);
for (var e in l) {
counts_2[e]++;
}
diff --git a/samples/sample_extension/test_sample_synchronous_extension.dart b/samples/sample_extension/test_sample_synchronous_extension.dart
index 77d2fc3..ac17724 100644
--- a/samples/sample_extension/test_sample_synchronous_extension.dart
+++ b/samples/sample_extension/test_sample_synchronous_extension.dart
@@ -2,8 +2,6 @@
// 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.9
-
library test_sample_extension;
import 'sample_synchronous_extension.dart';