Handle invalid deferred prefix declarations.

R=het@google.com

Review URL: https://codereview.chromium.org/2116473002 .
This commit is contained in:
Johnni Winther
2016-07-01 10:53:42 +02:00
parent ee29d16836
commit f00a439f7c
2 changed files with 43 additions and 1 deletions
+6 -1
View File
@@ -922,7 +922,12 @@ abstract class Compiler implements LibraryLoaderListener {
library.implementation.forEachLocalMember(enqueueAll);
library.imports.forEach((ImportElement import) {
if (import.isDeferred) {
world.addToWorkList(import.prefix.loadLibrary);
// `import.prefix` and `loadLibrary` may be `null` when the deferred
// import has compile-time errors.
GetterElement loadLibrary = import.prefix?.loadLibrary;
if (loadLibrary != null) {
world.addToWorkList(loadLibrary);
}
}
});
}
@@ -490,6 +490,43 @@ test() {
'b.dart': '''
''',
}),
const Test('Deferred without prefix', const {
'main.dart': '''
import 'a.dart';
main() {
test();
}
''',
}, preserializedSourceFiles: const {
'a.dart': '''
import 'b.dart' deferred;
test() {}
''',
'b.dart': '''
''',
}, expectedErrorCount: 1),
const Test('Deferred with duplicate prefix', const {
'main.dart': '''
import 'a.dart';
main() {
test();
}
''',
}, preserializedSourceFiles: const {
'a.dart': '''
import 'b.dart' deferred as pre;
import 'c.dart' deferred as pre;
test() {}
''',
'b.dart': '''
''',
'c.dart': '''
''',
}, expectedErrorCount: 1),
];
class Test {