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

Unified Diff: compiler/javatests/com/google/dart/compiler/resolver/ResolverTest.java

Issue 8384012: Make some ErrorCode-s compile-time errors and some just type warnings (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 2 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: compiler/javatests/com/google/dart/compiler/resolver/ResolverTest.java
diff --git a/compiler/javatests/com/google/dart/compiler/resolver/ResolverTest.java b/compiler/javatests/com/google/dart/compiler/resolver/ResolverTest.java
index bb3ea765129c446bb030dc4c01aa74e77d538320..783497cd918fe6c589ccbdf32d66affa50c243f9 100644
--- a/compiler/javatests/com/google/dart/compiler/resolver/ResolverTest.java
+++ b/compiler/javatests/com/google/dart/compiler/resolver/ResolverTest.java
@@ -5,12 +5,8 @@
package com.google.dart.compiler.resolver;
import com.google.common.base.Joiner;
-import com.google.dart.compiler.DartCompilationError;
import com.google.dart.compiler.ErrorCode;
-import com.google.dart.compiler.ErrorSeverity;
import com.google.dart.compiler.ast.DartClass;
-import com.google.dart.compiler.testing.TestCompilerContext;
-import com.google.dart.compiler.testing.TestCompilerContext.EventKind;
import com.google.dart.compiler.type.DynamicType;
import com.google.dart.compiler.type.InterfaceType;
import com.google.dart.compiler.type.Type;
@@ -306,50 +302,12 @@ public class ResolverTest extends ResolverTestCase {
}
public void testBadFactory() {
-
- TestCompilerContext context1 = new TestCompilerContext(EventKind.TYPE_ERROR) {
- @Override
- public void onError(DartCompilationError event) {
- recordError(event);
- }
- @Override
- public boolean shouldWarnOnNoSuchType() {
- return false;
- }
- };
- resolve(parseUnit("class Object {}",
- "class Zebra {",
- " factory foo() {}",
- "}"), context1);
- {
- ErrorCode[] expected = {
- ResolverErrorCode.NO_SUCH_TYPE
- };
- checkExpectedErrors(expected);
- }
-
- resetExpectedErrors();
- TestCompilerContext context2 = new TestCompilerContext(EventKind.TYPE_ERROR) {
- @Override
- public void onError(DartCompilationError event) {
- if (event.getErrorCode().getErrorSeverity() == ErrorSeverity.ERROR) {
- recordError(event);
- }
- }
- @Override
- public boolean shouldWarnOnNoSuchType() {
- return true;
- }
- };
- resolve(parseUnit("class Object {}",
- "class Zebra {",
- " factory foo() {}",
- "}"), context2);
- {
- ErrorCode[] expected = {
- };
- checkExpectedErrors(expected);
- }
+ resolveAndTest(Joiner.on("\n").join(
+ "class Object {}",
+ "class Zebra {",
+ " factory foo() {}",
+ "}"),
+ ResolverErrorCode.NO_SUCH_TYPE_CONSTRUCTOR);
}
/**
@@ -515,7 +473,7 @@ public class ResolverTest extends ResolverTestCase {
" var Bar;",
" create() { return new Bar();}",
"}"),
- ResolverErrorCode.NO_SUCH_TYPE,
+ ResolverErrorCode.NO_SUCH_TYPE_NEW,
ResolverErrorCode.NEW_EXPRESSION_NOT_CONSTRUCTOR);
// New expression tied to an unbound type variable is not allowed.
@@ -536,7 +494,128 @@ public class ResolverTest extends ResolverTestCase {
"class B {",
" foo() { return new Foo<T>(); }",
"}"),
- ResolverErrorCode.NO_SUCH_TYPE);
+ TypeErrorCode.NO_SUCH_TYPE_GENERICS_ARGUMENT);
+ }
+
+ public void test_noSuchType_field() throws Exception {
+ resolveAndTest(Joiner.on("\n").join(
+ "class Object {}",
+ "class MyClass {",
+ " Unknown field;",
+ "}"),
+ TypeErrorCode.NO_SUCH_TYPE_FIELD);
+ }
+
+ public void test_noSuchType_variableStatement() throws Exception {
+ resolveAndTest(Joiner.on("\n").join(
+ "class Object {}",
+ "class MyClass {",
+ " foo() {",
+ " Unknown bar;",
+ " }",
+ "}"),
+ TypeErrorCode.NO_SUCH_TYPE_VARIABLE_STATEMENT);
+ }
+
+ public void test_noSuchType_classExtends() throws Exception {
+ resolveAndTest(Joiner.on("\n").join(
+ "class Object {}",
+ "class MyClass extends Unknown {",
+ "}"),
+ ResolverErrorCode.NO_SUCH_TYPE_EXTENDS);
+ }
+
+ public void test_noSuchType_classExtendsTypeVariable() throws Exception {
+ resolveAndTest(Joiner.on("\n").join(
+ "class Object {}",
+ "class MyClass<E> extends E {",
+ "}"),
+ ResolverErrorCode.NOT_A_CLASS);
+ }
+
+ public void test_noSuchType_classImplements() throws Exception {
+ resolveAndTest(Joiner.on("\n").join(
+ "class Object {}",
+ "class MyClass implements Unknown {",
+ "}"),
+ ResolverErrorCode.NO_SUCH_TYPE_IMPLEMENTS);
+ }
+
+ public void test_noSuchType_classImplementsTypeVariable() throws Exception {
+ resolveAndTest(Joiner.on("\n").join(
+ "class Object {}",
+ "class MyClass<E> implements E {",
+ "}"),
+ ResolverErrorCode.NOT_A_CLASS_OR_INTERFACE);
+ }
+
+ public void test_noSuchType_typeArgument() throws Exception {
+ resolveAndTest(Joiner.on("\n").join(
+ "class Object {}",
+ "class Base<T> {}",
+ "class MyClass extends Base<Unknown> {",
+ "}"),
+ TypeErrorCode.NO_SUCH_TYPE_GENERICS_ARGUMENT);
+ }
+
+ public void test_noSuchType_methodParameterType() throws Exception {
+ resolveAndTest(Joiner.on("\n").join(
+ "class Object {}",
+ "class MyClass {",
+ " Object foo(Unknown p) {",
+ " return null;",
+ " }",
+ "}"),
+ TypeErrorCode.NO_SUCH_TYPE_PARAMETER);
+ }
+
+ public void test_noSuchType_returnType() throws Exception {
+ resolveAndTest(Joiner.on("\n").join(
+ "class Object {}",
+ "class MyClass {",
+ " Unknown foo() {",
+ " return null;",
+ " }",
+ "}"),
+ TypeErrorCode.NO_SUCH_TYPE_RETURN);
+ }
+
+ public void test_noSuchType_inExpression() throws Exception {
+ resolveAndTest(Joiner.on("\n").join(
+ "class Object {}",
+ "class MyClass {",
+ " foo() {",
+ " var bar;",
+ " if (bar is Bar) {",
+ " }",
+ " }",
+ "}"),
+ ResolverErrorCode.NO_SUCH_TYPE_IN_EXPRESSION);
+ }
+
+ public void test_noSuchType_inCatch() throws Exception {
+ resolveAndTest(Joiner.on("\n").join(
+ "class Object {}",
+ "class MyClass {",
+ " foo() {",
+ " try {",
+ " } catch (Unknown e) {",
+ " }",
+ " }",
+ "}"),
+ ResolverErrorCode.NO_SUCH_TYPE_IN_CATCH);
+ }
+
+ public void test_noSuchType_new() throws Exception {
+ resolveAndTest(Joiner.on("\n").join(
+ "class Object {}",
+ "class MyClass {",
+ " foo() {",
+ " new Unknown();",
+ " }",
+ "}"),
+ ResolverErrorCode.NO_SUCH_TYPE_NEW,
+ ResolverErrorCode.NEW_EXPRESSION_NOT_CONSTRUCTOR);
}
/**
@@ -545,14 +624,83 @@ public class ResolverTest extends ResolverTestCase {
* second unknown type "UnknownB", we expect in {@link Elements#findElement()} specific
* {@link ClassElement} implementation and {@link DynamicElement} is not valid.
*/
- public void test_classDynamicElement_fieldDynamicElement() throws Exception {
+ public void test_classExtendsUnknown_fieldUnknownType() throws Exception {
resolveAndTest(Joiner.on("\n").join(
"class Object {}",
- "class MyClass implements UnknownA {",
+ "class MyClass extends UnknownA {",
" UnknownB field;",
"}"),
- ResolverErrorCode.NO_SUCH_TYPE,
- ResolverErrorCode.NOT_A_CLASS_OR_INTERFACE,
- ResolverErrorCode.NO_SUCH_TYPE);
+ ResolverErrorCode.NO_SUCH_TYPE_EXTENDS,
+ TypeErrorCode.NO_SUCH_TYPE_FIELD);
+ }
+
+ /**
+ * When {@link SupertypeResolver} can not find "UnknownA", it uses {@link DynamicType}, which
+ * returns {@link DynamicElement}. By itself, this is OK. However when we later try to resolve
+ * super() constructor invocation, this should not cause exception.
+ */
+ public void test_classExtendsUnknown_callSuperConstructor() throws Exception {
+ resolveAndTest(Joiner.on("\n").join(
+ "class Object {}",
+ "class MyClass extends UnknownA {",
+ " MyClass() : super() {",
+ " }",
+ "}"),
+ ResolverErrorCode.NO_SUCH_TYPE_EXTENDS,
+ ResolverErrorCode.CANNOT_RESOLVE_SUPER_CONSTRUCTOR);
+ }
+
+ public void test_shadowType_withVariable() throws Exception {
+ resolveAndTest(Joiner.on("\n").join(
+ "class Object {}",
+ "class Foo<T> {}",
+ "class Param {}",
+ "class MyClass {",
+ " foo() {",
+ " var Param;",
+ " new Foo<Param>();",
+ " }",
+ "}"),
+ TypeErrorCode.NO_SUCH_TYPE_GENERICS_ARGUMENT);
+ }
+
+ // TODO(scheglov) check for "extends/implements Dynamic"
+ public void _test_extendsDynamic() throws Exception {
+ resolveAndTest(Joiner.on("\n").join(
+ "class Object {}",
+ "class MyClass extends Dynamic {",
+ "}"),
+ ResolverErrorCode.DYNAMIC_EXTENDS);
+ }
+
+ // TODO(scheglov) check for "extends/implements Dynamic"
+ public void _test_implementsDynamic() throws Exception {
+ resolveAndTest(Joiner.on("\n").join(
+ "class Object {}",
+ "class MyClass implements Dynamic {",
+ "}"),
+ ResolverErrorCode.DYNAMIC_IMPLEMENTS);
+ }
+
+ public void test_explicitDynamicTypeArgument() throws Exception {
+ resolveAndTest(Joiner.on("\n").join(
+ "class Object {}",
+ "class Map<K, V>{}",
+ "class MyClass implements Map<Object, Dynamic> {",
+ "}"));
+ }
+
+ public void test_operatorIs_withFunctionAlias() throws Exception {
+ resolveAndTest(Joiner.on("\n").join(
+ "class Object {}",
+ "class int {}",
+ "typedef Dynamic F1<T>(Dynamic x, T y);",
+ "class MyClass {",
+ " main() {",
+ " F1<int> f1 = (Object o, int i) => null;",
+ " if (f1 is F1<int>) {",
+ " }",
+ " }",
+ "}"));
}
}

Powered by Google App Engine
This is Rietveld 408576698