Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Unified Diff: editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/internal/scope/LibraryImportScopeTest.java

Issue 15074002: Report StaticTypeWarningCode.AMBIGUOUS_IMPORT when used as type annotation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/internal/scope/LibraryImportScopeTest.java
diff --git a/editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/internal/scope/LibraryImportScopeTest.java b/editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/internal/scope/LibraryImportScopeTest.java
index bd800d37f16ddc8386f6ef22ec3d2afca7b0439f..98e01f86ba1793468da0edd622cfe42e2931a439 100644
--- a/editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/internal/scope/LibraryImportScopeTest.java
+++ b/editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/internal/scope/LibraryImportScopeTest.java
@@ -13,6 +13,7 @@
*/
package com.google.dart.engine.internal.scope;
+import com.google.dart.engine.ast.Identifier;
import com.google.dart.engine.context.AnalysisContext;
import com.google.dart.engine.element.ClassElement;
import com.google.dart.engine.element.Element;
@@ -21,6 +22,7 @@ import com.google.dart.engine.element.LibraryElement;
import com.google.dart.engine.element.MultiplyDefinedElement;
import com.google.dart.engine.error.CompileTimeErrorCode;
import com.google.dart.engine.error.GatheringErrorListener;
+import com.google.dart.engine.error.StaticTypeWarningCode;
import com.google.dart.engine.internal.context.AnalysisContextImpl;
import com.google.dart.engine.internal.element.ClassElementImpl;
import com.google.dart.engine.internal.element.CompilationUnitElementImpl;
@@ -29,6 +31,8 @@ import com.google.dart.engine.internal.element.LibraryElementImpl;
import com.google.dart.engine.resolver.ResolverTestCase;
import static com.google.dart.engine.ast.ASTFactory.identifier;
+import static com.google.dart.engine.ast.ASTFactory.methodDeclaration;
+import static com.google.dart.engine.ast.ASTFactory.typeName;
public class LibraryImportScopeTest extends ResolverTestCase {
public void test_conflictingImports() {
@@ -55,19 +59,36 @@ public class LibraryImportScopeTest extends ResolverTestCase {
LibraryElementImpl importingLibrary = createTestLibrary(context, "importing");
importingLibrary.setImports(new ImportElement[] {import1, import2});
- GatheringErrorListener errorListener = new GatheringErrorListener();
- Scope scope = new LibraryImportScope(importingLibrary, errorListener);
- assertEquals(typeA, scope.lookup(typeNameA, importingLibrary));
- errorListener.assertNoErrors();
- assertEquals(typeC, scope.lookup(typeNameC, importingLibrary));
- errorListener.assertNoErrors();
- Element element = scope.lookup(typeNameB, importingLibrary);
- errorListener.assertErrors(CompileTimeErrorCode.AMBIGUOUS_IMPORT);
- assertInstanceOf(MultiplyDefinedElement.class, element);
- Element[] conflictingElements = ((MultiplyDefinedElement) element).getConflictingElements();
- assertEquals(typeB1, conflictingElements[0]);
- assertEquals(typeB2, conflictingElements[1]);
- assertEquals(2, conflictingElements.length);
+ {
+ GatheringErrorListener errorListener = new GatheringErrorListener();
+ Scope scope = new LibraryImportScope(importingLibrary, errorListener);
+
+ assertEquals(typeA, scope.lookup(identifier(typeNameA), importingLibrary));
+ errorListener.assertNoErrors();
+
+ assertEquals(typeC, scope.lookup(identifier(typeNameC), importingLibrary));
+ errorListener.assertNoErrors();
+
+ Element element = scope.lookup(identifier(typeNameB), importingLibrary);
+ errorListener.assertErrors(CompileTimeErrorCode.AMBIGUOUS_IMPORT);
+ assertInstanceOf(MultiplyDefinedElement.class, element);
+
+ Element[] conflictingElements = ((MultiplyDefinedElement) element).getConflictingElements();
+ assertEquals(typeB1, conflictingElements[0]);
+ assertEquals(typeB2, conflictingElements[1]);
+ assertEquals(2, conflictingElements.length);
+ }
+
+ {
+ GatheringErrorListener errorListener = new GatheringErrorListener();
+ Scope scope = new LibraryImportScope(importingLibrary, errorListener);
+
+ Identifier identifier = identifier(typeNameB);
+ methodDeclaration(null, typeName(identifier), null, null, identifier("foo"), null);
+ Element element = scope.lookup(identifier, importingLibrary);
+ errorListener.assertErrors(StaticTypeWarningCode.AMBIGUOUS_IMPORT);
+ assertInstanceOf(MultiplyDefinedElement.class, element);
+ }
}
public void test_creation_empty() {
@@ -88,7 +109,7 @@ public class LibraryImportScopeTest extends ResolverTestCase {
definingLibrary.setImports(new ImportElement[] {importElement});
GatheringErrorListener errorListener = new GatheringErrorListener();
Scope scope = new LibraryImportScope(definingLibrary, errorListener);
- assertEquals(importedType, scope.lookup(importedTypeName, definingLibrary));
+ assertEquals(importedType, scope.lookup(identifier(importedTypeName), definingLibrary));
}
public void test_getDefiningLibrary() throws Exception {

Powered by Google App Engine
This is Rietveld 408576698