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

Unified Diff: pkg/analyzer/test/generated/resolver_test.dart

Issue 650323003: Allow analyzer to distinguish unresolved types from dynamic. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | tests/language/language_analyzer2.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/generated/resolver_test.dart
diff --git a/pkg/analyzer/test/generated/resolver_test.dart b/pkg/analyzer/test/generated/resolver_test.dart
index f10dc5634d5670362cff740f42e46943775eb2b3..6c7e93cfdbdecb2a9faed619ecdb4de646faa5b1 100644
--- a/pkg/analyzer/test/generated/resolver_test.dart
+++ b/pkg/analyzer/test/generated/resolver_test.dart
@@ -437,6 +437,21 @@ class CheckedModeCompileTimeErrorCodeTest extends ResolverTestCase {
verify([source]);
}
+ void test_fieldFormalParameterAssignableToField_fieldType_unresolved_null() {
+ // Null always passes runtime type checks, even when the type is
+ // unresolved.
+ Source source = addSource(EngineTestCase.createSource([
+ "class A {",
+ " final Unresolved x;",
+ " const A(String this.x);",
+ "}",
+ "var v = const A(null);"]));
+ resolve(source);
+ assertErrors(source, [
+ StaticWarningCode.UNDEFINED_CLASS]);
+ verify([source]);
+ }
+
void test_fieldFormalParameterAssignableToField_implements() {
// According to checked-mode type checking rules, a value of type B is
// assignable to a field of type A, because B implements A (and hence is a
@@ -604,6 +619,20 @@ class CheckedModeCompileTimeErrorCodeTest extends ResolverTestCase {
verify([source]);
}
+ void test_fieldFormalParameterNotAssignableToField_fieldType_unresolved() {
+ Source source = addSource(EngineTestCase.createSource([
+ "class A {",
+ " final Unresolved x;",
+ " const A(String this.x);",
+ "}",
+ "var v = const A('foo');"]));
+ resolve(source);
+ assertErrors(source, [
+ CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH,
+ StaticWarningCode.UNDEFINED_CLASS]);
+ verify([source]);
+ }
+
void test_fieldFormalParameterNotAssignableToField_extends() {
// According to checked-mode type checking rules, a value of type A is not
// assignable to a field of type B, because B extends A (the subtyping
@@ -745,6 +774,20 @@ class CheckedModeCompileTimeErrorCodeTest extends ResolverTestCase {
verify([source]);
}
+ void test_fieldTypeMismatch_unresolved() {
+ Source source = addSource(EngineTestCase.createSource([
+ "class A {",
+ " const A(x) : y = x;",
+ " final Unresolved y;",
+ "}",
+ "var v = const A('foo');"]));
+ resolve(source);
+ assertErrors(source, [
+ CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH,
+ StaticWarningCode.UNDEFINED_CLASS]);
+ verify([source]);
+ }
+
void test_fieldTypeOk_null() {
Source source = addSource(EngineTestCase.createSource([
"class A {",
@@ -757,6 +800,21 @@ class CheckedModeCompileTimeErrorCodeTest extends ResolverTestCase {
verify([source]);
}
+ void test_fieldTypeOk_unresolved_null() {
+ // Null always passes runtime type checks, even when the type is
+ // unresolved.
+ Source source = addSource(EngineTestCase.createSource([
+ "class A {",
+ " const A(x) : y = x;",
+ " final Unresolved y;",
+ "}",
+ "var v = const A(null);"]));
+ resolve(source);
+ assertErrors(source, [
+ StaticWarningCode.UNDEFINED_CLASS]);
+ verify([source]);
+ }
+
void test_listElementTypeNotAssignable() {
Source source = addSource(EngineTestCase.createSource(["var v = const <String> [42];"]));
resolve(source);
@@ -796,6 +854,20 @@ class CheckedModeCompileTimeErrorCodeTest extends ResolverTestCase {
verify([source]);
}
+ void test_parameterAssignable_undefined_null() {
+ // Null always passes runtime type checks, even when the type is
+ // unresolved.
+ Source source = addSource(EngineTestCase.createSource([
+ "class A {",
+ " const A(Unresolved x);",
+ "}",
+ "var v = const A(null);"]));
+ resolve(source);
+ assertErrors(source, [
+ StaticWarningCode.UNDEFINED_CLASS]);
+ verify([source]);
+ }
+
void test_parameterAssignable_typeSubstitution() {
Source source = addSource(EngineTestCase.createSource([
"class A<T> {",
@@ -820,6 +892,19 @@ class CheckedModeCompileTimeErrorCodeTest extends ResolverTestCase {
verify([source]);
}
+ void test_parameterNotAssignable_undefined() {
+ Source source = addSource(EngineTestCase.createSource([
+ "class A {",
+ " const A(Unresolved x);",
+ "}",
+ "var v = const A('foo');"]));
+ resolve(source);
+ assertErrors(source, [
+ CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH,
+ StaticWarningCode.UNDEFINED_CLASS]);
+ verify([source]);
+ }
+
void test_parameterNotAssignable_typeSubstitution() {
Source source = addSource(EngineTestCase.createSource([
"class A<T> {",
@@ -841,6 +926,17 @@ class CheckedModeCompileTimeErrorCodeTest extends ResolverTestCase {
verify([source]);
}
+ void test_topLevelVarAssignable_undefined_null() {
+ // Null always passes runtime type checks, even when the type is
+ // unresolved.
+ Source source = addSource(EngineTestCase.createSource([
+ "const Unresolved x = null;"]));
+ resolve(source);
+ assertErrors(source, [
+ StaticWarningCode.UNDEFINED_CLASS]);
+ verify([source]);
+ }
+
void test_topLevelVarNotAssignable() {
Source source = addSource(EngineTestCase.createSource([
"const int x = 'foo';"]));
@@ -850,6 +946,16 @@ class CheckedModeCompileTimeErrorCodeTest extends ResolverTestCase {
StaticTypeWarningCode.INVALID_ASSIGNMENT]);
verify([source]);
}
+
+ void test_topLevelVarNotAssignable_undefined() {
+ Source source = addSource(EngineTestCase.createSource([
+ "const Unresolved x = 'foo';"]));
+ resolve(source);
+ assertErrors(source, [
+ CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH,
+ StaticWarningCode.UNDEFINED_CLASS]);
+ verify([source]);
+ }
}
class DeclarationMatcherTest extends ResolverTestCase {
@@ -8445,7 +8551,7 @@ class StaticTypeVerifier extends GeneralizingAstVisitor<Object> {
Object visitPrefixedIdentifier(PrefixedIdentifier node) {
// In cases where we have a prefixed identifier where the prefix is dynamic, we don't want to
// assert that the node will have a type.
- if (node.staticType == null && identical(node.prefix.staticType, DynamicTypeImpl.instance)) {
+ if (node.staticType == null && node.prefix.staticType.isDynamic) {
return null;
}
return super.visitPrefixedIdentifier(node);
@@ -8838,6 +8944,11 @@ class TestTypeProvider implements TypeProvider {
*/
InterfaceType _typeType;
+ /**
+ * The type representing typenames that can't be resolved.
+ */
+ DartType _undefinedType;
+
@override
InterfaceType get boolType {
if (_boolType == null) {
@@ -9046,6 +9157,14 @@ class TestTypeProvider implements TypeProvider {
return _typeType;
}
+ @override
+ DartType get undefinedType {
+ if (_undefinedType == null) {
+ _undefinedType = UndefinedTypeImpl.instance;
+ }
+ return _undefinedType;
+ }
+
/**
* Initialize the numeric types. They are created as a group so that we can (a) create the right
* hierarchy and (b) add members to them.
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | tests/language/language_analyzer2.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698