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

Unified Diff: compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java

Issue 9113064: Issue 1330. Return actual Type from DartNewExpression. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Tweaks for comments Created 8 years, 11 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
« no previous file with comments | « compiler/java/com/google/dart/compiler/resolver/Resolver.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
diff --git a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
index 3c394b136a5e258215eedf1fdd2d09ea10825bdb..cd9905eb2497fe008a269513540e2bf53ccf5cc4 100644
--- a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
+++ b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
@@ -11,6 +11,9 @@ import com.google.common.collect.Iterables;
import com.google.dart.compiler.CompilerTestCase;
import com.google.dart.compiler.DartCompilationError;
import com.google.dart.compiler.ast.DartClass;
+import com.google.dart.compiler.ast.DartExpression;
+import com.google.dart.compiler.ast.DartField;
+import com.google.dart.compiler.ast.DartFieldDefinition;
import com.google.dart.compiler.ast.DartFunctionExpression;
import com.google.dart.compiler.ast.DartIdentifier;
import com.google.dart.compiler.ast.DartInvocation;
@@ -514,4 +517,48 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
libraryResult.getCompilationErrors(),
errEx(ResolverErrorCode.DUPLICATE_NAMED_ARGUMENT, 16, 25, 5));
}
+
+ /**
+ * We should return correct {@link Type} for {@link DartNewExpression}.
+ */
+ public void test_DartNewExpression_getType() throws Exception {
+ AnalyzeLibraryResult libraryResult =
+ analyzeLibrary(
+ getName(),
+ makeCode(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "class A {",
+ " A() {}",
+ " A.foo() {}",
+ "}",
+ "var a1 = new A();",
+ "var a2 = new A.foo();",
+ ""));
+ assertErrors(libraryResult.getCompilationErrors());
+ assertErrors(libraryResult.getCompilationWarnings());
+ assertErrors(libraryResult.getTypeErrors());
+ DartUnit unit = libraryResult.getLibraryUnitResult().getUnit(getName());
+ // new A()
+ {
+ DartNewExpression newExpression = (DartNewExpression) getTopLevelFieldInitializer(unit, 1);
+ Type newType = newExpression.getType();
+ assertEquals("A", newType.getElement().getName());
+ }
+ // new A.foo()
+ {
+ DartNewExpression newExpression = (DartNewExpression) getTopLevelFieldInitializer(unit, 2);
+ Type newType = newExpression.getType();
+ assertEquals("A", newType.getElement().getName());
+ }
+ }
+
+ /**
+ * Expects that given {@link DartUnit} has {@link DartFieldDefinition} as <code>index</code> top
+ * level node and return initializer of first {@link DartField}.
+ */
+ private static DartExpression getTopLevelFieldInitializer(DartUnit unit, int index) {
+ DartFieldDefinition fieldDefinition = (DartFieldDefinition) unit.getTopLevelNodes().get(index);
+ DartField field = fieldDefinition.getFields().get(0);
+ return field.getValue();
+ }
}
« no previous file with comments | « compiler/java/com/google/dart/compiler/resolver/Resolver.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698