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

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

Issue 641413002: Substitute type parameters when evaluating const literal maps/lists. (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/constant.dart ('k') | no next file » | 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 230aecb8a7dbfedebb3fa2e5fa3b8478bc5fbf53..2e5da6f2665387274ef79c3778904c14e4a293e0 100644
--- a/pkg/analyzer/test/generated/resolver_test.dart
+++ b/pkg/analyzer/test/generated/resolver_test.dart
@@ -459,6 +459,69 @@ class CheckedModeCompileTimeErrorCodeTest extends ResolverTestCase {
verify([source]);
}
+ void test_fieldFormalParameterAssignableToField_list_dynamic() {
+ // [1, 2, 3] has type List<dynamic>, which is a subtype of List<int>.
+ Source source = addSource(EngineTestCase.createSource([
+ "class A {",
+ " const A(List<int> x);",
+ "}",
+ "var x = const A(const [1, 2, 3]);"]));
+ resolve(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
+ void test_fieldFormalParameterAssignableToField_list_nonDynamic() {
+ // <int>[1, 2, 3] has type List<int>, which is a subtype of List<num>.
+ Source source = addSource(EngineTestCase.createSource([
+ "class A {",
+ " const A(List<num> x);",
+ "}",
+ "var x = const A(const <int>[1, 2, 3]);"]));
+ resolve(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
+ void test_fieldFormalParameterAssignableToField_map_dynamic() {
+ // {1: 2} has type Map<dynamic, dynamic>, which is a subtype of
+ // Map<int, int>.
+ Source source = addSource(EngineTestCase.createSource([
+ "class A {",
+ " const A(Map<int, int> x);",
+ "}",
+ "var x = const A(const {1: 2});"]));
+ resolve(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
+ void test_fieldFormalParameterAssignableToField_map_keyDifferent() {
+ // <int, int>{1: 2} has type Map<int, int>, which is a subtype of
+ // Map<num, int>.
+ Source source = addSource(EngineTestCase.createSource([
+ "class A {",
+ " const A(Map<num, int> x);",
+ "}",
+ "var x = const A(const <int, int>{1: 2});"]));
+ resolve(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
+ void test_fieldFormalParameterAssignableToField_map_valueDifferent() {
+ // <int, int>{1: 2} has type Map<int, int>, which is a subtype of
+ // Map<int, num>.
+ Source source = addSource(EngineTestCase.createSource([
+ "class A {",
+ " const A(Map<int, num> x);",
+ "}",
+ "var x = const A(const <int, int>{1: 2});"]));
+ resolve(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
void test_fieldFormalParameterAssignableToField_notype() {
// If a field is declared without a type, then any value may be assigned to
// it.
@@ -486,31 +549,31 @@ class CheckedModeCompileTimeErrorCodeTest extends ResolverTestCase {
verify([source]);
}
- void test_fieldFormalParameterAssignableToField_typedef() {
+ void test_fieldFormalParameterAssignableToField_typeSubstitution() {
// foo has the runtime type dynamic -> dynamic, so it should be assignable
// to A.f.
Source source = addSource(EngineTestCase.createSource([
- "typedef String Int2String(int x);",
- "class A {",
- " final Int2String f;",
- " const A(this.f);",
+ "class A<T> {",
+ " final T x;",
+ " const A(this.x);",
"}",
- "foo(x) => 1;"
- "var v = const A(foo);"]));
+ "var v = const A<int>(3);"]));
resolve(source);
assertNoErrors(source);
verify([source]);
}
- void test_fieldFormalParameterAssignableToField_typeSubstitution() {
+ void test_fieldFormalParameterAssignableToField_typedef() {
// foo has the runtime type dynamic -> dynamic, so it should be assignable
// to A.f.
Source source = addSource(EngineTestCase.createSource([
- "class A<T> {",
- " final T x;",
- " const A(this.x);",
+ "typedef String Int2String(int x);",
+ "class A {",
+ " final Int2String f;",
+ " const A(this.f);",
"}",
- "var v = const A<int>(3);"]));
+ "foo(x) => 1;"
+ "var v = const A(foo);"]));
resolve(source);
assertNoErrors(source);
verify([source]);
@@ -572,6 +635,47 @@ class CheckedModeCompileTimeErrorCodeTest extends ResolverTestCase {
verify([source]);
}
+ void test_fieldFormalParameterNotAssignableToField_list() {
+ // <num>[1, 2, 3] has type List<num>, which is not a subtype of List<int>.
+ Source source = addSource(EngineTestCase.createSource([
+ "class A {",
+ " const A(List<int> x);",
+ "}",
+ "var x = const A(const <num>[1, 2, 3]);"]));
+ resolve(source);
+ assertErrors(source, [
+ CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH]);
+ verify([source]);
+ }
+
+ void test_fieldFormalParameterNotAssignableToField_map_keyMismatch() {
+ // <num, int>{1: 2} has type Map<num, int>, which is not a subtype of
+ // Map<int, int>.
+ Source source = addSource(EngineTestCase.createSource([
+ "class A {",
+ " const A(Map<int, int> x);",
+ "}",
+ "var x = const A(const <num, int>{1: 2});"]));
+ resolve(source);
+ assertErrors(source, [
+ CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH]);
+ verify([source]);
+ }
+
+ void test_fieldFormalParameterNotAssignableToField_map_valueMismatch() {
+ // <int, num>{1: 2} has type Map<int, num>, which is not a subtype of
+ // Map<int, int>.
+ Source source = addSource(EngineTestCase.createSource([
+ "class A {",
+ " const A(Map<int, int> x);",
+ "}",
+ "var x = const A(const <int, num>{1: 2});"]));
+ resolve(source);
+ assertErrors(source, [
+ CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH]);
+ verify([source]);
+ }
+
void test_fieldFormalParameterNotAssignableToField_optional() {
Source source = addSource(EngineTestCase.createSource([
"class A {",
« no previous file with comments | « pkg/analyzer/lib/src/generated/constant.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698