| 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 'dart:async'; |     5 import 'dart:async'; | 
|     6 import 'dart:collection'; |     6 import 'dart:collection'; | 
|     7  |     7  | 
|     8 import 'package:async_helper/async_helper.dart'; |     8 import 'package:async_helper/async_helper.dart'; | 
|     9 import 'package:expect/expect.dart'; |     9 import 'package:expect/expect.dart'; | 
|    10 import 'package:compiler/src/constants/expressions.dart'; |    10 import 'package:compiler/src/constants/expressions.dart'; | 
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   215     String script = """class A { foo() {} } |   215     String script = """class A { foo() {} } | 
|   216                        class B extends A { foo() => super.foo(); }"""; |   216                        class B extends A { foo() => super.foo(); }"""; | 
|   217     compiler.parseScript(script); |   217     compiler.parseScript(script); | 
|   218     compiler.resolveStatement("B b;"); |   218     compiler.resolveStatement("B b;"); | 
|   219  |   219  | 
|   220     ClassElement classB = compiler.mainApp.find("B"); |   220     ClassElement classB = compiler.mainApp.find("B"); | 
|   221     FunctionElement fooB = classB.lookupLocalMember("foo"); |   221     FunctionElement fooB = classB.lookupLocalMember("foo"); | 
|   222     ClassElement classA = compiler.mainApp.find("A"); |   222     ClassElement classA = compiler.mainApp.find("A"); | 
|   223     FunctionElement fooA = classA.lookupLocalMember("foo"); |   223     FunctionElement fooA = classA.lookupLocalMember("foo"); | 
|   224  |   224  | 
|   225     ResolverVisitor visitor = |   225     ResolverVisitor visitor = new ResolverVisitor( | 
|   226         new ResolverVisitor(compiler, fooB, |   226         compiler, | 
|   227             new ResolutionRegistry(compiler, |   227         fooB, | 
|   228                 new CollectingTreeElements(fooB))); |   228         new ResolutionRegistry(compiler, new CollectingTreeElements(fooB)), | 
 |   229         scope: new MockTypeVariablesScope(classB.buildScope())); | 
