Unverified Commit deb5e40f authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] handle null package (#75336)

parent 3b884aa6
...@@ -86,7 +86,7 @@ LanguageVersion determineLanguageVersion(File file, Package package) { ...@@ -86,7 +86,7 @@ LanguageVersion determineLanguageVersion(File file, Package package) {
// If the language version cannot be found, use the package version. // If the language version cannot be found, use the package version.
if (package != null) { if (package != null) {
return package.languageVersion; return package.languageVersion ?? nullSafeVersion;
} }
// Default to 2.12 // Default to 2.12
return nullSafeVersion; return nullSafeVersion;
......
...@@ -254,6 +254,20 @@ library funstuff; ...@@ -254,6 +254,20 @@ library funstuff;
expect(determineLanguageVersion(file, package), LanguageVersion(2, 7)); expect(determineLanguageVersion(file, package), LanguageVersion(2, 7));
}); });
testWithoutContext('defaults to null safe version if package lookup returns null', () {
final FileSystem fileSystem = MemoryFileSystem.test();
final File file = fileSystem.file('example.dart')
..writeAsStringSync('''
// Some license
''');
final Package package = Package(
'foo',
Uri.parse('file://foo/'),
languageVersion: null,
);
expect(determineLanguageVersion(file, package), LanguageVersion(2, 12));
});
testWithoutContext('Returns null safe error if reading the file throws a FileSystemException', () { testWithoutContext('Returns null safe error if reading the file throws a FileSystemException', () {
final Package package = Package( final Package package = Package(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment