| 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();
|
| + }
|
| }
|
|
|