| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 import 'dart:async'; | 6 import 'dart:async'; |
| 7 import "package:async_helper/async_helper.dart"; | 7 import "package:async_helper/async_helper.dart"; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import "../../../sdk/lib/_internal/compiler/implementation/resolution/resolution
.dart"; | 10 import "../../../sdk/lib/_internal/compiler/implementation/resolution/resolution
.dart"; |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 FunctionElement called = mapping[superCall]; | 198 FunctionElement called = mapping[superCall]; |
| 199 Expect.isNotNull(called); | 199 Expect.isNotNull(called); |
| 200 Expect.equals(fooA, called); | 200 Expect.equals(fooA, called); |
| 201 } | 201 } |
| 202 | 202 |
| 203 testThis() { | 203 testThis() { |
| 204 MockCompiler compiler = new MockCompiler(); | 204 MockCompiler compiler = new MockCompiler(); |
| 205 compiler.parseScript("class Foo { foo() { return this; } }"); | 205 compiler.parseScript("class Foo { foo() { return this; } }"); |
| 206 compiler.resolveStatement("Foo foo;"); | 206 compiler.resolveStatement("Foo foo;"); |
| 207 ClassElement fooElement = compiler.mainApp.find("Foo"); | 207 ClassElement fooElement = compiler.mainApp.find("Foo"); |
| 208 FunctionElement funElement = | 208 FunctionElement funElement = fooElement.lookupLocalMember("foo"); |
| 209 fooElement.lookupLocalMember("foo"); | |
| 210 ResolverVisitor visitor = | 209 ResolverVisitor visitor = |
| 211 new ResolverVisitor(compiler, funElement, | 210 new ResolverVisitor(compiler, funElement, |
| 212 new CollectingTreeElements(funElement)); | 211 new CollectingTreeElements(funElement)); |
| 213 FunctionExpression function = funElement.parseNode(compiler); | 212 FunctionExpression function = funElement.parseNode(compiler); |
| 214 visitor.visit(function.body); | 213 visitor.visit(function.body); |
| 215 Map mapping = map(visitor); | 214 Map mapping = map(visitor); |
| 216 List<Element> values = mapping.values.toList(); | 215 List<Element> values = mapping.values.toList(); |
| 217 Expect.equals(0, mapping.length); | 216 Expect.equals(0, mapping.length); |
| 218 Expect.equals(0, compiler.warnings.length); | 217 Expect.equals(0, compiler.warnings.length); |
| 219 | 218 |
| 220 compiler = new MockCompiler(); | 219 compiler = new MockCompiler(); |
| 221 compiler.resolveStatement("main() { return this; }"); | 220 compiler.resolveStatement("main() { return this; }"); |
| 222 Expect.equals(0, compiler.warnings.length); | 221 Expect.equals(0, compiler.warnings.length); |
| 223 Expect.equals(1, compiler.errors.length); | 222 Expect.equals(1, compiler.errors.length); |
| 224 Expect.equals(MessageKind.NO_INSTANCE_AVAILABLE, | 223 Expect.equals(MessageKind.NO_INSTANCE_AVAILABLE, |
| 225 compiler.errors[0].message.kind); | 224 compiler.errors[0].message.kind); |
| 226 | 225 |
| 227 compiler = new MockCompiler(); | 226 compiler = new MockCompiler(); |
| 228 compiler.parseScript("class Foo { static foo() { return this; } }"); | 227 compiler.parseScript("class Foo { static foo() { return this; } }"); |
| 229 compiler.resolveStatement("Foo foo;"); | 228 compiler.resolveStatement("Foo foo;"); |
| 230 fooElement = compiler.mainApp.find("Foo"); | 229 fooElement = compiler.mainApp.find("Foo"); |
| 231 funElement = | 230 funElement = fooElement.lookupLocalMember("foo"); |
| 232 fooElement.lookupLocalMember("foo"); | |
| 233 visitor = new ResolverVisitor(compiler, funElement, | 231 visitor = new ResolverVisitor(compiler, funElement, |
| 234 new CollectingTreeElements(funElement)); | 232 new CollectingTreeElements(funElement)); |
| 235 function = funElement.parseNode(compiler); | 233 function = funElement.parseNode(compiler); |
| 236 visitor.visit(function.body); | 234 visitor.visit(function.body); |
| 237 Expect.equals(0, compiler.warnings.length); | 235 Expect.equals(0, compiler.warnings.length); |
| 238 Expect.equals(1, compiler.errors.length); | 236 Expect.equals(1, compiler.errors.length); |
| 239 Expect.equals(MessageKind.NO_INSTANCE_AVAILABLE, | 237 Expect.equals(MessageKind.NO_INSTANCE_AVAILABLE, |
| 240 compiler.errors[0].message.kind); | 238 compiler.errors[0].message.kind); |
| 241 } | 239 } |
| 242 | 240 |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 | 612 |
| 615 resolveConstructor(String script, String statement, String className, | 613 resolveConstructor(String script, String statement, String className, |
| 616 String constructor, int expectedElementCount, | 614 String constructor, int expectedElementCount, |
| 617 {List expectedWarnings: const [], | 615 {List expectedWarnings: const [], |
| 618 List expectedErrors: const [], | 616 List expectedErrors: const [], |
| 619 List expectedInfos: const [], | 617 List expectedInfos: const [], |
| 620 String corelib: DEFAULT_CORELIB}) { | 618 String corelib: DEFAULT_CORELIB}) { |
| 621 MockCompiler compiler = new MockCompiler(coreSource: corelib); | 619 MockCompiler compiler = new MockCompiler(coreSource: corelib); |
| 622 compiler.parseScript(script); | 620 compiler.parseScript(script); |
| 623 compiler.resolveStatement(statement); | 621 compiler.resolveStatement(statement); |
| 624 ClassElement classElement = | 622 ClassElement classElement = compiler.mainApp.find(className); |
| 625 compiler.mainApp.find(className); | |
| 626 Element element; | 623 Element element; |
| 627 if (constructor != '') { | 624 if (constructor != '') { |
| 628 element = classElement.lookupConstructor( | 625 element = classElement.lookupConstructor( |
| 629 new Selector.callConstructor(constructor, | 626 new Selector.callConstructor(constructor, classElement.getLibrary())); |
| 630 classElement.getLibrary())); | |
| 631 } else { | 627 } else { |
| 632 element = classElement.lookupConstructor( | 628 element = classElement.lookupConstructor( |
| 633 new Selector.callDefaultConstructor(classElement.getLibrary())); | 629 new Selector.callDefaultConstructor(classElement.getLibrary())); |
| 634 } | 630 } |
| 635 | 631 |
| 636 FunctionExpression tree = element.parseNode(compiler); | 632 FunctionExpression tree = element.parseNode(compiler); |
| 637 ResolverVisitor visitor = | 633 ResolverVisitor visitor = |
| 638 new ResolverVisitor(compiler, element, | 634 new ResolverVisitor(compiler, element, |
| 639 new CollectingTreeElements(element)); | 635 new CollectingTreeElements(element)); |
| 640 new InitializerResolver(visitor).resolveInitializers(element, tree); | 636 new InitializerResolver(visitor).resolveInitializers(element, tree); |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 }"""; | 964 }"""; |
| 969 asyncTest(() => compileScript(script2).then((compiler) { | 965 asyncTest(() => compileScript(script2).then((compiler) { |
| 970 expect(compiler, | 966 expect(compiler, |
| 971 [MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS], | 967 [MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS], |
| 972 [MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_CONSTRUCTOR, | 968 [MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_CONSTRUCTOR, |
| 973 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_CONSTRUCTOR, | 969 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_CONSTRUCTOR, |
| 974 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_FIELD, | 970 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_FIELD, |
| 975 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_FIELD]); | 971 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_FIELD]); |
| 976 })); | 972 })); |
| 977 } | 973 } |
| OLD | NEW |