Fix for crash when part directive uri is has null value.

R=brianwilkerson@google.com, paulberry@google.com
BUG=

Review-Url: https://codereview.chromium.org/2628303002 .
This commit is contained in:
Konstantin Shcheglov 2017-01-12 17:29:13 -08:00
parent a60f4ff378
commit 646193e6fb
4 changed files with 45 additions and 7 deletions

View file

@ -178,7 +178,7 @@ class _PublicNamespaceVisitor extends RecursiveAstVisitor {
@override
visitPartDirective(PartDirective node) {
parts.add(node.uri.stringValue);
parts.add(node.uri.stringValue ?? '');
}
@override

View file

@ -65,10 +65,4 @@ class CompileTimeErrorCodeTest_Driver extends CompileTimeErrorCodeTest {
test_uriDoesNotExist_import_appears_after_deleting_target() {
return super.test_uriDoesNotExist_import_appears_after_deleting_target();
}
@failingTest
@override
test_uriWithInterpolation_nonConstant() {
return super.test_uriWithInterpolation_nonConstant();
}
}

View file

@ -4345,6 +4345,15 @@ void named({x: 1}) {}
checkLibrary('library my.lib; part "foo/";');
}
test_parts_invalidUri_nullStringValue() {
allowMissingFiles = true;
addSource('/foo/bar.dart', 'part of my.lib;');
checkLibrary(r'''
library my.lib;
part "${foo}/bar.dart";
''');
}
test_propagated_type_refers_to_closure() {
checkLibrary('''
void f() {

View file

@ -6471,6 +6471,17 @@ class B extends A {}
expect(unlinkedExports[0].configurations, isEmpty);
}
test_export_uri_nullStringValue() {
String libraryText = r'''
export "${'a'}.dart";
''';
serializeLibraryText(libraryText);
var unlinkedExports = unlinkedUnits[0].publicNamespace.exports;
expect(unlinkedExports, hasLength(1));
expect(unlinkedExports[0].uri, '');
expect(unlinkedExports[0].configurations, isEmpty);
}
test_export_variable() {
addNamedSource('/a.dart', 'var v;');
serializeLibraryText('export "a.dart";');
@ -8346,6 +8357,16 @@ class D extends p.C {} // Prevent "unused import" warning
expect(unlinkedUnits[0].imports[0].uri, 'dart:async');
}
test_import_uri_nullStringValue() {
String libraryText = r'''
import "${'a'}.dart";
''';
serializeLibraryText(libraryText);
// Second import is the implicit import of dart:core
expect(unlinkedUnits[0].imports, hasLength(2));
expect(unlinkedUnits[0].imports[0].uri, '');
}
test_inferred_function_type_parameter_type_with_unrelated_type_param() {
if (!strongMode || skipFullyLinkedData) {
return;
@ -9475,6 +9496,20 @@ f(x) => 42;
expect(unlinkedUnits[0].parts[0].uriEnd, text.indexOf('; // <-part'));
}
test_part_declaration_invalidUri_nullStringValue() {
addNamedSource('/a.dart', 'part of my.lib;');
String text = r'''
library my.lib;
part "${'a'}.dart"; // <-part
''';
serializeLibraryText(text);
expect(unlinkedUnits[0].publicNamespace.parts, hasLength(1));
expect(unlinkedUnits[0].publicNamespace.parts[0], '');
expect(unlinkedUnits[0].parts, hasLength(1));
expect(unlinkedUnits[0].parts[0].uriOffset, text.indexOf(r'"${'));
expect(unlinkedUnits[0].parts[0].uriEnd, text.indexOf('; // <-part'));
}
test_part_isPartOf() {
addNamedSource('/a.dart', 'part of foo; class C {}');
serializeLibraryText('library foo; part "a.dart";');