Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
[flutter_tools] No more implicit --no-sound-null-safety (#118491)
Browse files Browse the repository at this point in the history
* remove implicit no-sound-null-safety

* add test

* bump sdk constraint in test file
  • Loading branch information
christopherfujino authored Jan 18, 2023
1 parent 8a58ec5 commit 374f09e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
10 changes: 5 additions & 5 deletions packages/flutter_tools/lib/src/resident_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,8 @@ class FlutterDevice {
required Platform platform,
TargetModel targetModel = TargetModel.flutter,
List<String>? experimentalFlags,
ResidentCompiler? generator,
String? userIdentifier,
}) async {
ResidentCompiler generator;
final TargetPlatform targetPlatform = await device.targetPlatform;
if (device.platformType == PlatformType.fuchsia) {
targetModel = TargetModel.flutterRunner;
Expand All @@ -111,6 +109,8 @@ class FlutterDevice {
fileSystem: globals.fs,
);

final ResidentCompiler generator;

// For both web and non-web platforms we initialize dill to/from
// a shared location for faster bootstrapping. If the compiler fails
// due to a kernel target or version mismatch, no error is reported
Expand All @@ -119,7 +119,7 @@ class FlutterDevice {
// used to file a bug, but the compiler will still start up correctly.
if (targetPlatform == TargetPlatform.web_javascript) {
// TODO(zanderso): consistently provide these flags across platforms.
late String platformDillName;
final String platformDillName;
final List<String> extraFrontEndOptions = List<String>.of(buildInfo.extraFrontEndOptions);
if (buildInfo.nullSafetyMode == NullSafetyMode.unsound) {
platformDillName = 'ddc_outline.dill';
Expand All @@ -132,12 +132,12 @@ class FlutterDevice {
extraFrontEndOptions.add('--sound-null-safety');
}
} else {
assert(false);
throw StateError('Expected buildInfo.nullSafetyMode to be one of unsound or sound, got ${buildInfo.nullSafetyMode}');
}

final String platformDillPath = globals.fs.path.join(
getWebPlatformBinariesDirectory(globals.artifacts!, buildInfo.webRenderer).path,
platformDillName
platformDillName,
);

generator = ResidentCompiler(
Expand Down
6 changes: 5 additions & 1 deletion packages/flutter_tools/lib/src/runner/flutter_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,11 @@ abstract class FlutterCommand extends Command<void> {
(languageVersion.major == nullSafeVersion.major && languageVersion.minor >= nullSafeVersion.minor)) {
nullSafetyMode = NullSafetyMode.sound;
} else {
nullSafetyMode = NullSafetyMode.unsound;
throwToolExit(
'This application does not support sound null-safety (its language version is $languageVersion).\n'
'To build this application, you must provide the CLI flag --no-sound-null-safety. Dart 3 will only '
'support sound null safety, see https://dart.dev/null-safety.',
);
}
} else if (!wasNullSafetyFlagParsed) {
// This mode is only used for commands which do not build a single target like
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,27 @@ void main() {
ProcessManager: () => processManager,
});

testUsingContext('tool exits on non-sound-null-safe code when explicit flag not passed', () async {
final DummyFlutterCommand flutterCommand = DummyFlutterCommand(packagesPath: 'foo');
flutterCommand.argParser
..addFlag(FlutterOptions.kNullSafety, defaultsTo: true)
..addOption('target');
final File targetFile = fileSystem.file('targetFile.dart')
..writeAsStringSync('// @dart = 2.11');
expect(
() async => flutterCommand.getBuildInfo(
forcedBuildMode: BuildMode.debug,
forcedTargetFile: targetFile,
),
throwsToolExit(
message: 'This application does not support sound null-safety (its language version is 2.11)',
),
);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
});

testUsingContext('use packagesPath to generate BuildInfo', () async {
final DummyFlutterCommand flutterCommand = DummyFlutterCommand(packagesPath: 'foo');
final BuildInfo buildInfo = await flutterCommand.getBuildInfo(forcedBuildMode: BuildMode.debug);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class WebSteppingProject extends Project {
final String pubspec = '''
name: test
environment:
sdk: '>=2.10.0 <4.0.0'
sdk: '>=2.12.0 <4.0.0'
dependencies:
flutter:
sdk: flutter
Expand Down

0 comments on commit 374f09e

Please sign in to comment.