| 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:collection'; | 7 import 'dart:collection'; |
| 7 | 8 |
| 8 import "../../../sdk/lib/_internal/compiler/implementation/resolution/resolution
.dart"; | 9 import "../../../sdk/lib/_internal/compiler/implementation/resolution/resolution
.dart"; |
| 9 import "compiler_helper.dart"; | 10 import "compiler_helper.dart"; |
| 10 import "parser_helper.dart"; | 11 import "parser_helper.dart"; |
| 11 | 12 |
| 12 import '../../../sdk/lib/_internal/compiler/implementation/dart_types.dart'; | 13 import '../../../sdk/lib/_internal/compiler/implementation/dart_types.dart'; |
| 13 | 14 |
| 14 Node buildIdentifier(String name) => new Identifier(scan(name)); | 15 Node buildIdentifier(String name) => new Identifier(scan(name)); |
| 15 | 16 |
| (...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 817 | 818 |
| 818 at(Link link, int index) => (index == 0) ? link.head : at(link.tail, index - 1); | 819 at(Link link, int index) => (index == 0) ? link.head : at(link.tail, index - 1); |
| 819 | 820 |
| 820 List<String> asSortedStrings(Link link) { | 821 List<String> asSortedStrings(Link link) { |
| 821 List<String> result = <String>[]; | 822 List<String> result = <String>[]; |
| 822 for (; !link.isEmpty; link = link.tail) result.add(link.head.toString()); | 823 for (; !link.isEmpty; link = link.tail) result.add(link.head.toString()); |
| 823 result.sort((s1, s2) => s1.compareTo(s2)); | 824 result.sort((s1, s2) => s1.compareTo(s2)); |
| 824 return result; | 825 return result; |
| 825 } | 826 } |
| 826 | 827 |
| 827 compileScript(String source) { | 828 Future compileScript(String source) { |
| 828 Uri uri = new Uri(scheme: 'source'); | 829 Uri uri = new Uri(scheme: 'source'); |
| 829 MockCompiler compiler = compilerFor(source, uri); | 830 MockCompiler compiler = compilerFor(source, uri); |
| 830 compiler.runCompiler(uri); | 831 return compiler.runCompiler(uri).then((_) { |
| 831 return compiler; | 832 return compiler; |
| 833 }); |
| 832 } | 834 } |
| 833 | 835 |
| 834 checkMemberResolved(compiler, className, memberName) { | 836 checkMemberResolved(compiler, className, memberName) { |
| 835 Element memberElement = findElement(compiler, className) | 837 Element memberElement = findElement(compiler, className) |
| 836 .lookupLocalMember(memberName); | 838 .lookupLocalMember(memberName); |
| 837 Expect.isNotNull(memberElement); | 839 Expect.isNotNull(memberElement); |
| 838 Expect.isNotNull( | 840 Expect.isNotNull( |
| 839 compiler.enqueuer.resolution.getCachedElements(memberElement)); | 841 compiler.enqueuer.resolution.getCachedElements(memberElement)); |
| 840 } | 842 } |
| 841 | 843 |
| 842 testToString() { | 844 testToString() { |
| 843 final script = r"class C { toString() => 'C'; } main() { '${new C()}'; }"; | 845 final script = r"class C { toString() => 'C'; } main() { '${new C()}'; }"; |
| 844 final compiler = compileScript(script); | 846 compileScript(script).then((compiler) { |
| 845 | 847 checkMemberResolved(compiler, 'C', buildSourceString('toString')); |
| 846 checkMemberResolved(compiler, 'C', buildSourceString('toString')); | 848 }); |
| 847 } | 849 } |
| 848 | 850 |
| 849 operatorName(op, isUnary) { | 851 operatorName(op, isUnary) { |
| 850 return Elements.constructOperatorName(new SourceString(op), isUnary); | 852 return Elements.constructOperatorName(new SourceString(op), isUnary); |
| 851 } | 853 } |
| 852 | 854 |
| 853 testIndexedOperator() { | 855 testIndexedOperator() { |
| 854 final script = r""" | 856 final script = r""" |
| 855 class C { | 857 class C { |
| 856 operator[](ix) => ix; | 858 operator[](ix) => ix; |
| 857 operator[]=(ix, v) {} | 859 operator[]=(ix, v) {} |
| 858 } | 860 } |
| 859 main() { var c = new C(); c[0]++; }"""; | 861 main() { var c = new C(); c[0]++; }"""; |
| 860 final compiler = compileScript(script); | 862 compileScript(script).then((compiler) { |
| 861 | 863 checkMemberResolved(compiler, 'C', operatorName('[]', false)); |
| 862 checkMemberResolved(compiler, 'C', operatorName('[]', false)); | 864 checkMemberResolved(compiler, 'C', operatorName('[]=', false)); |
| 863 checkMemberResolved(compiler, 'C', operatorName('[]=', false)); | 865 }); |
| 864 } | 866 } |
| 865 | 867 |
| 866 testIncrementsAndDecrements() { | 868 testIncrementsAndDecrements() { |
| 867 final script = r""" | 869 final script = r""" |
| 868 class A { operator+(o)=>null; } | 870 class A { operator+(o)=>null; } |
| 869 class B { operator+(o)=>null; } | 871 class B { operator+(o)=>null; } |
| 870 class C { operator-(o)=>null; } | 872 class C { operator-(o)=>null; } |
| 871 class D { operator-(o)=>null; } | 873 class D { operator-(o)=>null; } |
| 872 main() { | 874 main() { |
| 873 var a = new A(); | 875 var a = new A(); |
| 874 a++; | 876 a++; |
| 875 var b = new B(); | 877 var b = new B(); |
| 876 ++b; | 878 ++b; |
| 877 var c = new C(); | 879 var c = new C(); |
| 878 c--; | 880 c--; |
| 879 var d = new D(); | 881 var d = new D(); |
| 880 --d; | 882 --d; |
| 881 }"""; | 883 }"""; |
| 882 final compiler = compileScript(script); | 884 compileScript(script).then((compiler) { |
| 883 | 885 checkMemberResolved(compiler, 'A', operatorName('+', false)); |
| 884 checkMemberResolved(compiler, 'A', operatorName('+', false)); | 886 checkMemberResolved(compiler, 'B', operatorName('+', false)); |
| 885 checkMemberResolved(compiler, 'B', operatorName('+', false)); | 887 checkMemberResolved(compiler, 'C', operatorName('-', false)); |
| 886 checkMemberResolved(compiler, 'C', operatorName('-', false)); | 888 checkMemberResolved(compiler, 'D', operatorName('-', false)); |
| 887 checkMemberResolved(compiler, 'D', operatorName('-', false)); | 889 }); |
| 888 } | 890 } |
| 889 | 891 |
| 890 testOverrideHashCodeCheck() { | 892 testOverrideHashCodeCheck() { |
| 891 final script = r""" | 893 final script = r""" |
| 892 class A { | 894 class A { |
| 893 operator==(other) => true; | 895 operator==(other) => true; |
| 894 } | 896 } |
| 895 class B { | 897 class B { |
| 896 operator==(other) => true; | 898 operator==(other) => true; |
| 897 get hashCode => 0; | 899 get hashCode => 0; |
| 898 } | 900 } |
| 899 main() { | 901 main() { |
| 900 new A() == new B(); | 902 new A() == new B(); |
| 901 }"""; | 903 }"""; |
| 902 final compiler = compileScript(script); | 904 compileScript(script).then((compiler) { |
| 903 Expect.equals(1, compiler.warnings.length); | 905 Expect.equals(1, compiler.warnings.length); |
| 904 Expect.equals(MessageKind.OVERRIDE_EQUALS_NOT_HASH_CODE, | 906 Expect.equals(MessageKind.OVERRIDE_EQUALS_NOT_HASH_CODE, |
| 905 compiler.warnings[0].message.kind); | 907 compiler.warnings[0].message.kind); |
| 906 Expect.equals(0, compiler.errors.length); | 908 Expect.equals(0, compiler.errors.length); |
| 909 }); |
| 907 } | 910 } |
| OLD | NEW |