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

Commit 374f09e

Browse files
[flutter_tools] No more implicit --no-sound-null-safety (#118491)
* remove implicit no-sound-null-safety * add test * bump sdk constraint in test file
1 parent 8a58ec5 commit 374f09e

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

packages/flutter_tools/lib/src/resident_runner.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,8 @@ class FlutterDevice {
8383
required Platform platform,
8484
TargetModel targetModel = TargetModel.flutter,
8585
List<String>? experimentalFlags,
86-
ResidentCompiler? generator,
8786
String? userIdentifier,
8887
}) async {
89-
ResidentCompiler generator;
9088
final TargetPlatform targetPlatform = await device.targetPlatform;
9189
if (device.platformType == PlatformType.fuchsia) {
9290
targetModel = TargetModel.flutterRunner;
@@ -111,6 +109,8 @@ class FlutterDevice {
111109
fileSystem: globals.fs,
112110
);
113111

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

138138
final String platformDillPath = globals.fs.path.join(
139139
getWebPlatformBinariesDirectory(globals.artifacts!, buildInfo.webRenderer).path,
140-
platformDillName
140+
platformDillName,
141141
);
142142

143143
generator = ResidentCompiler(

packages/flutter_tools/lib/src/runner/flutter_command.dart

+5-1
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,11 @@ abstract class FlutterCommand extends Command<void> {
10931093
(languageVersion.major == nullSafeVersion.major && languageVersion.minor >= nullSafeVersion.minor)) {
10941094
nullSafetyMode = NullSafetyMode.sound;
10951095
} else {
1096-
nullSafetyMode = NullSafetyMode.unsound;
1096+
throwToolExit(
1097+
'This application does not support sound null-safety (its language version is $languageVersion).\n'
1098+
'To build this application, you must provide the CLI flag --no-sound-null-safety. Dart 3 will only '
1099+
'support sound null safety, see https://dart.dev/null-safety.',
1100+
);
10971101
}
10981102
} else if (!wasNullSafetyFlagParsed) {
10991103
// This mode is only used for commands which do not build a single target like

packages/flutter_tools/test/general.shard/runner/flutter_command_test.dart

+21
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,27 @@ void main() {
554554
ProcessManager: () => processManager,
555555
});
556556

557+
testUsingContext('tool exits on non-sound-null-safe code when explicit flag not passed', () async {
558+
final DummyFlutterCommand flutterCommand = DummyFlutterCommand(packagesPath: 'foo');
559+
flutterCommand.argParser
560+
..addFlag(FlutterOptions.kNullSafety, defaultsTo: true)
561+
..addOption('target');
562+
final File targetFile = fileSystem.file('targetFile.dart')
563+
..writeAsStringSync('// @dart = 2.11');
564+
expect(
565+
() async => flutterCommand.getBuildInfo(
566+
forcedBuildMode: BuildMode.debug,
567+
forcedTargetFile: targetFile,
568+
),
569+
throwsToolExit(
570+
message: 'This application does not support sound null-safety (its language version is 2.11)',
571+
),
572+
);
573+
}, overrides: <Type, Generator>{
574+
FileSystem: () => fileSystem,
575+
ProcessManager: () => processManager,
576+
});
577+
557578
testUsingContext('use packagesPath to generate BuildInfo', () async {
558579
final DummyFlutterCommand flutterCommand = DummyFlutterCommand(packagesPath: 'foo');
559580
final BuildInfo buildInfo = await flutterCommand.getBuildInfo(forcedBuildMode: BuildMode.debug);

packages/flutter_tools/test/integration.shard/test_data/stepping_project.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class WebSteppingProject extends Project {
6565
final String pubspec = '''
6666
name: test
6767
environment:
68-
sdk: '>=2.10.0 <4.0.0'
68+
sdk: '>=2.12.0 <4.0.0'
6969
dependencies:
7070
flutter:
7171
sdk: flutter

0 commit comments

Comments
 (0)