|   229     FunctionExpression node = |   230     FunctionExpression node = | 
|   230         (fooB as FunctionElementX).parseNode(compiler.parsingContext); |   231         (fooB as FunctionElementX).parseNode(compiler.parsingContext); | 
|   231     visitor.visit(node.body); |   232     visitor.visit(node.body); | 
|   232     Map mapping = map(visitor); |   233     Map mapping = map(visitor); | 
|   233  |   234  | 
|   234     Send superCall = node.body.asReturn().expression; |   235     Send superCall = node.body.asReturn().expression; | 
|   235     FunctionElement called = mapping[superCall]; |   236     FunctionElement called = mapping[superCall]; | 
|   236     Expect.isNotNull(called); |   237     Expect.isNotNull(called); | 
|   237     Expect.equals(fooA, called); |   238     Expect.equals(fooA, called); | 
|   238   }); |   239   }); | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
|   259   }); |   260   }); | 
|   260 } |   261 } | 
|   261  |   262  | 
|   262 Future testThis() { |   263 Future testThis() { | 
|   263   return Future.wait([ |   264   return Future.wait([ | 
|   264     MockCompiler.create((MockCompiler compiler) { |   265     MockCompiler.create((MockCompiler compiler) { | 
|   265       compiler.parseScript("class Foo { foo() { return this; } }"); |   266       compiler.parseScript("class Foo { foo() { return this; } }"); | 
|   266       compiler.resolveStatement("Foo foo;"); |   267       compiler.resolveStatement("Foo foo;"); | 
|   267       ClassElement fooElement = compiler.mainApp.find("Foo"); |   268       ClassElement fooElement = compiler.mainApp.find("Foo"); | 
|   268       FunctionElement funElement = fooElement.lookupLocalMember("foo"); |   269       FunctionElement funElement = fooElement.lookupLocalMember("foo"); | 
|   269       ResolverVisitor visitor = |   270       ResolverVisitor visitor = new ResolverVisitor( | 
|   270           new ResolverVisitor(compiler, funElement, |   271           compiler, | 
|   271               new ResolutionRegistry(compiler, |   272           funElement, | 
|   272                   new CollectingTreeElements(funElement))); |   273           new ResolutionRegistry( | 
 |   274               compiler, new CollectingTreeElements(funElement)), | 
 |   275           scope: new MockTypeVariablesScope(fooElement.buildScope())); | 
|   273       FunctionExpression function = |   276       FunctionExpression function = | 
|   274           (funElement as FunctionElementX).parseNode(compiler.parsingContext); |   277           (funElement as FunctionElementX).parseNode(compiler.parsingContext); | 
|   275       visitor.visit(function.body); |   278       visitor.visit(function.body); | 
|   276       Map mapping = map(visitor); |   279       Map mapping = map(visitor); | 
|   277       List<Element> values = mapping.values.toList(); |   280       List<Element> values = mapping.values.toList(); | 
|   278       DiagnosticCollector collector = compiler.diagnosticCollector; |   281       DiagnosticCollector collector = compiler.diagnosticCollector; | 
|   279       Expect.equals(0, mapping.length); |   282       Expect.equals(0, mapping.length); | 
|   280       Expect.equals(0, collector.warnings.length); |   283       Expect.equals(0, collector.warnings.length); | 
|   281     }), |   284     }), | 
|   282     MockCompiler.create((MockCompiler compiler) { |   285     MockCompiler.create((MockCompiler compiler) { | 
|   283       compiler.resolveStatement("main() { return this; }"); |   286       compiler.resolveStatement("main() { return this; }"); | 
|   284       DiagnosticCollector collector = compiler.diagnosticCollector; |   287       DiagnosticCollector collector = compiler.diagnosticCollector; | 
|   285       Expect.equals(0, collector.warnings.length); |   288       Expect.equals(0, collector.warnings.length); | 
|   286       Expect.equals(1, collector.errors.length); |   289       Expect.equals(1, collector.errors.length); | 
|   287       Expect.equals(MessageKind.NO_INSTANCE_AVAILABLE, |   290       Expect.equals(MessageKind.NO_INSTANCE_AVAILABLE, | 
|   288                     collector.errors.first.message.kind); |   291                     collector.errors.first.message.kind); | 
|   289     }), |   292     }), | 
|   290     MockCompiler.create((MockCompiler compiler) { |   293     MockCompiler.create((MockCompiler compiler) { | 
|   291       compiler.parseScript("class Foo { static foo() { return this; } }"); |   294       compiler.parseScript("class Foo { static foo() { return this; } }"); | 
|   292       compiler.resolveStatement("Foo foo;"); |   295       compiler.resolveStatement("Foo foo;"); | 
|   293       ClassElement fooElement = compiler.mainApp.find("Foo"); |   296       ClassElement fooElement = compiler.mainApp.find("Foo"); | 
|   294       FunctionElement funElement = fooElement.lookupLocalMember("foo"); |   297       FunctionElement funElement = fooElement.lookupLocalMember("foo"); | 
|   295       ResolverVisitor visitor = new ResolverVisitor(compiler, funElement, |   298       ResolverVisitor visitor = new ResolverVisitor( | 
|   296           new ResolutionRegistry(compiler, |   299           compiler, | 
|   297               new CollectingTreeElements(funElement))); |   300           funElement, | 
 |   301           new ResolutionRegistry( | 
 |   302               compiler, new CollectingTreeElements(funElement)), | 
 |   303           scope: new MockTypeVariablesScope(fooElement.buildScope())); | 
|   298       FunctionExpression function = |   304       FunctionExpression function = | 
|   299           (funElement as FunctionElementX).parseNode(compiler.parsingContext); |   305           (funElement as FunctionElementX).parseNode(compiler.parsingContext); | 
|   300       visitor.visit(function.body); |   306       visitor.visit(function.body); | 
|   301       DiagnosticCollector collector = compiler.diagnosticCollector; |   307       DiagnosticCollector collector = compiler.diagnosticCollector; | 
|   302       Expect.equals(0, collector.warnings.length); |   308       Expect.equals(0, collector.warnings.length); | 
|   303       Expect.equals(1, collector.errors.length); |   309       Expect.equals(1, collector.errors.length); | 
|   304       Expect.equals(MessageKind.NO_INSTANCE_AVAILABLE, |   310       Expect.equals(MessageKind.NO_INSTANCE_AVAILABLE, | 
|   305                     collector.errors.first.message.kind); |   311                     collector.errors.first.message.kind); | 
|   306     }), |   312     }), | 
|   307   ]); |   313   ]); | 
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   574         new Message( |   580         new Message( | 
|   575             MessageTemplate.TEMPLATES[MessageKind.CANNOT_RESOLVE_TYPE], |   581             MessageTemplate.TEMPLATES[MessageKind.CANNOT_RESOLVE_TYPE], | 
|   576             {'typeName': 'bar'}, false), |   582             {'typeName': 'bar'}, false), | 
|   577         collector.errors.first.message); |   583         collector.errors.first.message); | 
|   578     collector.clear(); |   584     collector.clear(); | 
|   579  |   585  | 
|   580     // Add the abstract class to the world and make sure everything is setup |   586     // Add the abstract class to the world and make sure everything is setup | 
|   581     // correctly. |   587     // correctly. | 
|   582     compiler.parseScript("abstract class Bar {}"); |   588     compiler.parseScript("abstract class Bar {}"); | 
|   583  |   589  | 
|   584     ResolverVisitor visitor = |   590     ResolverVisitor visitor = new ResolverVisitor( | 
|   585         new ResolverVisitor(compiler, null, |   591         compiler, | 
|   586             new ResolutionRegistry(compiler, |   592         null, | 
|   587                 new CollectingTreeElements(null))); |   593         new ResolutionRegistry(compiler, new CollectingTreeElements(null))); | 
|   588     compiler.resolveStatement("Foo bar;"); |   594     compiler.resolveStatement("Foo bar;"); | 
|   589  |   595  | 
|   590     ClassElement fooElement = compiler.mainApp.find('Foo'); |   596     ClassElement fooElement = compiler.mainApp.find('Foo'); | 
|   591     ClassElement barElement = compiler.mainApp.find('Bar'); |   597     ClassElement barElement = compiler.mainApp.find('Bar'); | 
|   592  |   598  | 
|   593     Expect.equals(null, barElement.supertype); |   599     Expect.equals(null, barElement.supertype); | 
|   594     Expect.isTrue(barElement.interfaces.isEmpty); |   600     Expect.isTrue(barElement.interfaces.isEmpty); | 
|   595  |   601  | 
|   596     Expect.equals(barElement.computeType(compiler.resolution), |   602     Expect.equals(barElement.computeType(compiler.resolution), | 
|   597                   fooElement.interfaces.head); |   603                   fooElement.interfaces.head); | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
|   612     ClassElement i2 = compiler.mainApp.find('I2'); |   618     ClassElement i2 = compiler.mainApp.find('I2'); | 
|   613  |   619  | 
|   614     Expect.equals(2, length(c.interfaces)); |   620     Expect.equals(2, length(c.interfaces)); | 
|   615     Expect.equals(i1.computeType(compiler.resolution), at(c.interfaces, 0)); |   621     Expect.equals(i1.computeType(compiler.resolution), at(c.interfaces, 0)); | 
|   616     Expect.equals(i2.computeType(compiler.resolution), at(c.interfaces, 1)); |   622     Expect.equals(i2.computeType(compiler.resolution), at(c.interfaces, 1)); | 
|   617   }); |   623   }); | 
|   618 } |   624 } | 
|   619  |   625  | 
|   620 Future testFunctionExpression() { |   626 Future testFunctionExpression() { | 
|   621   return MockCompiler.create((MockCompiler compiler) { |   627   return MockCompiler.create((MockCompiler compiler) { | 
|   622     ResolverVisitor visitor = compiler.resolverVisitor(); |  | 
|   623     Map mapping = compiler.resolveStatement("int f() {}").map; |   628     Map mapping = compiler.resolveStatement("int f() {}").map; | 
|   624     Expect.equals(2, mapping.length); |   629     Expect.equals(2, mapping.length); | 
|   625     Element element; |   630     Element element; | 
|   626     Node node; |   631     Node node; | 
|   627     mapping.forEach((Node n, Element e) { |   632     mapping.forEach((Node n, Element e) { | 
|   628       if (n is FunctionExpression) { |   633       if (n is FunctionExpression) { | 
|   629         element = e; |   634         element = e; | 
|   630         node = n; |   635         node = n; | 
|   631       } |   636       } | 
|   632     }); |   637     }); | 
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   694      List expectedInfos: const [], |   699      List expectedInfos: const [], | 
|   695      Map<String, String> corelib}) { |   700      Map<String, String> corelib}) { | 
|   696   MockCompiler compiler = new MockCompiler.internal(coreSource: corelib); |   701   MockCompiler compiler = new MockCompiler.internal(coreSource: corelib); | 
|   697   return compiler.init().then((_) { |   702   return compiler.init().then((_) { | 
|   698     compiler.parseScript(script); |   703     compiler.parseScript(script); | 
|   699     compiler.resolveStatement(statement); |   704     compiler.resolveStatement(statement); | 
|   700     ClassElement classElement = compiler.mainApp.find(className); |   705     ClassElement classElement = compiler.mainApp.find(className); | 
|   701     Element element; |   706     Element element; | 
|   702     element = classElement.lookupConstructor(constructor); |   707     element = classElement.lookupConstructor(constructor); | 
|   703     FunctionExpression tree = (element as FunctionElement).node; |   708     FunctionExpression tree = (element as FunctionElement).node; | 
|   704     ResolverVisitor visitor = |   709     ResolverVisitor visitor = new ResolverVisitor( | 
|   705         new ResolverVisitor(compiler, element, |   710         compiler, | 
|   706             new ResolutionRegistry(compiler, |   711         element, | 
|   707                 new CollectingTreeElements(element))); |   712         new ResolutionRegistry(compiler, new CollectingTreeElements(element)), | 
 |   713         scope: classElement.buildScope()); | 
|   708     new InitializerResolver(visitor, element, tree).resolveInitializers(); |   714     new InitializerResolver(visitor, element, tree).resolveInitializers(); | 
|   709     visitor.visit(tree.body); |   715     visitor.visit(tree.body); | 
|   710     Expect.equals(expectedElementCount, map(visitor).length, |   716     Expect.equals(expectedElementCount, map(visitor).length, | 
|   711         "${map(visitor).values} for '$statement' in context of `$script`"); |   717         "${map(visitor).values} for '$statement' in context of `$script`"); | 
|   712  |   718  | 
|   713     DiagnosticCollector collector = compiler.diagnosticCollector; |   719     DiagnosticCollector collector = compiler.diagnosticCollector; | 
|   714     compareWarningKinds(script, expectedWarnings, collector.warnings); |   720     compareWarningKinds(script, expectedWarnings, collector.warnings); | 
|   715     compareWarningKinds(script, expectedErrors, collector.errors); |   721     compareWarningKinds(script, expectedErrors, collector.errors); | 
|   716     compareWarningKinds(script, expectedInfos, collector.infos); |   722     compareWarningKinds(script, expectedInfos, collector.infos); | 
|   717   }); |   723   }); | 
| (...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1441     } |  1447     } | 
|  1442     main() => A.m(); |  1448     main() => A.m(); | 
|  1443   ''', functionName: 'm'); |  1449   ''', functionName: 'm'); | 
|  1444   check(''' |  1450   check(''' | 
|  1445     class A { |  1451     class A { | 
|  1446       m() => () => await - 3; |  1452       m() => () => await - 3; | 
|  1447     } |  1453     } | 
|  1448     main() => new A().m(); |  1454     main() => new A().m(); | 
|  1449   ''', className: 'A'); |  1455   ''', className: 'A'); | 
|  1450 } |  1456 } | 
| OLD | NEW |