Don't reload if compilation has errors (#38586)
diff --git a/packages/flutter_tools/lib/src/devfs.dart b/packages/flutter_tools/lib/src/devfs.dart index f2a5cf2..a084f93 100644 --- a/packages/flutter_tools/lib/src/devfs.dart +++ b/packages/flutter_tools/lib/src/devfs.dart
@@ -467,7 +467,7 @@ outputPath: dillOutputPath ?? getDefaultApplicationKernelPath(trackWidgetCreation: trackWidgetCreation), packagesFilePath : _packagesFilePath, ); - if (compilerOutput == null) { + if (compilerOutput == null || compilerOutput.errorCount > 0) { return UpdateFSReport(success: false); } // list of sources that needs to be monitored are in [compilerOutput.sources]
diff --git a/packages/flutter_tools/test/general.shard/devfs_test.dart b/packages/flutter_tools/test/general.shard/devfs_test.dart index 7a1a112..0230408 100644 --- a/packages/flutter_tools/test/general.shard/devfs_test.dart +++ b/packages/flutter_tools/test/general.shard/devfs_test.dart
@@ -10,9 +10,11 @@ import 'package:file/memory.dart'; import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/io.dart'; +import 'package:flutter_tools/src/compile.dart'; import 'package:flutter_tools/src/devfs.dart'; import 'package:flutter_tools/src/vmservice.dart'; import 'package:json_rpc_2/json_rpc_2.dart' as rpc; +import 'package:mockito/mockito.dart'; import '../src/common.dart'; import '../src/context.dart'; @@ -100,6 +102,7 @@ vmService = MockVMService(); await vmService.setUp(); }); + tearDownAll(() async { await vmService.tearDown(); _cleanupTempDirs(); @@ -171,6 +174,33 @@ }, overrides: <Type, Generator>{ FileSystem: () => fs, }); + + testUsingContext('reports unsuccessful compile when errors are returned', () async { + devFS = DevFS(vmService, 'test', tempDir); + await devFS.create(); + + final RealMockResidentCompiler residentCompiler = RealMockResidentCompiler(); + when(residentCompiler.recompile( + any, + any, + outputPath: anyNamed('outputPath'), + )).thenAnswer((Invocation invocation) { + return Future<CompilerOutput>.value(const CompilerOutput('example', 2, <Uri>[])); + }); + + final UpdateFSReport report = await devFS.update( + mainPath: 'lib/foo.txt', + generator: residentCompiler, + pathToReload: 'lib/foo.txt.dill', + trackWidgetCreation: false, + invalidatedFiles: <Uri>[], + ); + + expect(report.success, false); + }, overrides: <Type, Generator>{ + FileSystem: () => fs, + }); + }); } @@ -260,6 +290,7 @@ dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); } +class RealMockResidentCompiler extends Mock implements ResidentCompiler {} final List<Directory> _tempDirs = <Directory>[]; final Map <String, Uri> _packages = <String, Uri>{};