diff --git a/compiler/java/com/google/dart/compiler/ast/DartLiteral.java b/compiler/java/com/google/dart/compiler/ast/DartLiteral.java index 289dcb05a91..616fe29236e 100644 --- a/compiler/java/com/google/dart/compiler/ast/DartLiteral.java +++ b/compiler/java/com/google/dart/compiler/ast/DartLiteral.java @@ -1,24 +1,11 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. package com.google.dart.compiler.ast; -import com.google.dart.compiler.type.Type; - /** * Abstract base class for Dart literal values. */ public abstract class DartLiteral extends DartExpression { - private Type type; - - @Override - public void setType(Type type) { - this.type = type; - } - - @Override - public Type getType() { - return type; - } } diff --git a/compiler/java/com/google/dart/compiler/ast/DartNode.java b/compiler/java/com/google/dart/compiler/ast/DartNode.java index 77931caaa15..1259d36e59d 100644 --- a/compiler/java/com/google/dart/compiler/ast/DartNode.java +++ b/compiler/java/com/google/dart/compiler/ast/DartNode.java @@ -7,7 +7,6 @@ package com.google.dart.compiler.ast; import com.google.dart.compiler.common.AbstractNode; import com.google.dart.compiler.resolver.Element; import com.google.dart.compiler.type.Type; -import com.google.dart.compiler.type.Types; import com.google.dart.compiler.util.DefaultTextOutput; import java.util.List; @@ -16,10 +15,8 @@ import java.util.List; * Base class for all Dart AST nodes. */ public abstract class DartNode extends AbstractNode { - private static final Type dynamicType = Types.newDynamicType(); - private DartNode parent; - private Type type = dynamicType; + private Type type; public final String toSource() { DefaultTextOutput out = new DefaultTextOutput(false); diff --git a/compiler/java/com/google/dart/compiler/ast/DartParameterizedTypeNode.java b/compiler/java/com/google/dart/compiler/ast/DartParameterizedTypeNode.java index 08f19c9814e..bf684ac8595 100644 --- a/compiler/java/com/google/dart/compiler/ast/DartParameterizedTypeNode.java +++ b/compiler/java/com/google/dart/compiler/ast/DartParameterizedTypeNode.java @@ -1,17 +1,14 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. package com.google.dart.compiler.ast; -import com.google.dart.compiler.type.Type; - import java.util.List; public class DartParameterizedTypeNode extends DartExpression { private DartExpression expression; private final NodeList typeParameters = NodeList.create(this); - private Type type; public DartParameterizedTypeNode(DartExpression expression, List typeParameters) { setExpression(expression); @@ -27,11 +24,6 @@ public class DartParameterizedTypeNode extends DartExpression { return expression; } - @Override - public Type getType() { - return type; - } - public List getTypeParameters() { return typeParameters; } @@ -40,11 +32,6 @@ public class DartParameterizedTypeNode extends DartExpression { this.expression = expression; } - @Override - public void setType(Type type) { - this.type = type; - } - @Override public void visitChildren(ASTVisitor visitor) { getExpression().accept(visitor); diff --git a/compiler/java/com/google/dart/compiler/ast/DartPropertyAccess.java b/compiler/java/com/google/dart/compiler/ast/DartPropertyAccess.java index 7a73da1b0d1..64ac55fa903 100644 --- a/compiler/java/com/google/dart/compiler/ast/DartPropertyAccess.java +++ b/compiler/java/com/google/dart/compiler/ast/DartPropertyAccess.java @@ -1,4 +1,4 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. @@ -6,7 +6,6 @@ package com.google.dart.compiler.ast; import com.google.dart.compiler.resolver.Element; import com.google.dart.compiler.resolver.NodeElement; -import com.google.dart.compiler.type.Type; /** * Represents a Dart property access expression (a.b). @@ -15,7 +14,6 @@ public class DartPropertyAccess extends DartExpression { private DartNode qualifier; private DartIdentifier name; - private Type type; public DartPropertyAccess(DartNode qualifier, DartIdentifier name) { this.qualifier = becomeParentOf(qualifier); @@ -53,16 +51,6 @@ public class DartPropertyAccess extends DartExpression { return name.getElement(); } - @Override - public void setType(Type type) { - this.type = type; - } - - @Override - public Type getType() { - return type; - } - @Override public void visitChildren(ASTVisitor visitor) { qualifier.accept(visitor); diff --git a/compiler/java/com/google/dart/compiler/ast/DartTypeNode.java b/compiler/java/com/google/dart/compiler/ast/DartTypeNode.java index 8e537509564..f7b6b105073 100644 --- a/compiler/java/com/google/dart/compiler/ast/DartTypeNode.java +++ b/compiler/java/com/google/dart/compiler/ast/DartTypeNode.java @@ -1,11 +1,9 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. package com.google.dart.compiler.ast; -import com.google.dart.compiler.type.Type; - import java.util.List; /** @@ -15,7 +13,6 @@ public class DartTypeNode extends DartNode { private DartNode identifier; private NodeList typeArguments = NodeList.create(this); - private Type type; public DartTypeNode(DartNode identifier) { this(identifier, null); @@ -34,16 +31,6 @@ public class DartTypeNode extends DartNode { return typeArguments; } - @Override - public void setType(Type type) { - this.type = type; - } - - @Override - public Type getType() { - return type; - } - @Override public void visitChildren(ASTVisitor visitor) { identifier.accept(visitor); diff --git a/compiler/java/com/google/dart/compiler/ast/DartTypeParameter.java b/compiler/java/com/google/dart/compiler/ast/DartTypeParameter.java index dd33c775206..58a0c2920c3 100644 --- a/compiler/java/com/google/dart/compiler/ast/DartTypeParameter.java +++ b/compiler/java/com/google/dart/compiler/ast/DartTypeParameter.java @@ -1,11 +1,10 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. package com.google.dart.compiler.ast; import com.google.dart.compiler.resolver.Element; -import com.google.dart.compiler.type.Type; /** * Represents a type parameter in a class or interface declaration. @@ -13,7 +12,6 @@ import com.google.dart.compiler.type.Type; public class DartTypeParameter extends DartDeclaration { private DartTypeNode bound; - private Type type; public DartTypeParameter(DartIdentifier name, DartTypeNode bound) { super(name); @@ -36,16 +34,6 @@ public class DartTypeParameter extends DartDeclaration { public R accept(ASTVisitor visitor) { return visitor.visitTypeParameter(this); } - - @Override - public Type getType() { - return type; - } - - @Override - public void setType(Type type) { - this.type = type; - } @Override public Element getElement() { diff --git a/compiler/java/com/google/dart/compiler/ast/DartTypedLiteral.java b/compiler/java/com/google/dart/compiler/ast/DartTypedLiteral.java index 51ccde285eb..28015cd8228 100644 --- a/compiler/java/com/google/dart/compiler/ast/DartTypedLiteral.java +++ b/compiler/java/com/google/dart/compiler/ast/DartTypedLiteral.java @@ -1,18 +1,16 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. package com.google.dart.compiler.ast; import com.google.dart.compiler.type.InterfaceType; -import com.google.dart.compiler.type.Type; import java.util.List; public abstract class DartTypedLiteral extends DartExpression { private final boolean isConst; private final NodeList typeArguments = NodeList.create(this); - private InterfaceType type; DartTypedLiteral(boolean isConst, List typeArguments) { this.isConst = isConst; @@ -27,14 +25,9 @@ public abstract class DartTypedLiteral extends DartExpression { return typeArguments; } - @Override - public void setType(Type type) { - this.type = (InterfaceType) type; - } - @Override public InterfaceType getType() { - return type; + return (InterfaceType) super.getType(); } @Override diff --git a/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java b/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java index 6fda7985128..5b76ac8d5c3 100644 --- a/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java +++ b/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java @@ -1237,6 +1237,9 @@ public class TypeAnalyzer implements DartCompilationPhase { @Override public Type visitIdentifier(DartIdentifier node) { + if (node.getType() != null) { + return node.getType(); + } Element element = node.getElement(); Type type; switch (ElementKind.of(element)) { @@ -1579,10 +1582,10 @@ public class TypeAnalyzer implements DartCompilationPhase { @Override public Type visitPropertyAccess(DartPropertyAccess node) { - Element element = node.getElement(); if (node.getType() != null) { return node.getType(); } + Element element = node.getElement(); if (element != null) { return element.getType(); } diff --git a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java index 8689b3399b6..a16e2de184d 100644 --- a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java +++ b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java @@ -813,7 +813,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { errEx(TypeErrorCode.FIELD_IS_FINAL, 7, 5, 1), errEx(TypeErrorCode.FIELD_IS_FINAL, 8, 5, 1)); } - + public void test_finalField_inInterface() throws Exception { AnalyzeLibraryResult libraryResult = analyzeLibrary( getName(), @@ -1460,6 +1460,19 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase { assertVariableTypeString(libraryResult, "v2", "bool"); } + public void test_getType_getterInSwitch() throws Exception { + AnalyzeLibraryResult libraryResult = analyzeLibrary( + "int get foo() {}", + "f() {", + " switch (true) {", + " default:", + " int v = foo;", + " }", + "}", + ""); + assertErrors(libraryResult.getErrors()); + } + /** * Asserts that {@link VariableElement} with given name has expected type. */