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

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

Issue 640813004: Handle non-factory redirects in constant evaluation. (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') | pkg/analyzer/test/generated/resolver_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/generated/all_the_rest.dart
diff --git a/pkg/analyzer/test/generated/all_the_rest.dart b/pkg/analyzer/test/generated/all_the_rest.dart
index 05a433b164a3aac41f9f0c2a437bc8847792050a..c194f19f41a3cc51cc918760ce925b011ef9251b 100644
--- a/pkg/analyzer/test/generated/all_the_rest.dart
+++ b/pkg/analyzer/test/generated/all_the_rest.dart
@@ -3806,6 +3806,89 @@ class ConstantValueComputerTest extends ResolverTestCase {
[]);
}
+ void test_dependencyOnNonFactoryRedirect() {
+ // a depends on A.foo() depends on A.bar()
+ _assertProperDependencies(
+ EngineTestCase.createSource(
+ [
+ "const A a = const A.foo();",
+ "class A {",
+ " const A.foo() : this.bar();",
+ " const A.bar();",
+ "}"]),
+ []);
+ }
+
+ void test_dependencyOnNonFactoryRedirect_arg() {
+ // a depends on A.foo() depends on b
+ _assertProperDependencies(
+ EngineTestCase.createSource(
+ [
+ "const A a = const A.foo();",
+ "const int b = 1;",
+ "class A {",
+ " const A.foo() : this.bar(b);",
+ " const A.bar(x) : y = x;",
+ " final int y;"
+ "}"]),
+ []);
+ }
+
+ void test_dependencyOnNonFactoryRedirect_defaultValue() {
+ // a depends on A.foo() depends on A.bar() depends on b
+ _assertProperDependencies(
+ EngineTestCase.createSource(
+ [
+ "const A a = const A.foo();",
+ "const int b = 1;",
+ "class A {",
+ " const A.foo() : this.bar();",
+ " const A.bar([x = b]) : y = x;",
+ " final int y;",
+ "}"]),
+ []);
+ }
+
+ void test_dependencyOnNonFactoryRedirect_toMissing() {
+ // a depends on A.foo() which depends on nothing, since A.bar() is
+ // missing.
+ _assertProperDependencies(
+ EngineTestCase.createSource(
+ [
+ "const A a = const A.foo();",
+ "class A {",
+ " const A.foo() : this.bar();",
+ "}"]),
+ [CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_MISSING_CONSTRUCTOR]);
+ }
+
+ void test_dependencyOnNonFactoryRedirect_toNonConst() {
+ // a depends on A.foo() which depends on nothing, since A.bar() is
+ // non-const.
+ _assertProperDependencies(
+ EngineTestCase.createSource(
+ [
+ "const A a = const A.foo();",
+ "class A {",
+ " const A.foo() : this.bar();",
+ " A.bar();",
+ "}"]),
+ []);
+ }
+
+ void test_dependencyOnNonFactoryRedirect_unnamed() {
+ // a depends on A.foo() depends on A()
+ _assertProperDependencies(
+ EngineTestCase.createSource(
+ [
+ "const A a = const A.foo();",
+ "class A {",
+ " const A.foo() : this();",
+ " const A();",
+ "}"]),
+ []);
+ }
+
void test_dependencyOnOptionalParameterDefault() {
// a depends on A() depends on B()
_assertProperDependencies(
@@ -4126,6 +4209,119 @@ class ConstantValueComputerTest extends ResolverTestCase {
_assertIntField(superclassFields, "x", 3);
}
+ void test_instanceCreationExpression_nonFactoryRedirect() {
+ CompilationUnit compilationUnit = resolveSource(
+ EngineTestCase.createSource(
+ [
+ "const foo = const A.a1();",
+ "class A {",
+ " const A.a1() : this.a2();",
+ " const A.a2() : x = 5;",
+ " final int x;",
+ "}"]));
+ Map<String, DartObjectImpl> aFields = _assertType(
+ _evaluateInstanceCreationExpression(compilationUnit, "foo"),
+ "A");
+ _assertIntField(aFields, 'x', 5);
+ }
+
+ void test_instanceCreationExpression_nonFactoryRedirect_arg() {
+ CompilationUnit compilationUnit = resolveSource(
+ EngineTestCase.createSource(
+ [
+ "const foo = const A.a1(1);",
+ "class A {",
+ " const A.a1(x) : this.a2(x + 100);",
+ " const A.a2(x) : y = x + 10;",
+ " final int y;",
+ "}"]));
+ Map<String, DartObjectImpl> aFields = _assertType(
+ _evaluateInstanceCreationExpression(compilationUnit, "foo"),
+ "A");
+ _assertIntField(aFields, 'y', 111);
+ }
+
+ void test_instanceCreationExpression_nonFactoryRedirect_cycle() {
+ // It is an error to have a cycle in non-factory redirects; however, we
+ // need to make sure that even if the error occurs, attempting to evaluate
+ // the constant will terminate.
+ CompilationUnit compilationUnit = resolveSource(
+ EngineTestCase.createSource(
+ [
+ "const foo = const A();",
+ "class A {",
+ " const A() : this.b();",
+ " const A.b() : this();",
+ "}"]));
+ _assertValidUnknown(
+ _evaluateInstanceCreationExpression(compilationUnit, "foo"));
+ }
+
+ void test_instanceCreationExpression_nonFactoryRedirect_defaultArg() {
+ CompilationUnit compilationUnit = resolveSource(
+ EngineTestCase.createSource(
+ [
+ "const foo = const A.a1();",
+ "class A {",
+ " const A.a1() : this.a2();",
+ " const A.a2([x = 100]) : y = x + 10;",
+ " final int y;",
+ "}"]));
+ Map<String, DartObjectImpl> aFields = _assertType(
+ _evaluateInstanceCreationExpression(compilationUnit, "foo"),
+ "A");
+ _assertIntField(aFields, 'y', 110);
+ }
+
+ void test_instanceCreationExpression_nonFactoryRedirect_toMissing() {
+ CompilationUnit compilationUnit = resolveSource(
+ EngineTestCase.createSource(
+ [
+ "const foo = const A.a1();",
+ "class A {",
+ " const A.a1() : this.a2();",
+ "}"]));
+ // We don't care what value foo evaluates to (since there is a compile
+ // error), but we shouldn't crash, and we should figure
+ // out that it evaluates to an instance of class A.
+ _assertType(
+ _evaluateInstanceCreationExpression(compilationUnit, "foo"),
+ "A");
+ }
+
+ void test_instanceCreationExpression_nonFactoryRedirect_toNonConst() {
+ CompilationUnit compilationUnit = resolveSource(
+ EngineTestCase.createSource(
+ [
+ "const foo = const A.a1();",
+ "class A {",
+ " const A.a1() : this.a2();",
+ " A.a2();",
+ "}"]));
+ // We don't care what value foo evaluates to (since there is a compile
+ // error), but we shouldn't crash, and we should figure
+ // out that it evaluates to an instance of class A.
+ _assertType(
+ _evaluateInstanceCreationExpression(compilationUnit, "foo"),
+ "A");
+ }
+
+ void test_instanceCreationExpression_nonFactoryRedirect_unnamed() {
+ CompilationUnit compilationUnit = resolveSource(
+ EngineTestCase.createSource(
+ [
+ "const foo = const A.a1();",
+ "class A {",
+ " const A.a1() : this();",
+ " const A() : x = 5;",
+ " final int x;",
+ "}"]));
+ Map<String, DartObjectImpl> aFields = _assertType(
+ _evaluateInstanceCreationExpression(compilationUnit, "foo"),
+ "A");
+ _assertIntField(aFields, 'x', 5);
+ }
+
void test_instanceCreationExpression_redirect() {
CompilationUnit compilationUnit = resolveSource(
EngineTestCase.createSource(
« no previous file with comments | « pkg/analyzer/lib/src/generated/constant.dart ('k') | pkg/analyzer/test/generated/resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698