[dart2js] Fix type of RandomAccessFileOutputProvider.onFailure.
Issue: #48820
Change-Id: I62e182a5fd974a5dc488c3dc1b08ff8c1aaae9d1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352781
Reviewed-by: Nate Biggs <natebiggs@google.com>
diff --git a/pkg/compiler/lib/src/source_file_provider.dart b/pkg/compiler/lib/src/source_file_provider.dart
index c216b54..ec4cf3b 100644
--- a/pkg/compiler/lib/src/source_file_provider.dart
+++ b/pkg/compiler/lib/src/source_file_provider.dart
@@ -310,7 +310,8 @@
toString() => 'Aborted due to --throw-on-error: $message';
}
-typedef MessageCallback = void Function(String message);
+typedef OnInfo = void Function(String message);
+typedef OnFailure = Never Function(String message);
class RandomAccessFileOutputProvider implements api.CompilerOutput {
// The file name to use for the main output. Also used as the filename prefix
@@ -318,11 +319,8 @@
// primary output but can still write other files.
final Uri? out;
final Uri? sourceMapOut;
- final MessageCallback onInfo;
-
- // TODO(48820): Make [onFailure] return `Never`. The value passed in for the
- // real compiler exits. [onFailure] is not specified or faked in some tests.
- final MessageCallback onFailure;
+ final OnInfo onInfo;
+ final OnFailure onFailure;
int totalCharactersWritten = 0;
int totalCharactersWrittenPrimary = 0;
@@ -332,9 +330,7 @@
List<String> allOutputFiles = <String>[];
RandomAccessFileOutputProvider(this.out, this.sourceMapOut,
- {this.onInfo = _ignore, this.onFailure = _ignore});
-
- static void _ignore(String message) {}
+ {required this.onInfo, required this.onFailure});
Uri createUri(String name, String extension, api.OutputType type) {
Uri uri;
@@ -400,8 +396,6 @@
.openSync(mode: FileMode.write);
} on FileSystemException catch (e) {
onFailure('$e');
- // TODO(48820): Make onFailure return `Never`
- throw StateError('unreachable');
}
allOutputFiles.add(fe.relativizeUri(Uri.base, uri, Platform.isWindows));
@@ -436,8 +430,6 @@
.openSync(mode: FileMode.write);
} on FileSystemException catch (e) {
onFailure('$e');
- // TODO(48820): Make `onFailure` return `Never`.
- throw StateError('unreachable');
}
void onClose(int bytesWritten) {
diff --git a/pkg/compiler/test/sourcemaps/helpers/sourcemap_helper.dart b/pkg/compiler/test/sourcemaps/helpers/sourcemap_helper.dart
index d325b7f..fecff04 100644
--- a/pkg/compiler/test/sourcemaps/helpers/sourcemap_helper.dart
+++ b/pkg/compiler/test/sourcemaps/helpers/sourcemap_helper.dart
@@ -72,7 +72,12 @@
RandomAccessFileOutputProvider outputProvider;
CloningOutputProvider(Uri jsUri, Uri jsMapUri)
- : outputProvider = RandomAccessFileOutputProvider(jsUri, jsMapUri);
+ : outputProvider = RandomAccessFileOutputProvider(jsUri, jsMapUri,
+ onInfo: _ignore, onFailure: _fail);
+
+ static void _ignore(String message) {}
+
+ static Never _fail(String message) => throw StateError('unreachable');
@override
api.OutputSink createOutputSink(