From 489199eff1cd69e6c269ff6abaea0a8c27fa5ecd Mon Sep 17 00:00:00 2001 From: Johnni Winther Date: Thu, 1 Dec 2016 10:53:56 +0100 Subject: [PATCH] Disallow `null` in spanFromSpannable. Closes #27938 R=sigmund@google.com Review URL: https://codereview.chromium.org/2537303004 . --- pkg/compiler/lib/src/compiler.dart | 2 -- pkg/compiler/lib/src/library_loader.dart | 23 ++++++++++--------- .../lib/src/resolution/class_hierarchy.dart | 4 ++-- .../lib/src/resolution/constructors.dart | 2 +- .../lib/src/resolved_uri_translator.dart | 8 +++---- tests/compiler/dart2js/mock_compiler.dart | 2 +- 6 files changed, 19 insertions(+), 22 deletions(-) diff --git a/pkg/compiler/lib/src/compiler.dart b/pkg/compiler/lib/src/compiler.dart index db282a37ac9..16ef47def23 100644 --- a/pkg/compiler/lib/src/compiler.dart +++ b/pkg/compiler/lib/src/compiler.dart @@ -1792,8 +1792,6 @@ class CompilerDiagnosticReporter extends DiagnosticReporter { } SourceSpan spanFromSpannable(Spannable node) { - // TODO(johnniwinther): Disallow `node == null` ? - if (node == null) return null; if (node == CURRENT_ELEMENT_SPANNABLE) { node = currentElement; } else if (node == NO_LOCATION_SPANNABLE) { diff --git a/pkg/compiler/lib/src/library_loader.dart b/pkg/compiler/lib/src/library_loader.dart index c7c6e86a390..796b7079258 100644 --- a/pkg/compiler/lib/src/library_loader.dart +++ b/pkg/compiler/lib/src/library_loader.dart @@ -427,7 +427,8 @@ class _LibraryLoaderTask extends CompilerTask implements LibraryLoaderTask { // TODO(johnniwinther): Ensure that currentHandler correctly encloses the // loading of a library cluster. currentHandler = new LibraryDependencyHandler(this); - return createLibrary(currentHandler, null, resolvedUri, + return createLibrary( + currentHandler, null, resolvedUri, NO_LOCATION_SPANNABLE, skipFileWithPartOfTag: skipFileWithPartOfTag) .then((LibraryElement library) { if (library == null) { @@ -543,7 +544,7 @@ class _LibraryLoaderTask extends CompilerTask implements LibraryLoaderTask { // Import dart:core if not already imported. if (!importsDartCore && library.canonicalUri != Uris.dart_core) { - return createLibrary(handler, null, Uris.dart_core) + return createLibrary(handler, null, Uris.dart_core, library) .then((LibraryElement coreLibrary) { handler.registerDependency( library, @@ -629,7 +630,7 @@ class _LibraryLoaderTask extends CompilerTask implements LibraryLoaderTask { LibraryElement library, LibraryDependencyElementX libraryDependency) { Uri base = library.canonicalUri; Uri resolvedUri = base.resolveUri(libraryDependency.uri); - return createLibrary(handler, library, resolvedUri, node: libraryDependency) + return createLibrary(handler, library, resolvedUri, libraryDependency) .then((LibraryElement loadedLibrary) { if (loadedLibrary == null) return; reporter.withCurrentElement(library, () { @@ -650,15 +651,15 @@ class _LibraryLoaderTask extends CompilerTask implements LibraryLoaderTask { return listener.onLibraryScanned(library, handler).then((_) { return Future.forEach(library.imports, (ImportElement import) { Uri resolvedUri = library.canonicalUri.resolveUri(import.uri); - return createLibrary(handler, library, resolvedUri); + return createLibrary(handler, library, resolvedUri, library); }).then((_) { return Future.forEach(library.exports, (ExportElement export) { Uri resolvedUri = library.canonicalUri.resolveUri(export.uri); - return createLibrary(handler, library, resolvedUri); + return createLibrary(handler, library, resolvedUri, library); }).then((_) { // TODO(johnniwinther): Shouldn't there be an [ImportElement] for the // implicit import of dart:core? - return createLibrary(handler, library, Uris.dart_core); + return createLibrary(handler, library, Uris.dart_core, library); }).then((_) => library); }); }); @@ -680,10 +681,10 @@ class _LibraryLoaderTask extends CompilerTask implements LibraryLoaderTask { * If a new library is created, the [handler] is notified. */ Future createLibrary(LibraryDependencyHandler handler, - LibraryElement importingLibrary, Uri resolvedUri, - {Spannable node, bool skipFileWithPartOfTag: false}) { + LibraryElement importingLibrary, Uri resolvedUri, Spannable spannable, + {bool skipFileWithPartOfTag: false}) { Uri readableUri = - uriTranslator.translate(importingLibrary, resolvedUri, node); + uriTranslator.translate(importingLibrary, resolvedUri, spannable); LibraryElement library = libraryCanonicalUriMap[resolvedUri]; if (library != null) { return new Future.value(library); @@ -693,7 +694,7 @@ class _LibraryLoaderTask extends CompilerTask implements LibraryLoaderTask { return loadDeserializedLibrary(handler, library); } return reporter.withCurrentElement(importingLibrary, () { - return _readScript(node, readableUri, resolvedUri) + return _readScript(spannable, readableUri, resolvedUri) .then((Script script) { if (script == null) return null; LibraryElement element = @@ -721,7 +722,7 @@ class _LibraryLoaderTask extends CompilerTask implements LibraryLoaderTask { DiagnosticMessage info = reporter.withCurrentElement( importingLibrary, () => reporter.createMessage( - node, MessageKind.IMPORT_PART_OF_HERE)); + spannable, MessageKind.IMPORT_PART_OF_HERE)); reporter.reportError(error, [info]); } } diff --git a/pkg/compiler/lib/src/resolution/class_hierarchy.dart b/pkg/compiler/lib/src/resolution/class_hierarchy.dart index ef03ab58bd5..551a47e7332 100644 --- a/pkg/compiler/lib/src/resolution/class_hierarchy.dart +++ b/pkg/compiler/lib/src/resolution/class_hierarchy.dart @@ -482,12 +482,12 @@ class ClassResolverVisitor extends TypeDefinitionVisitor { if (interfaceType != null) { if (interfaceType.isMalformed) { reporter.reportErrorMessage( - superclass, + link.head, MessageKind.CANNOT_IMPLEMENT_MALFORMED, {'className': element.name, 'malformedType': interfaceType}); } else if (interfaceType.isEnumType) { reporter.reportErrorMessage( - superclass, + link.head, MessageKind.CANNOT_IMPLEMENT_ENUM, {'className': element.name, 'enumType': interfaceType}); } else if (!interfaceType.isInterfaceType) { diff --git a/pkg/compiler/lib/src/resolution/constructors.dart b/pkg/compiler/lib/src/resolution/constructors.dart index ae51c80018d..6a4ab3bfc9f 100644 --- a/pkg/compiler/lib/src/resolution/constructors.dart +++ b/pkg/compiler/lib/src/resolution/constructors.dart @@ -345,7 +345,7 @@ class InitializerResolver { if (!field.isMalformed) { registry.registerStaticUse(new StaticUse.fieldInit(field)); } - checkForDuplicateInitializers(field, element.initializer); + checkForDuplicateInitializers(field, parameterNode); visitor.defineLocalVariable(parameterNode, initializingFormal); visitor.addToScope(initializingFormal); if (isConst) { diff --git a/pkg/compiler/lib/src/resolved_uri_translator.dart b/pkg/compiler/lib/src/resolved_uri_translator.dart index 41a96b3c92f..84cdf501c6c 100644 --- a/pkg/compiler/lib/src/resolved_uri_translator.dart +++ b/pkg/compiler/lib/src/resolved_uri_translator.dart @@ -35,8 +35,7 @@ abstract class ResolvedUriTranslator { /// responsible for reporting errors. /// /// See [LibraryLoader] for terminology on URIs. - Uri translate(LibraryElement importingLibrary, Uri uri, - [Spannable spannable]); + Uri translate(LibraryElement importingLibrary, Uri uri, Spannable spannable); } /// A translator that forwards all methods to an internal @@ -59,7 +58,7 @@ class ForwardingResolvedUriTranslator implements ResolvedUriTranslator { @override Uri translate(LibraryElement importingLibrary, Uri resolvedUri, - [Spannable spannable]) => + Spannable spannable) => resolvedUriTranslator.translate(importingLibrary, resolvedUri, spannable); @override @@ -86,8 +85,7 @@ class _ResolvedUriTranslator implements ResolvedUriTranslator { Map get sdkLibraries => _sdkLibraries; @override - Uri translate(LibraryElement importingLibrary, Uri uri, - [Spannable spannable]) { + Uri translate(LibraryElement importingLibrary, Uri uri, Spannable spannable) { if (uri.scheme == 'dart') { return translateDartUri(importingLibrary, uri, spannable); } diff --git a/tests/compiler/dart2js/mock_compiler.dart b/tests/compiler/dart2js/mock_compiler.dart index 7469f0c81f0..fb5f82430d5 100644 --- a/tests/compiler/dart2js/mock_compiler.dart +++ b/tests/compiler/dart2js/mock_compiler.dart @@ -290,7 +290,7 @@ class MockResolvedUriTranslator implements ResolvedUriTranslator { static final _emptySet = new Set(); Uri translate(LibraryElement importingLibrary, Uri resolvedUri, - [Spannable spannable]) => + Spannable spannable) => resolvedUri; Set get disallowedLibraryUris => _emptySet; bool get mockableLibraryUsed => false;