| Index: frog/tests/leg/src/ResolverTest.dart
|
| diff --git a/frog/tests/leg/src/ResolverTest.dart b/frog/tests/leg/src/ResolverTest.dart
|
| index be28905929a053488f3ab105b348f3482daca385..4a30933291b71eb087383f9a714b0023e25d9fe0 100644
|
| --- a/frog/tests/leg/src/ResolverTest.dart
|
| +++ b/frog/tests/leg/src/ResolverTest.dart
|
| @@ -64,6 +64,7 @@ main() {
|
| testFunctionExpression();
|
| testNewExpression();
|
| testTopLevelFields();
|
| + testInitializers();
|
| }
|
|
|
| testLocalsOne() {
|
| @@ -377,6 +378,72 @@ testTopLevelFields() {
|
| Expect.equals(bNode.type.typeName.source.stringValue, 'var');
|
| }
|
|
|
| +resolveConstructor(String script, String statement, String className,
|
| + String constructor, int expectedElementCount,
|
| + [List expectedWarnings = const [],
|
| + List expectedErrors = const []]) {
|
| + MockCompiler compiler = new MockCompiler();
|
| + compiler.parseScript(script);
|
| + compiler.resolveStatement(statement);
|
| + ClassElement classElement =
|
| + compiler.universe.find(buildSourceString(className));
|
| + Element element =
|
| + classElement.lookupLocalElement(buildSourceString(constructor));
|
| + Node tree = element.parseNode(compiler, compiler);
|
| + ResolverVisitor visitor = new SignatureResolverVisitor(compiler, element);
|
| + visitor.visit(tree);
|
| + Expect.equals(expectedElementCount, visitor.mapping.map.length);
|
| +
|
| + visitor = new FullResolverVisitor.from(visitor);
|
| + for (Link<Node> link = tree.initializers.nodes;
|
| + !link.isEmpty();
|
| + link = link.tail) {
|
| + SendSet init = link.head;
|
| + Node value = init.arguments.head;
|
| + visitor.visitIn(value, new StaticScope(visitor.context));
|
| + }
|
| +
|
| + compareWarningKinds(script, expectedWarnings, compiler.warnings);
|
| + compareWarningKinds(script, expectedErrors, compiler.errors);
|
| +}
|
| +
|
| +testInitializers() {
|
| + String script;
|
| + script = """class A {
|
| + int foo; int bar;
|
| + A() : this.foo = 1, bar = 2;
|
| + }""";
|
| + resolveConstructor(script, "A a = new A();", "A", "A", 3);
|
| +
|
| + script = """class A {
|
| + int foo; A a;
|
| + A() : a.foo = 1;
|
| + }""";
|
| + resolveConstructor(script, "A a = new A();", "A", "A", 2,
|
| + [], [MessageKind.INVALID_RECEIVER_IN_INITIALIZER]);
|
| +
|
| + script = """class A {
|
| + int foo;
|
| + A() : this.foo = 1, this.foo = 2;
|
| + }""";
|
| + resolveConstructor(script, "A a = new A();", "A", "A", 3,
|
| + [MessageKind.DUPLICATION_INITIALIZATION]);
|
| +
|
| + script = """class A {
|
| + A() : this.foo = 1;
|
| + }""";
|
| + resolveConstructor(script, "A a = new A();", "A", "A", 1,
|
| + [], [MessageKind.CANNOT_RESOLVE]);
|
| +
|
| + script = """class A {
|
| + int foo;
|
| + int bar;
|
| + A() : this.foo = bar;
|
| + }""";
|
| + resolveConstructor(script, "A a = new A();", "A", "A", 2,
|
| + [], [MessageKind.CANNOT_RESOLVE]);
|
| +}
|
| +
|
| length(Link link) => link.isEmpty() ? 0 : length(link.tail) + 1;
|
|
|
| at(Link link, int index) => (index == 0) ? link.head : at(link.tail, index - 1);
|
|
|