| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 testInitializers(); | 72 testInitializers(); |
| 73 testThis(); | 73 testThis(); |
| 74 testSuperCalls(); | 74 testSuperCalls(); |
| 75 testTypeVariables(); | 75 testTypeVariables(); |
| 76 testToString(); | 76 testToString(); |
| 77 testIndexedOperator(); | 77 testIndexedOperator(); |
| 78 testIncrementsAndDecrements(); | 78 testIncrementsAndDecrements(); |
| 79 testOverrideHashCodeCheck(); | 79 testOverrideHashCodeCheck(); |
| 80 testSupertypeOrder(); | 80 testSupertypeOrder(); |
| 81 testConstructorArgumentMismatch(); | 81 testConstructorArgumentMismatch(); |
| 82 testConstConstructorAndNonFinalFields(); |
| 82 } | 83 } |
| 83 | 84 |
| 84 testSupertypeOrder() { | 85 testSupertypeOrder() { |
| 85 MockCompiler compiler = new MockCompiler(); | 86 MockCompiler compiler = new MockCompiler(); |
| 86 compiler.parseScript(""" | 87 compiler.parseScript(""" |
| 87 class I1 {} | 88 class I1 {} |
| 88 class I2 {} | 89 class I2 {} |
| 89 class J1 extends K1 {} | 90 class J1 extends K1 {} |
| 90 class J2 implements K2 {} | 91 class J2 implements K2 {} |
| 91 class K1 {} | 92 class K1 {} |
| (...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 List<String> asSortedStrings(Link link) { | 840 List<String> asSortedStrings(Link link) { |
| 840 List<String> result = <String>[]; | 841 List<String> result = <String>[]; |
| 841 for (; !link.isEmpty; link = link.tail) result.add(link.head.toString()); | 842 for (; !link.isEmpty; link = link.tail) result.add(link.head.toString()); |
| 842 result.sort((s1, s2) => s1.compareTo(s2)); | 843 result.sort((s1, s2) => s1.compareTo(s2)); |
| 843 return result; | 844 return result; |
| 844 } | 845 } |
| 845 | 846 |
| 846 Future compileScript(String source) { | 847 Future compileScript(String source) { |
| 847 Uri uri = new Uri(scheme: 'source'); | 848 Uri uri = new Uri(scheme: 'source'); |
| 848 MockCompiler compiler = compilerFor(source, uri); | 849 MockCompiler compiler = compilerFor(source, uri); |
| 850 compiler.diagnosticHandler = createHandler(compiler, source); |
| 849 return compiler.runCompiler(uri).then((_) { | 851 return compiler.runCompiler(uri).then((_) { |
| 850 return compiler; | 852 return compiler; |
| 851 }); | 853 }); |
| 852 } | 854 } |
| 853 | 855 |
| 854 checkMemberResolved(compiler, className, memberName) { | 856 checkMemberResolved(compiler, className, memberName) { |
| 855 ClassElement cls = findElement(compiler, className); | 857 ClassElement cls = findElement(compiler, className); |
| 856 Element memberElement = cls.lookupLocalMember(memberName); | 858 Element memberElement = cls.lookupLocalMember(memberName); |
| 857 Expect.isNotNull(memberElement); | 859 Expect.isNotNull(memberElement); |
| 858 Expect.isNotNull( | 860 Expect.isNotNull( |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 main() { | 921 main() { |
| 920 new A() == new B(); | 922 new A() == new B(); |
| 921 }"""; | 923 }"""; |
| 922 asyncTest(() => compileScript(script).then((compiler) { | 924 asyncTest(() => compileScript(script).then((compiler) { |
| 923 Expect.equals(1, compiler.warnings.length); | 925 Expect.equals(1, compiler.warnings.length); |
| 924 Expect.equals(MessageKind.OVERRIDE_EQUALS_NOT_HASH_CODE, | 926 Expect.equals(MessageKind.OVERRIDE_EQUALS_NOT_HASH_CODE, |
| 925 compiler.warnings[0].message.kind); | 927 compiler.warnings[0].message.kind); |
| 926 Expect.equals(0, compiler.errors.length); | 928 Expect.equals(0, compiler.errors.length); |
| 927 })); | 929 })); |
| 928 } | 930 } |
| 931 |
| 932 testConstConstructorAndNonFinalFields() { |
| 933 void expect(compiler, List errors, List warnings) { |
| 934 Expect.equals(errors.length, compiler.errors.length); |
| 935 for (int i = 0 ; i < errors.length ; i++) { |
| 936 Expect.equals(errors[i], compiler.errors[i].message.kind); |
| 937 } |
| 938 Expect.equals(warnings.length, compiler.warnings.length); |
| 939 for (int i = 0 ; i < warnings.length ; i++) { |
| 940 Expect.equals(warnings[i], compiler.warnings[i].message.kind); |
| 941 } |
| 942 } |
| 943 |
| 944 final script1 = r""" |
| 945 class A { |
| 946 var a; |
| 947 const A(this.a); |
| 948 } |
| 949 main() { |
| 950 new A(0); |
| 951 }"""; |
| 952 asyncTest(() => compileScript(script1).then((compiler) { |
| 953 expect(compiler, |
| 954 [MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS], |
| 955 [MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_FIELD]); |
| 956 })); |
| 957 |
| 958 final script2 = r""" |
| 959 class A { |
| 960 var a; |
| 961 var b; |
| 962 const A(this.a, this.b); |
| 963 const A.named(this.a, this.b); |
| 964 } |
| 965 main() { |
| 966 new A(0, 1); |
| 967 }"""; |
| 968 asyncTest(() => compileScript(script2).then((compiler) { |
| 969 expect(compiler, |
| 970 [MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS], |
| 971 [MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_CONSTRUCTOR, |
| 972 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_CONSTRUCTOR, |
| 973 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_FIELD, |
| 974 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_FIELD]); |
| 975 })); |
| 976 } |
| OLD | NEW |