Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: pkg/analyzer/test/src/dart/constant/evaluation_test.dart

Issue 2625203002: Run the rest of the analysis tests with the new analysis driver. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analyzer/test/generated/strong_mode_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 library analyzer.test.constant_test; 5 library analyzer.test.constant_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analyzer/context/declared_variables.dart'; 9 import 'package:analyzer/context/declared_variables.dart';
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 $text'''); 88 $text''');
89 } 89 }
90 } 90 }
91 fail(out.toString()); 91 fail(out.toString());
92 } 92 }
93 } 93 }
94 94
95 @reflectiveTest 95 @reflectiveTest
96 class ConstantValueComputerTest extends ResolverTestCase { 96 class ConstantValueComputerTest extends ResolverTestCase {
97 test_annotation_constConstructor() async { 97 test_annotation_constConstructor() async {
98 CompilationUnit compilationUnit = resolveSource(r''' 98 CompilationUnit compilationUnit = await resolveSource(r'''
99 class A { 99 class A {
100 final int i; 100 final int i;
101 const A(this.i); 101 const A(this.i);
102 } 102 }
103 103
104 class C { 104 class C {
105 @A(5) 105 @A(5)
106 f() {} 106 f() {}
107 } 107 }
108 '''); 108 ''');
109 EvaluationResultImpl result = 109 EvaluationResultImpl result =
110 _evaluateAnnotation(compilationUnit, "C", "f"); 110 _evaluateAnnotation(compilationUnit, "C", "f");
111 Map<String, DartObjectImpl> annotationFields = _assertType(result, 'A'); 111 Map<String, DartObjectImpl> annotationFields = _assertType(result, 'A');
112 _assertIntField(annotationFields, 'i', 5); 112 _assertIntField(annotationFields, 'i', 5);
113 } 113 }
114 114
115 test_annotation_constConstructor_named() async { 115 test_annotation_constConstructor_named() async {
116 CompilationUnit compilationUnit = resolveSource(r''' 116 CompilationUnit compilationUnit = await resolveSource(r'''
117 class A { 117 class A {
118 final int i; 118 final int i;
119 const A.named(this.i); 119 const A.named(this.i);
120 } 120 }
121 121
122 class C { 122 class C {
123 @A.named(5) 123 @A.named(5)
124 f() {} 124 f() {}
125 } 125 }
126 '''); 126 ''');
127 EvaluationResultImpl result = 127 EvaluationResultImpl result =
128 _evaluateAnnotation(compilationUnit, "C", "f"); 128 _evaluateAnnotation(compilationUnit, "C", "f");
129 Map<String, DartObjectImpl> annotationFields = _assertType(result, 'A'); 129 Map<String, DartObjectImpl> annotationFields = _assertType(result, 'A');
130 _assertIntField(annotationFields, 'i', 5); 130 _assertIntField(annotationFields, 'i', 5);
131 } 131 }
132 132
133 test_annotation_constConstructor_noArgs() async { 133 test_annotation_constConstructor_noArgs() async {
134 // Failing to pass arguments to an annotation which is a constant 134 // Failing to pass arguments to an annotation which is a constant
135 // constructor is illegal, but shouldn't crash analysis. 135 // constructor is illegal, but shouldn't crash analysis.
136 CompilationUnit compilationUnit = resolveSource(r''' 136 CompilationUnit compilationUnit = await resolveSource(r'''
137 class A { 137 class A {
138 final int i; 138 final int i;
139 const A(this.i); 139 const A(this.i);
140 } 140 }
141 141
142 class C { 142 class C {
143 @A 143 @A
144 f() {} 144 f() {}
145 } 145 }
146 '''); 146 ''');
147 _evaluateAnnotation(compilationUnit, "C", "f"); 147 _evaluateAnnotation(compilationUnit, "C", "f");
148 } 148 }
149 149
150 test_annotation_constConstructor_noArgs_named() async { 150 test_annotation_constConstructor_noArgs_named() async {
151 // Failing to pass arguments to an annotation which is a constant 151 // Failing to pass arguments to an annotation which is a constant
152 // constructor is illegal, but shouldn't crash analysis. 152 // constructor is illegal, but shouldn't crash analysis.
153 CompilationUnit compilationUnit = resolveSource(r''' 153 CompilationUnit compilationUnit = await resolveSource(r'''
154 class A { 154 class A {
155 final int i; 155 final int i;
156 const A.named(this.i); 156 const A.named(this.i);
157 } 157 }
158 158
159 class C { 159 class C {
160 @A.named 160 @A.named
161 f() {} 161 f() {}
162 } 162 }
163 '''); 163 ''');
164 _evaluateAnnotation(compilationUnit, "C", "f"); 164 _evaluateAnnotation(compilationUnit, "C", "f");
165 } 165 }
166 166
167 test_annotation_nonConstConstructor() async { 167 test_annotation_nonConstConstructor() async {
168 // Calling a non-const constructor from an annotation that is illegal, but 168 // Calling a non-const constructor from an annotation that is illegal, but
169 // shouldn't crash analysis. 169 // shouldn't crash analysis.
170 CompilationUnit compilationUnit = resolveSource(r''' 170 CompilationUnit compilationUnit = await resolveSource(r'''
171 class A { 171 class A {
172 final int i; 172 final int i;
173 A(this.i); 173 A(this.i);
174 } 174 }
175 175
176 class C { 176 class C {
177 @A(5) 177 @A(5)
178 f() {} 178 f() {}
179 } 179 }
180 '''); 180 ''');
181 _evaluateAnnotation(compilationUnit, "C", "f"); 181 _evaluateAnnotation(compilationUnit, "C", "f");
182 } 182 }
183 183
184 test_annotation_staticConst() async { 184 test_annotation_staticConst() async {
185 CompilationUnit compilationUnit = resolveSource(r''' 185 CompilationUnit compilationUnit = await resolveSource(r'''
186 class C { 186 class C {
187 static const int i = 5; 187 static const int i = 5;
188 188
189 @i 189 @i
190 f() {} 190 f() {}
191 } 191 }
192 '''); 192 ''');
193 EvaluationResultImpl result = 193 EvaluationResultImpl result =
194 _evaluateAnnotation(compilationUnit, "C", "f"); 194 _evaluateAnnotation(compilationUnit, "C", "f");
195 expect(_assertValidInt(result), 5); 195 expect(_assertValidInt(result), 5);
196 } 196 }
197 197
198 test_annotation_staticConst_args() async { 198 test_annotation_staticConst_args() async {
199 // Applying arguments to an annotation that is a static const is 199 // Applying arguments to an annotation that is a static const is
200 // illegal, but shouldn't crash analysis. 200 // illegal, but shouldn't crash analysis.
201 CompilationUnit compilationUnit = resolveSource(r''' 201 CompilationUnit compilationUnit = await resolveSource(r'''
202 class C { 202 class C {
203 static const int i = 5; 203 static const int i = 5;
204 204
205 @i(1) 205 @i(1)
206 f() {} 206 f() {}
207 } 207 }
208 '''); 208 ''');
209 _evaluateAnnotation(compilationUnit, "C", "f"); 209 _evaluateAnnotation(compilationUnit, "C", "f");
210 } 210 }
211 211
212 test_annotation_staticConst_otherClass() async { 212 test_annotation_staticConst_otherClass() async {
213 CompilationUnit compilationUnit = resolveSource(r''' 213 CompilationUnit compilationUnit = await resolveSource(r'''
214 class A { 214 class A {
215 static const int i = 5; 215 static const int i = 5;
216 } 216 }
217 217
218 class C { 218 class C {
219 @A.i 219 @A.i
220 f() {} 220 f() {}
221 } 221 }
222 '''); 222 ''');
223 EvaluationResultImpl result = 223 EvaluationResultImpl result =
224 _evaluateAnnotation(compilationUnit, "C", "f"); 224 _evaluateAnnotation(compilationUnit, "C", "f");
225 expect(_assertValidInt(result), 5); 225 expect(_assertValidInt(result), 5);
226 } 226 }
227 227
228 test_annotation_staticConst_otherClass_args() async { 228 test_annotation_staticConst_otherClass_args() async {
229 // Applying arguments to an annotation that is a static const is 229 // Applying arguments to an annotation that is a static const is
230 // illegal, but shouldn't crash analysis. 230 // illegal, but shouldn't crash analysis.
231 CompilationUnit compilationUnit = resolveSource(r''' 231 CompilationUnit compilationUnit = await resolveSource(r'''
232 class A { 232 class A {
233 static const int i = 5; 233 static const int i = 5;
234 } 234 }
235 235
236 class C { 236 class C {
237 @A.i(1) 237 @A.i(1)
238 f() {} 238 f() {}
239 } 239 }
240 '''); 240 ''');
241 _evaluateAnnotation(compilationUnit, "C", "f"); 241 _evaluateAnnotation(compilationUnit, "C", "f");
242 } 242 }
243 243
244 test_annotation_topLevelVariable() async { 244 test_annotation_topLevelVariable() async {
245 CompilationUnit compilationUnit = resolveSource(r''' 245 CompilationUnit compilationUnit = await resolveSource(r'''
246 const int i = 5; 246 const int i = 5;
247 class C { 247 class C {
248 @i 248 @i
249 f() {} 249 f() {}
250 } 250 }
251 '''); 251 ''');
252 EvaluationResultImpl result = 252 EvaluationResultImpl result =
253 _evaluateAnnotation(compilationUnit, "C", "f"); 253 _evaluateAnnotation(compilationUnit, "C", "f");
254 expect(_assertValidInt(result), 5); 254 expect(_assertValidInt(result), 5);
255 } 255 }
256 256
257 test_annotation_topLevelVariable_args() async { 257 test_annotation_topLevelVariable_args() async {
258 // Applying arguments to an annotation that is a top-level variable is 258 // Applying arguments to an annotation that is a top-level variable is
259 // illegal, but shouldn't crash analysis. 259 // illegal, but shouldn't crash analysis.
260 CompilationUnit compilationUnit = resolveSource(r''' 260 CompilationUnit compilationUnit = await resolveSource(r'''
261 const int i = 5; 261 const int i = 5;
262 class C { 262 class C {
263 @i(1) 263 @i(1)
264 f() {} 264 f() {}
265 } 265 }
266 '''); 266 ''');
267 _evaluateAnnotation(compilationUnit, "C", "f"); 267 _evaluateAnnotation(compilationUnit, "C", "f");
268 } 268 }
269 269
270 test_computeValues_cycle() async { 270 test_computeValues_cycle() async {
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 } 595 }
596 596
597 test_dependencyOnVariable() async { 597 test_dependencyOnVariable() async {
598 // x depends on y 598 // x depends on y
599 await _assertProperDependencies(r''' 599 await _assertProperDependencies(r'''
600 const x = y + 1; 600 const x = y + 1;
601 const y = 2;'''); 601 const y = 2;''');
602 } 602 }
603 603
604 test_final_initialized_at_declaration() async { 604 test_final_initialized_at_declaration() async {
605 CompilationUnit compilationUnit = resolveSource(''' 605 CompilationUnit compilationUnit = await resolveSource('''
606 class A { 606 class A {
607 final int i = 123; 607 final int i = 123;
608 const A(); 608 const A();
609 } 609 }
610 610
611 const A a = const A(); 611 const A a = const A();
612 '''); 612 ''');
613 EvaluationResultImpl result = 613 EvaluationResultImpl result =
614 _evaluateTopLevelVariable(compilationUnit, 'a'); 614 _evaluateTopLevelVariable(compilationUnit, 'a');
615 Map<String, DartObjectImpl> fields = _assertType(result, "A"); 615 Map<String, DartObjectImpl> fields = _assertType(result, "A");
616 expect(fields, hasLength(1)); 616 expect(fields, hasLength(1));
617 _assertIntField(fields, "i", 123); 617 _assertIntField(fields, "i", 123);
618 } 618 }
619 619
620 test_fromEnvironment_bool_default_false() async { 620 test_fromEnvironment_bool_default_false() async {
621 expect(_assertValidBool(_check_fromEnvironment_bool(null, "false")), false); 621 expect(_assertValidBool(await _check_fromEnvironment_bool(null, "false")),
622 false);
622 } 623 }
623 624
624 test_fromEnvironment_bool_default_overridden() async { 625 test_fromEnvironment_bool_default_overridden() async {
625 expect( 626 expect(_assertValidBool(await _check_fromEnvironment_bool("false", "true")),
626 _assertValidBool(_check_fromEnvironment_bool("false", "true")), false); 627 false);
627 } 628 }
628 629
629 test_fromEnvironment_bool_default_parseError() async { 630 test_fromEnvironment_bool_default_parseError() async {
630 expect(_assertValidBool(_check_fromEnvironment_bool("parseError", "true")), 631 expect(
632 _assertValidBool(
633 await _check_fromEnvironment_bool("parseError", "true")),
631 true); 634 true);
632 } 635 }
633 636
634 test_fromEnvironment_bool_default_true() async { 637 test_fromEnvironment_bool_default_true() async {
635 expect(_assertValidBool(_check_fromEnvironment_bool(null, "true")), true); 638 expect(_assertValidBool(await _check_fromEnvironment_bool(null, "true")),
639 true);
636 } 640 }
637 641
638 test_fromEnvironment_bool_false() async { 642 test_fromEnvironment_bool_false() async {
639 expect(_assertValidBool(_check_fromEnvironment_bool("false", null)), false); 643 expect(_assertValidBool(await _check_fromEnvironment_bool("false", null)),
644 false);
640 } 645 }
641 646
642 test_fromEnvironment_bool_parseError() async { 647 test_fromEnvironment_bool_parseError() async {
643 expect(_assertValidBool(_check_fromEnvironment_bool("parseError", null)), 648 expect(
649 _assertValidBool(await _check_fromEnvironment_bool("parseError", null)),
644 false); 650 false);
645 } 651 }
646 652
647 test_fromEnvironment_bool_true() async { 653 test_fromEnvironment_bool_true() async {
648 expect(_assertValidBool(_check_fromEnvironment_bool("true", null)), true); 654 expect(_assertValidBool(await _check_fromEnvironment_bool("true", null)),
655 true);
649 } 656 }
650 657
651 test_fromEnvironment_bool_undeclared() async { 658 test_fromEnvironment_bool_undeclared() async {
652 _assertValidUnknown(_check_fromEnvironment_bool(null, null)); 659 _assertValidUnknown(await _check_fromEnvironment_bool(null, null));
653 } 660 }
654 661
655 test_fromEnvironment_int_default_overridden() async { 662 test_fromEnvironment_int_default_overridden() async {
656 expect(_assertValidInt(_check_fromEnvironment_int("234", "123")), 234); 663 expect(
664 _assertValidInt(await _check_fromEnvironment_int("234", "123")), 234);
657 } 665 }
658 666
659 test_fromEnvironment_int_default_parseError() async { 667 test_fromEnvironment_int_default_parseError() async {
660 expect( 668 expect(
661 _assertValidInt(_check_fromEnvironment_int("parseError", "123")), 123); 669 _assertValidInt(await _check_fromEnvironment_int("parseError", "123")),
670 123);
662 } 671 }
663 672
664 test_fromEnvironment_int_default_undeclared() async { 673 test_fromEnvironment_int_default_undeclared() async {
665 expect(_assertValidInt(_check_fromEnvironment_int(null, "123")), 123); 674 expect(_assertValidInt(await _check_fromEnvironment_int(null, "123")), 123);
666 } 675 }
667 676
668 test_fromEnvironment_int_ok() async { 677 test_fromEnvironment_int_ok() async {
669 expect(_assertValidInt(_check_fromEnvironment_int("234", null)), 234); 678 expect(_assertValidInt(await _check_fromEnvironment_int("234", null)), 234);
670 } 679 }
671 680
672 test_fromEnvironment_int_parseError() async { 681 test_fromEnvironment_int_parseError() async {
673 _assertValidNull(_check_fromEnvironment_int("parseError", null)); 682 _assertValidNull(await _check_fromEnvironment_int("parseError", null));
674 } 683 }
675 684
676 test_fromEnvironment_int_parseError_nullDefault() async { 685 test_fromEnvironment_int_parseError_nullDefault() async {
677 _assertValidNull(_check_fromEnvironment_int("parseError", "null")); 686 _assertValidNull(await _check_fromEnvironment_int("parseError", "null"));
678 } 687 }
679 688
680 test_fromEnvironment_int_undeclared() async { 689 test_fromEnvironment_int_undeclared() async {
681 _assertValidUnknown(_check_fromEnvironment_int(null, null)); 690 _assertValidUnknown(await _check_fromEnvironment_int(null, null));
682 } 691 }
683 692
684 test_fromEnvironment_int_undeclared_nullDefault() async { 693 test_fromEnvironment_int_undeclared_nullDefault() async {
685 _assertValidNull(_check_fromEnvironment_int(null, "null")); 694 _assertValidNull(await _check_fromEnvironment_int(null, "null"));
686 } 695 }
687 696
688 test_fromEnvironment_string_default_overridden() async { 697 test_fromEnvironment_string_default_overridden() async {
689 expect(_assertValidString(_check_fromEnvironment_string("abc", "'def'")), 698 expect(
699 _assertValidString(await _check_fromEnvironment_string("abc", "'def'")),
690 "abc"); 700 "abc");
691 } 701 }
692 702
693 test_fromEnvironment_string_default_undeclared() async { 703 test_fromEnvironment_string_default_undeclared() async {
694 expect(_assertValidString(_check_fromEnvironment_string(null, "'def'")), 704 expect(
705 _assertValidString(await _check_fromEnvironment_string(null, "'def'")),
695 "def"); 706 "def");
696 } 707 }
697 708
698 test_fromEnvironment_string_empty() async { 709 test_fromEnvironment_string_empty() async {
699 expect(_assertValidString(_check_fromEnvironment_string("", null)), ""); 710 expect(
711 _assertValidString(await _check_fromEnvironment_string("", null)), "");
700 } 712 }
701 713
702 test_fromEnvironment_string_ok() async { 714 test_fromEnvironment_string_ok() async {
703 expect( 715 expect(_assertValidString(await _check_fromEnvironment_string("abc", null)),
704 _assertValidString(_check_fromEnvironment_string("abc", null)), "abc"); 716 "abc");
705 } 717 }
706 718
707 test_fromEnvironment_string_undeclared() async { 719 test_fromEnvironment_string_undeclared() async {
708 _assertValidUnknown(_check_fromEnvironment_string(null, null)); 720 _assertValidUnknown(await _check_fromEnvironment_string(null, null));
709 } 721 }
710 722
711 test_fromEnvironment_string_undeclared_nullDefault() async { 723 test_fromEnvironment_string_undeclared_nullDefault() async {
712 _assertValidNull(_check_fromEnvironment_string(null, "null")); 724 _assertValidNull(await _check_fromEnvironment_string(null, "null"));
713 } 725 }
714 726
715 test_instanceCreationExpression_computedField() async { 727 test_instanceCreationExpression_computedField() async {
716 CompilationUnit compilationUnit = resolveSource(r''' 728 CompilationUnit compilationUnit = await resolveSource(r'''
717 const foo = const A(4, 5); 729 const foo = const A(4, 5);
718 class A { 730 class A {
719 const A(int i, int j) : k = 2 * i + j; 731 const A(int i, int j) : k = 2 * i + j;
720 final int k; 732 final int k;
721 }'''); 733 }''');
722 EvaluationResultImpl result = 734 EvaluationResultImpl result =
723 _evaluateTopLevelVariable(compilationUnit, "foo"); 735 _evaluateTopLevelVariable(compilationUnit, "foo");
724 Map<String, DartObjectImpl> fields = _assertType(result, "A"); 736 Map<String, DartObjectImpl> fields = _assertType(result, "A");
725 expect(fields, hasLength(1)); 737 expect(fields, hasLength(1));
726 _assertIntField(fields, "k", 13); 738 _assertIntField(fields, "k", 13);
727 } 739 }
728 740
729 test_instanceCreationExpression_computedField_namedOptionalWithDefault() async { 741 test_instanceCreationExpression_computedField_namedOptionalWithDefault() async {
730 _checkInstanceCreationOptionalParams(false, true, true); 742 await _checkInstanceCreationOptionalParams(false, true, true);
731 } 743 }
732 744
733 test_instanceCreationExpression_computedField_namedOptionalWithoutDefault() as ync { 745 test_instanceCreationExpression_computedField_namedOptionalWithoutDefault() as ync {
734 _checkInstanceCreationOptionalParams(false, true, false); 746 await _checkInstanceCreationOptionalParams(false, true, false);
735 } 747 }
736 748
737 test_instanceCreationExpression_computedField_unnamedOptionalWithDefault() asy nc { 749 test_instanceCreationExpression_computedField_unnamedOptionalWithDefault() asy nc {
738 _checkInstanceCreationOptionalParams(false, false, true); 750 await _checkInstanceCreationOptionalParams(false, false, true);
739 } 751 }
740 752
741 test_instanceCreationExpression_computedField_unnamedOptionalWithoutDefault() async { 753 test_instanceCreationExpression_computedField_unnamedOptionalWithoutDefault() async {
742 _checkInstanceCreationOptionalParams(false, false, false); 754 await _checkInstanceCreationOptionalParams(false, false, false);
743 } 755 }
744 756
745 test_instanceCreationExpression_computedField_usesConstConstructor() async { 757 test_instanceCreationExpression_computedField_usesConstConstructor() async {
746 CompilationUnit compilationUnit = resolveSource(r''' 758 CompilationUnit compilationUnit = await resolveSource(r'''
747 const foo = const A(3); 759 const foo = const A(3);
748 class A { 760 class A {
749 const A(int i) : b = const B(4); 761 const A(int i) : b = const B(4);
750 final int b; 762 final int b;
751 } 763 }
752 class B { 764 class B {
753 const B(this.k); 765 const B(this.k);
754 final int k; 766 final int k;
755 }'''); 767 }''');
756 EvaluationResultImpl result = 768 EvaluationResultImpl result =
757 _evaluateTopLevelVariable(compilationUnit, "foo"); 769 _evaluateTopLevelVariable(compilationUnit, "foo");
758 Map<String, DartObjectImpl> fieldsOfA = _assertType(result, "A"); 770 Map<String, DartObjectImpl> fieldsOfA = _assertType(result, "A");
759 expect(fieldsOfA, hasLength(1)); 771 expect(fieldsOfA, hasLength(1));
760 Map<String, DartObjectImpl> fieldsOfB = 772 Map<String, DartObjectImpl> fieldsOfB =
761 _assertFieldType(fieldsOfA, "b", "B"); 773 _assertFieldType(fieldsOfA, "b", "B");
762 expect(fieldsOfB, hasLength(1)); 774 expect(fieldsOfB, hasLength(1));
763 _assertIntField(fieldsOfB, "k", 4); 775 _assertIntField(fieldsOfB, "k", 4);
764 } 776 }
765 777
766 test_instanceCreationExpression_computedField_usesStaticConst() async { 778 test_instanceCreationExpression_computedField_usesStaticConst() async {
767 CompilationUnit compilationUnit = resolveSource(r''' 779 CompilationUnit compilationUnit = await resolveSource(r'''
768 const foo = const A(3); 780 const foo = const A(3);
769 class A { 781 class A {
770 const A(int i) : k = i + B.bar; 782 const A(int i) : k = i + B.bar;
771 final int k; 783 final int k;
772 } 784 }
773 class B { 785 class B {
774 static const bar = 4; 786 static const bar = 4;
775 }'''); 787 }''');
776 EvaluationResultImpl result = 788 EvaluationResultImpl result =
777 _evaluateTopLevelVariable(compilationUnit, "foo"); 789 _evaluateTopLevelVariable(compilationUnit, "foo");
778 Map<String, DartObjectImpl> fields = _assertType(result, "A"); 790 Map<String, DartObjectImpl> fields = _assertType(result, "A");
779 expect(fields, hasLength(1)); 791 expect(fields, hasLength(1));
780 _assertIntField(fields, "k", 7); 792 _assertIntField(fields, "k", 7);
781 } 793 }
782 794
783 test_instanceCreationExpression_computedField_usesTopLevelConst() async { 795 test_instanceCreationExpression_computedField_usesTopLevelConst() async {
784 CompilationUnit compilationUnit = resolveSource(r''' 796 CompilationUnit compilationUnit = await resolveSource(r'''
785 const foo = const A(3); 797 const foo = const A(3);
786 const bar = 4; 798 const bar = 4;
787 class A { 799 class A {
788 const A(int i) : k = i + bar; 800 const A(int i) : k = i + bar;
789 final int k; 801 final int k;
790 }'''); 802 }''');
791 EvaluationResultImpl result = 803 EvaluationResultImpl result =
792 _evaluateTopLevelVariable(compilationUnit, "foo"); 804 _evaluateTopLevelVariable(compilationUnit, "foo");
793 Map<String, DartObjectImpl> fields = _assertType(result, "A"); 805 Map<String, DartObjectImpl> fields = _assertType(result, "A");
794 expect(fields, hasLength(1)); 806 expect(fields, hasLength(1));
795 _assertIntField(fields, "k", 7); 807 _assertIntField(fields, "k", 7);
796 } 808 }
797 809
798 test_instanceCreationExpression_explicitSuper() async { 810 test_instanceCreationExpression_explicitSuper() async {
799 CompilationUnit compilationUnit = resolveSource(r''' 811 CompilationUnit compilationUnit = await resolveSource(r'''
800 const foo = const B(4, 5); 812 const foo = const B(4, 5);
801 class A { 813 class A {
802 const A(this.x); 814 const A(this.x);
803 final int x; 815 final int x;
804 } 816 }
805 class B extends A { 817 class B extends A {
806 const B(int x, this.y) : super(x * 2); 818 const B(int x, this.y) : super(x * 2);
807 final int y; 819 final int y;
808 }'''); 820 }''');
809 EvaluationResultImpl result = 821 EvaluationResultImpl result =
810 _evaluateTopLevelVariable(compilationUnit, "foo"); 822 _evaluateTopLevelVariable(compilationUnit, "foo");
811 Map<String, DartObjectImpl> fields = _assertType(result, "B"); 823 Map<String, DartObjectImpl> fields = _assertType(result, "B");
812 expect(fields, hasLength(2)); 824 expect(fields, hasLength(2));
813 _assertIntField(fields, "y", 5); 825 _assertIntField(fields, "y", 5);
814 Map<String, DartObjectImpl> superclassFields = 826 Map<String, DartObjectImpl> superclassFields =
815 _assertFieldType(fields, GenericState.SUPERCLASS_FIELD, "A"); 827 _assertFieldType(fields, GenericState.SUPERCLASS_FIELD, "A");
816 expect(superclassFields, hasLength(1)); 828 expect(superclassFields, hasLength(1));
817 _assertIntField(superclassFields, "x", 8); 829 _assertIntField(superclassFields, "x", 8);
818 } 830 }
819 831
820 test_instanceCreationExpression_fieldFormalParameter() async { 832 test_instanceCreationExpression_fieldFormalParameter() async {
821 CompilationUnit compilationUnit = resolveSource(r''' 833 CompilationUnit compilationUnit = await resolveSource(r'''
822 const foo = const A(42); 834 const foo = const A(42);
823 class A { 835 class A {
824 int x; 836 int x;
825 const A(this.x) 837 const A(this.x)
826 }'''); 838 }''');
827 EvaluationResultImpl result = 839 EvaluationResultImpl result =
828 _evaluateTopLevelVariable(compilationUnit, "foo"); 840 _evaluateTopLevelVariable(compilationUnit, "foo");
829 Map<String, DartObjectImpl> fields = _assertType(result, "A"); 841 Map<String, DartObjectImpl> fields = _assertType(result, "A");
830 expect(fields, hasLength(1)); 842 expect(fields, hasLength(1));
831 _assertIntField(fields, "x", 42); 843 _assertIntField(fields, "x", 42);
832 } 844 }
833 845
834 test_instanceCreationExpression_fieldFormalParameter_namedOptionalWithDefault( ) async { 846 test_instanceCreationExpression_fieldFormalParameter_namedOptionalWithDefault( ) async {
835 _checkInstanceCreationOptionalParams(true, true, true); 847 await _checkInstanceCreationOptionalParams(true, true, true);
836 } 848 }
837 849
838 test_instanceCreationExpression_fieldFormalParameter_namedOptionalWithoutDefau lt() async { 850 test_instanceCreationExpression_fieldFormalParameter_namedOptionalWithoutDefau lt() async {
839 _checkInstanceCreationOptionalParams(true, true, false); 851 await _checkInstanceCreationOptionalParams(true, true, false);
840 } 852 }
841 853
842 test_instanceCreationExpression_fieldFormalParameter_unnamedOptionalWithDefaul t() async { 854 test_instanceCreationExpression_fieldFormalParameter_unnamedOptionalWithDefaul t() async {
843 _checkInstanceCreationOptionalParams(true, false, true); 855 await _checkInstanceCreationOptionalParams(true, false, true);
844 } 856 }
845 857
846 test_instanceCreationExpression_fieldFormalParameter_unnamedOptionalWithoutDef ault() async { 858 test_instanceCreationExpression_fieldFormalParameter_unnamedOptionalWithoutDef ault() async {
847 _checkInstanceCreationOptionalParams(true, false, false); 859 await _checkInstanceCreationOptionalParams(true, false, false);
848 } 860 }
849 861
850 test_instanceCreationExpression_implicitSuper() async { 862 test_instanceCreationExpression_implicitSuper() async {
851 CompilationUnit compilationUnit = resolveSource(r''' 863 CompilationUnit compilationUnit = await resolveSource(r'''
852 const foo = const B(4); 864 const foo = const B(4);
853 class A { 865 class A {
854 const A() : x = 3; 866 const A() : x = 3;
855 final int x; 867 final int x;
856 } 868 }
857 class B extends A { 869 class B extends A {
858 const B(this.y); 870 const B(this.y);
859 final int y; 871 final int y;
860 }'''); 872 }''');
861 EvaluationResultImpl result = 873 EvaluationResultImpl result =
862 _evaluateTopLevelVariable(compilationUnit, "foo"); 874 _evaluateTopLevelVariable(compilationUnit, "foo");
863 Map<String, DartObjectImpl> fields = _assertType(result, "B"); 875 Map<String, DartObjectImpl> fields = _assertType(result, "B");
864 expect(fields, hasLength(2)); 876 expect(fields, hasLength(2));
865 _assertIntField(fields, "y", 4); 877 _assertIntField(fields, "y", 4);
866 Map<String, DartObjectImpl> superclassFields = 878 Map<String, DartObjectImpl> superclassFields =
867 _assertFieldType(fields, GenericState.SUPERCLASS_FIELD, "A"); 879 _assertFieldType(fields, GenericState.SUPERCLASS_FIELD, "A");
868 expect(superclassFields, hasLength(1)); 880 expect(superclassFields, hasLength(1));
869 _assertIntField(superclassFields, "x", 3); 881 _assertIntField(superclassFields, "x", 3);
870 } 882 }
871 883
872 test_instanceCreationExpression_nonFactoryRedirect() async { 884 test_instanceCreationExpression_nonFactoryRedirect() async {
873 CompilationUnit compilationUnit = resolveSource(r''' 885 CompilationUnit compilationUnit = await resolveSource(r'''
874 const foo = const A.a1(); 886 const foo = const A.a1();
875 class A { 887 class A {
876 const A.a1() : this.a2(); 888 const A.a1() : this.a2();
877 const A.a2() : x = 5; 889 const A.a2() : x = 5;
878 final int x; 890 final int x;
879 }'''); 891 }''');
880 Map<String, DartObjectImpl> aFields = 892 Map<String, DartObjectImpl> aFields =
881 _assertType(_evaluateTopLevelVariable(compilationUnit, "foo"), "A"); 893 _assertType(_evaluateTopLevelVariable(compilationUnit, "foo"), "A");
882 _assertIntField(aFields, 'x', 5); 894 _assertIntField(aFields, 'x', 5);
883 } 895 }
884 896
885 test_instanceCreationExpression_nonFactoryRedirect_arg() async { 897 test_instanceCreationExpression_nonFactoryRedirect_arg() async {
886 CompilationUnit compilationUnit = resolveSource(r''' 898 CompilationUnit compilationUnit = await resolveSource(r'''
887 const foo = const A.a1(1); 899 const foo = const A.a1(1);
888 class A { 900 class A {
889 const A.a1(x) : this.a2(x + 100); 901 const A.a1(x) : this.a2(x + 100);
890 const A.a2(x) : y = x + 10; 902 const A.a2(x) : y = x + 10;
891 final int y; 903 final int y;
892 }'''); 904 }''');
893 Map<String, DartObjectImpl> aFields = 905 Map<String, DartObjectImpl> aFields =
894 _assertType(_evaluateTopLevelVariable(compilationUnit, "foo"), "A"); 906 _assertType(_evaluateTopLevelVariable(compilationUnit, "foo"), "A");
895 _assertIntField(aFields, 'y', 111); 907 _assertIntField(aFields, 'y', 111);
896 } 908 }
897 909
898 test_instanceCreationExpression_nonFactoryRedirect_cycle() async { 910 test_instanceCreationExpression_nonFactoryRedirect_cycle() async {
899 // It is an error to have a cycle in non-factory redirects; however, we 911 // It is an error to have a cycle in non-factory redirects; however, we
900 // need to make sure that even if the error occurs, attempting to evaluate 912 // need to make sure that even if the error occurs, attempting to evaluate
901 // the constant will terminate. 913 // the constant will terminate.
902 CompilationUnit compilationUnit = resolveSource(r''' 914 CompilationUnit compilationUnit = await resolveSource(r'''
903 const foo = const A(); 915 const foo = const A();
904 class A { 916 class A {
905 const A() : this.b(); 917 const A() : this.b();
906 const A.b() : this(); 918 const A.b() : this();
907 }'''); 919 }''');
908 _assertValidUnknown(_evaluateTopLevelVariable(compilationUnit, "foo")); 920 _assertValidUnknown(_evaluateTopLevelVariable(compilationUnit, "foo"));
909 } 921 }
910 922
911 test_instanceCreationExpression_nonFactoryRedirect_defaultArg() async { 923 test_instanceCreationExpression_nonFactoryRedirect_defaultArg() async {
912 CompilationUnit compilationUnit = resolveSource(r''' 924 CompilationUnit compilationUnit = await resolveSource(r'''
913 const foo = const A.a1(); 925 const foo = const A.a1();
914 class A { 926 class A {
915 const A.a1() : this.a2(); 927 const A.a1() : this.a2();
916 const A.a2([x = 100]) : y = x + 10; 928 const A.a2([x = 100]) : y = x + 10;
917 final int y; 929 final int y;
918 }'''); 930 }''');
919 Map<String, DartObjectImpl> aFields = 931 Map<String, DartObjectImpl> aFields =
920 _assertType(_evaluateTopLevelVariable(compilationUnit, "foo"), "A"); 932 _assertType(_evaluateTopLevelVariable(compilationUnit, "foo"), "A");
921 _assertIntField(aFields, 'y', 110); 933 _assertIntField(aFields, 'y', 110);
922 } 934 }
923 935
924 test_instanceCreationExpression_nonFactoryRedirect_toMissing() async { 936 test_instanceCreationExpression_nonFactoryRedirect_toMissing() async {
925 CompilationUnit compilationUnit = resolveSource(r''' 937 CompilationUnit compilationUnit = await resolveSource(r'''
926 const foo = const A.a1(); 938 const foo = const A.a1();
927 class A { 939 class A {
928 const A.a1() : this.a2(); 940 const A.a1() : this.a2();
929 }'''); 941 }''');
930 // We don't care what value foo evaluates to (since there is a compile 942 // We don't care what value foo evaluates to (since there is a compile
931 // error), but we shouldn't crash, and we should figure 943 // error), but we shouldn't crash, and we should figure
932 // out that it evaluates to an instance of class A. 944 // out that it evaluates to an instance of class A.
933 _assertType(_evaluateTopLevelVariable(compilationUnit, "foo"), "A"); 945 _assertType(_evaluateTopLevelVariable(compilationUnit, "foo"), "A");
934 } 946 }
935 947
936 test_instanceCreationExpression_nonFactoryRedirect_toNonConst() async { 948 test_instanceCreationExpression_nonFactoryRedirect_toNonConst() async {
937 CompilationUnit compilationUnit = resolveSource(r''' 949 CompilationUnit compilationUnit = await resolveSource(r'''
938 const foo = const A.a1(); 950 const foo = const A.a1();
939 class A { 951 class A {
940 const A.a1() : this.a2(); 952 const A.a1() : this.a2();
941 A.a2(); 953 A.a2();
942 }'''); 954 }''');
943 // We don't care what value foo evaluates to (since there is a compile 955 // We don't care what value foo evaluates to (since there is a compile
944 // error), but we shouldn't crash, and we should figure 956 // error), but we shouldn't crash, and we should figure
945 // out that it evaluates to an instance of class A. 957 // out that it evaluates to an instance of class A.
946 _assertType(_evaluateTopLevelVariable(compilationUnit, "foo"), "A"); 958 _assertType(_evaluateTopLevelVariable(compilationUnit, "foo"), "A");
947 } 959 }
948 960
949 test_instanceCreationExpression_nonFactoryRedirect_unnamed() async { 961 test_instanceCreationExpression_nonFactoryRedirect_unnamed() async {
950 CompilationUnit compilationUnit = resolveSource(r''' 962 CompilationUnit compilationUnit = await resolveSource(r'''
951 const foo = const A.a1(); 963 const foo = const A.a1();
952 class A { 964 class A {
953 const A.a1() : this(); 965 const A.a1() : this();
954 const A() : x = 5; 966 const A() : x = 5;
955 final int x; 967 final int x;
956 }'''); 968 }''');
957 Map<String, DartObjectImpl> aFields = 969 Map<String, DartObjectImpl> aFields =
958 _assertType(_evaluateTopLevelVariable(compilationUnit, "foo"), "A"); 970 _assertType(_evaluateTopLevelVariable(compilationUnit, "foo"), "A");
959 _assertIntField(aFields, 'x', 5); 971 _assertIntField(aFields, 'x', 5);
960 } 972 }
961 973
962 test_instanceCreationExpression_redirect() async { 974 test_instanceCreationExpression_redirect() async {
963 CompilationUnit compilationUnit = resolveSource(r''' 975 CompilationUnit compilationUnit = await resolveSource(r'''
964 const foo = const A(); 976 const foo = const A();
965 class A { 977 class A {
966 const factory A() = B; 978 const factory A() = B;
967 } 979 }
968 class B implements A { 980 class B implements A {
969 const B(); 981 const B();
970 }'''); 982 }''');
971 _assertType(_evaluateTopLevelVariable(compilationUnit, "foo"), "B"); 983 _assertType(_evaluateTopLevelVariable(compilationUnit, "foo"), "B");
972 } 984 }
973 985
974 test_instanceCreationExpression_redirect_cycle() async { 986 test_instanceCreationExpression_redirect_cycle() async {
975 // It is an error to have a cycle in factory redirects; however, we need 987 // It is an error to have a cycle in factory redirects; however, we need
976 // to make sure that even if the error occurs, attempting to evaluate the 988 // to make sure that even if the error occurs, attempting to evaluate the
977 // constant will terminate. 989 // constant will terminate.
978 CompilationUnit compilationUnit = resolveSource(r''' 990 CompilationUnit compilationUnit = await resolveSource(r'''
979 const foo = const A(); 991 const foo = const A();
980 class A { 992 class A {
981 const factory A() = A.b; 993 const factory A() = A.b;
982 const factory A.b() = A; 994 const factory A.b() = A;
983 }'''); 995 }''');
984 _assertValidUnknown(_evaluateTopLevelVariable(compilationUnit, "foo")); 996 _assertValidUnknown(_evaluateTopLevelVariable(compilationUnit, "foo"));
985 } 997 }
986 998
987 test_instanceCreationExpression_redirect_external() async { 999 test_instanceCreationExpression_redirect_external() async {
988 CompilationUnit compilationUnit = resolveSource(r''' 1000 CompilationUnit compilationUnit = await resolveSource(r'''
989 const foo = const A(); 1001 const foo = const A();
990 class A { 1002 class A {
991 external const factory A(); 1003 external const factory A();
992 }'''); 1004 }''');
993 _assertValidUnknown(_evaluateTopLevelVariable(compilationUnit, "foo")); 1005 _assertValidUnknown(_evaluateTopLevelVariable(compilationUnit, "foo"));
994 } 1006 }
995 1007
996 test_instanceCreationExpression_redirect_nonConst() async { 1008 test_instanceCreationExpression_redirect_nonConst() async {
997 // It is an error for a const factory constructor redirect to a non-const 1009 // It is an error for a const factory constructor redirect to a non-const
998 // constructor; however, we need to make sure that even if the error 1010 // constructor; however, we need to make sure that even if the error
999 // attempting to evaluate the constant won't cause a crash. 1011 // attempting to evaluate the constant won't cause a crash.
1000 CompilationUnit compilationUnit = resolveSource(r''' 1012 CompilationUnit compilationUnit = await resolveSource(r'''
1001 const foo = const A(); 1013 const foo = const A();
1002 class A { 1014 class A {
1003 const factory A() = A.b; 1015 const factory A() = A.b;
1004 A.b(); 1016 A.b();
1005 }'''); 1017 }''');
1006 _assertValidUnknown(_evaluateTopLevelVariable(compilationUnit, "foo")); 1018 _assertValidUnknown(_evaluateTopLevelVariable(compilationUnit, "foo"));
1007 } 1019 }
1008 1020
1009 test_instanceCreationExpression_redirectWithTypeParams() async { 1021 test_instanceCreationExpression_redirectWithTypeParams() async {
1010 CompilationUnit compilationUnit = resolveSource(r''' 1022 CompilationUnit compilationUnit = await resolveSource(r'''
1011 class A { 1023 class A {
1012 const factory A(var a) = B<int>; 1024 const factory A(var a) = B<int>;
1013 } 1025 }
1014 1026
1015 class B<T> implements A { 1027 class B<T> implements A {
1016 final T x; 1028 final T x;
1017 const B(this.x); 1029 const B(this.x);
1018 } 1030 }
1019 1031
1020 const A a = const A(10);'''); 1032 const A a = const A(10);''');
1021 EvaluationResultImpl result = 1033 EvaluationResultImpl result =
1022 _evaluateTopLevelVariable(compilationUnit, "a"); 1034 _evaluateTopLevelVariable(compilationUnit, "a");
1023 Map<String, DartObjectImpl> fields = _assertType(result, "B<int>"); 1035 Map<String, DartObjectImpl> fields = _assertType(result, "B<int>");
1024 expect(fields, hasLength(1)); 1036 expect(fields, hasLength(1));
1025 _assertIntField(fields, "x", 10); 1037 _assertIntField(fields, "x", 10);
1026 } 1038 }
1027 1039
1028 test_instanceCreationExpression_redirectWithTypeSubstitution() async { 1040 test_instanceCreationExpression_redirectWithTypeSubstitution() async {
1029 // To evaluate the redirection of A<int>, 1041 // To evaluate the redirection of A<int>,
1030 // A's template argument (T=int) must be substituted 1042 // A's template argument (T=int) must be substituted
1031 // into B's template argument (B<U> where U=T) to get B<int>. 1043 // into B's template argument (B<U> where U=T) to get B<int>.
1032 CompilationUnit compilationUnit = resolveSource(r''' 1044 CompilationUnit compilationUnit = await resolveSource(r'''
1033 class A<T> { 1045 class A<T> {
1034 const factory A(var a) = B<T>; 1046 const factory A(var a) = B<T>;
1035 } 1047 }
1036 1048
1037 class B<U> implements A { 1049 class B<U> implements A {
1038 final U x; 1050 final U x;
1039 const B(this.x); 1051 const B(this.x);
1040 } 1052 }
1041 1053
1042 const A<int> a = const A<int>(10);'''); 1054 const A<int> a = const A<int>(10);''');
1043 EvaluationResultImpl result = 1055 EvaluationResultImpl result =
1044 _evaluateTopLevelVariable(compilationUnit, "a"); 1056 _evaluateTopLevelVariable(compilationUnit, "a");
1045 Map<String, DartObjectImpl> fields = _assertType(result, "B<int>"); 1057 Map<String, DartObjectImpl> fields = _assertType(result, "B<int>");
1046 expect(fields, hasLength(1)); 1058 expect(fields, hasLength(1));
1047 _assertIntField(fields, "x", 10); 1059 _assertIntField(fields, "x", 10);
1048 } 1060 }
1049 1061
1050 test_instanceCreationExpression_symbol() async { 1062 test_instanceCreationExpression_symbol() async {
1051 CompilationUnit compilationUnit = 1063 CompilationUnit compilationUnit =
1052 resolveSource("const foo = const Symbol('a');"); 1064 await resolveSource("const foo = const Symbol('a');");
1053 EvaluationResultImpl evaluationResult = 1065 EvaluationResultImpl evaluationResult =
1054 _evaluateTopLevelVariable(compilationUnit, "foo"); 1066 _evaluateTopLevelVariable(compilationUnit, "foo");
1055 expect(evaluationResult.value, isNotNull); 1067 expect(evaluationResult.value, isNotNull);
1056 DartObjectImpl value = evaluationResult.value; 1068 DartObjectImpl value = evaluationResult.value;
1057 expect(value.type, typeProvider.symbolType); 1069 expect(value.type, typeProvider.symbolType);
1058 expect(value.toSymbolValue(), "a"); 1070 expect(value.toSymbolValue(), "a");
1059 } 1071 }
1060 1072
1061 test_instanceCreationExpression_withSupertypeParams_explicit() async { 1073 test_instanceCreationExpression_withSupertypeParams_explicit() async {
1062 _checkInstanceCreation_withSupertypeParams(true); 1074 await _checkInstanceCreation_withSupertypeParams(true);
1063 } 1075 }
1064 1076
1065 test_instanceCreationExpression_withSupertypeParams_implicit() async { 1077 test_instanceCreationExpression_withSupertypeParams_implicit() async {
1066 _checkInstanceCreation_withSupertypeParams(false); 1078 await _checkInstanceCreation_withSupertypeParams(false);
1067 } 1079 }
1068 1080
1069 test_instanceCreationExpression_withTypeParams() async { 1081 test_instanceCreationExpression_withTypeParams() async {
1070 CompilationUnit compilationUnit = resolveSource(r''' 1082 CompilationUnit compilationUnit = await resolveSource(r'''
1071 class C<E> { 1083 class C<E> {
1072 const C(); 1084 const C();
1073 } 1085 }
1074 const c_int = const C<int>(); 1086 const c_int = const C<int>();
1075 const c_num = const C<num>();'''); 1087 const c_num = const C<num>();''');
1076 EvaluationResultImpl c_int = 1088 EvaluationResultImpl c_int =
1077 _evaluateTopLevelVariable(compilationUnit, "c_int"); 1089 _evaluateTopLevelVariable(compilationUnit, "c_int");
1078 _assertType(c_int, "C<int>"); 1090 _assertType(c_int, "C<int>");
1079 DartObjectImpl c_int_value = c_int.value; 1091 DartObjectImpl c_int_value = c_int.value;
1080 EvaluationResultImpl c_num = 1092 EvaluationResultImpl c_num =
(...skipping 27 matching lines...) Expand all
1108 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo."), isFalse); 1120 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo."), isFalse);
1109 expect(ConstantEvaluationEngine.isValidPublicSymbol("+.foo"), isFalse); 1121 expect(ConstantEvaluationEngine.isValidPublicSymbol("+.foo"), isFalse);
1110 expect(ConstantEvaluationEngine.isValidPublicSymbol("void.foo"), isFalse); 1122 expect(ConstantEvaluationEngine.isValidPublicSymbol("void.foo"), isFalse);
1111 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo.void"), isFalse); 1123 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo.void"), isFalse);
1112 } 1124 }
1113 1125
1114 test_length_of_improperly_typed_string_expression() async { 1126 test_length_of_improperly_typed_string_expression() async {
1115 // Since type annotations are ignored in unchecked mode, the improper 1127 // Since type annotations are ignored in unchecked mode, the improper
1116 // types on s1 and s2 shouldn't prevent us from evaluating i to 1128 // types on s1 and s2 shouldn't prevent us from evaluating i to
1117 // 'alpha'.length. 1129 // 'alpha'.length.
1118 CompilationUnit compilationUnit = resolveSource(''' 1130 CompilationUnit compilationUnit = await resolveSource('''
1119 const int s1 = 'alpha'; 1131 const int s1 = 'alpha';
1120 const int s2 = 'beta'; 1132 const int s2 = 'beta';
1121 const int i = (true ? s1 : s2).length; 1133 const int i = (true ? s1 : s2).length;
1122 '''); 1134 ''');
1123 ConstTopLevelVariableElementImpl element = 1135 ConstTopLevelVariableElementImpl element =
1124 findTopLevelDeclaration(compilationUnit, 'i').element; 1136 findTopLevelDeclaration(compilationUnit, 'i').element;
1125 EvaluationResultImpl result = element.evaluationResult; 1137 EvaluationResultImpl result = element.evaluationResult;
1126 expect(_assertValidInt(result), 5); 1138 expect(_assertValidInt(result), 5);
1127 } 1139 }
1128 1140
1129 test_length_of_improperly_typed_string_identifier() async { 1141 test_length_of_improperly_typed_string_identifier() async {
1130 // Since type annotations are ignored in unchecked mode, the improper type 1142 // Since type annotations are ignored in unchecked mode, the improper type
1131 // on s shouldn't prevent us from evaluating i to 'alpha'.length. 1143 // on s shouldn't prevent us from evaluating i to 'alpha'.length.
1132 CompilationUnit compilationUnit = resolveSource(''' 1144 CompilationUnit compilationUnit = await resolveSource('''
1133 const int s = 'alpha'; 1145 const int s = 'alpha';
1134 const int i = s.length; 1146 const int i = s.length;
1135 '''); 1147 ''');
1136 ConstTopLevelVariableElementImpl element = 1148 ConstTopLevelVariableElementImpl element =
1137 findTopLevelDeclaration(compilationUnit, 'i').element; 1149 findTopLevelDeclaration(compilationUnit, 'i').element;
1138 EvaluationResultImpl result = element.evaluationResult; 1150 EvaluationResultImpl result = element.evaluationResult;
1139 expect(_assertValidInt(result), 5); 1151 expect(_assertValidInt(result), 5);
1140 } 1152 }
1141 1153
1142 test_non_static_const_initialized_at_declaration() async { 1154 test_non_static_const_initialized_at_declaration() async {
1143 // Even though non-static consts are not allowed by the language, we need 1155 // Even though non-static consts are not allowed by the language, we need
1144 // to handle them for error recovery purposes. 1156 // to handle them for error recovery purposes.
1145 CompilationUnit compilationUnit = resolveSource(''' 1157 CompilationUnit compilationUnit = await resolveSource('''
1146 class A { 1158 class A {
1147 const int i = 123; 1159 const int i = 123;
1148 const A(); 1160 const A();
1149 } 1161 }
1150 1162
1151 const A a = const A(); 1163 const A a = const A();
1152 '''); 1164 ''');
1153 EvaluationResultImpl result = 1165 EvaluationResultImpl result =
1154 _evaluateTopLevelVariable(compilationUnit, 'a'); 1166 _evaluateTopLevelVariable(compilationUnit, 'a');
1155 Map<String, DartObjectImpl> fields = _assertType(result, "A"); 1167 Map<String, DartObjectImpl> fields = _assertType(result, "A");
1156 expect(fields, hasLength(1)); 1168 expect(fields, hasLength(1));
1157 _assertIntField(fields, "i", 123); 1169 _assertIntField(fields, "i", 123);
1158 } 1170 }
1159 1171
1160 test_symbolLiteral_void() async { 1172 test_symbolLiteral_void() async {
1161 CompilationUnit compilationUnit = 1173 CompilationUnit compilationUnit =
1162 resolveSource("const voidSymbol = #void;"); 1174 await resolveSource("const voidSymbol = #void;");
1163 VariableDeclaration voidSymbol = 1175 VariableDeclaration voidSymbol =
1164 findTopLevelDeclaration(compilationUnit, "voidSymbol"); 1176 findTopLevelDeclaration(compilationUnit, "voidSymbol");
1165 EvaluationResultImpl voidSymbolResult = 1177 EvaluationResultImpl voidSymbolResult =
1166 (voidSymbol.element as VariableElementImpl).evaluationResult; 1178 (voidSymbol.element as VariableElementImpl).evaluationResult;
1167 DartObjectImpl value = voidSymbolResult.value; 1179 DartObjectImpl value = voidSymbolResult.value;
1168 expect(value.type, typeProvider.symbolType); 1180 expect(value.type, typeProvider.symbolType);
1169 expect(value.toSymbolValue(), "void"); 1181 expect(value.toSymbolValue(), "void");
1170 } 1182 }
1171 1183
1172 Map<String, DartObjectImpl> _assertFieldType( 1184 Map<String, DartObjectImpl> _assertFieldType(
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1241 expect(value.type, typeProvider.stringType); 1253 expect(value.type, typeProvider.stringType);
1242 return value.toStringValue(); 1254 return value.toStringValue();
1243 } 1255 }
1244 1256
1245 void _assertValidUnknown(EvaluationResultImpl result) { 1257 void _assertValidUnknown(EvaluationResultImpl result) {
1246 expect(result.value, isNotNull); 1258 expect(result.value, isNotNull);
1247 DartObjectImpl value = result.value; 1259 DartObjectImpl value = result.value;
1248 expect(value.isUnknown, isTrue); 1260 expect(value.isUnknown, isTrue);
1249 } 1261 }
1250 1262
1251 EvaluationResultImpl _check_fromEnvironment_bool( 1263 Future<EvaluationResultImpl> _check_fromEnvironment_bool(
1252 String valueInEnvironment, String defaultExpr) { 1264 String valueInEnvironment, String defaultExpr) async {
1253 String envVarName = "x"; 1265 String envVarName = "x";
1254 String varName = "foo"; 1266 String varName = "foo";
1255 if (valueInEnvironment != null) { 1267 if (valueInEnvironment != null) {
1256 analysisContext2.declaredVariables.define(envVarName, valueInEnvironment); 1268 analysisContext2.declaredVariables.define(envVarName, valueInEnvironment);
1257 } 1269 }
1258 String defaultArg = 1270 String defaultArg =
1259 defaultExpr == null ? "" : ", defaultValue: $defaultExpr"; 1271 defaultExpr == null ? "" : ", defaultValue: $defaultExpr";
1260 CompilationUnit compilationUnit = resolveSource( 1272 CompilationUnit compilationUnit = await resolveSource(
1261 "const $varName = const bool.fromEnvironment('$envVarName'$defaultArg);" ); 1273 "const $varName = const bool.fromEnvironment('$envVarName'$defaultArg);" );
1262 return _evaluateTopLevelVariable(compilationUnit, varName); 1274 return _evaluateTopLevelVariable(compilationUnit, varName);
1263 } 1275 }
1264 1276
1265 EvaluationResultImpl _check_fromEnvironment_int( 1277 Future<EvaluationResultImpl> _check_fromEnvironment_int(
1266 String valueInEnvironment, String defaultExpr) { 1278 String valueInEnvironment, String defaultExpr) async {
1267 String envVarName = "x"; 1279 String envVarName = "x";
1268 String varName = "foo"; 1280 String varName = "foo";
1269 if (valueInEnvironment != null) { 1281 if (valueInEnvironment != null) {
1270 analysisContext2.declaredVariables.define(envVarName, valueInEnvironment); 1282 analysisContext2.declaredVariables.define(envVarName, valueInEnvironment);
1271 } 1283 }
1272 String defaultArg = 1284 String defaultArg =
1273 defaultExpr == null ? "" : ", defaultValue: $defaultExpr"; 1285 defaultExpr == null ? "" : ", defaultValue: $defaultExpr";
1274 CompilationUnit compilationUnit = resolveSource( 1286 CompilationUnit compilationUnit = await resolveSource(
1275 "const $varName = const int.fromEnvironment('$envVarName'$defaultArg);") ; 1287 "const $varName = const int.fromEnvironment('$envVarName'$defaultArg);") ;
1276 return _evaluateTopLevelVariable(compilationUnit, varName); 1288 return _evaluateTopLevelVariable(compilationUnit, varName);
1277 } 1289 }
1278 1290
1279 EvaluationResultImpl _check_fromEnvironment_string( 1291 Future<EvaluationResultImpl> _check_fromEnvironment_string(
1280 String valueInEnvironment, String defaultExpr) { 1292 String valueInEnvironment, String defaultExpr) async {
1281 String envVarName = "x"; 1293 String envVarName = "x";
1282 String varName = "foo"; 1294 String varName = "foo";
1283 if (valueInEnvironment != null) { 1295 if (valueInEnvironment != null) {
1284 analysisContext2.declaredVariables.define(envVarName, valueInEnvironment); 1296 analysisContext2.declaredVariables.define(envVarName, valueInEnvironment);
1285 } 1297 }
1286 String defaultArg = 1298 String defaultArg =
1287 defaultExpr == null ? "" : ", defaultValue: $defaultExpr"; 1299 defaultExpr == null ? "" : ", defaultValue: $defaultExpr";
1288 CompilationUnit compilationUnit = resolveSource( 1300 CompilationUnit compilationUnit = await resolveSource(
1289 "const $varName = const String.fromEnvironment('$envVarName'$defaultArg) ;"); 1301 "const $varName = const String.fromEnvironment('$envVarName'$defaultArg) ;");
1290 return _evaluateTopLevelVariable(compilationUnit, varName); 1302 return _evaluateTopLevelVariable(compilationUnit, varName);
1291 } 1303 }
1292 1304
1293 void _checkInstanceCreation_withSupertypeParams(bool isExplicit) { 1305 Future<Null> _checkInstanceCreation_withSupertypeParams(
1306 bool isExplicit) async {
1294 String superCall = isExplicit ? " : super()" : ""; 1307 String superCall = isExplicit ? " : super()" : "";
1295 CompilationUnit compilationUnit = resolveSource(""" 1308 CompilationUnit compilationUnit = await resolveSource("""
1296 class A<T> { 1309 class A<T> {
1297 const A(); 1310 const A();
1298 } 1311 }
1299 class B<T, U> extends A<T> { 1312 class B<T, U> extends A<T> {
1300 const B()$superCall; 1313 const B()$superCall;
1301 } 1314 }
1302 class C<T, U> extends A<U> { 1315 class C<T, U> extends A<U> {
1303 const C()$superCall; 1316 const C()$superCall;
1304 } 1317 }
1305 const b_int_num = const B<int, num>(); 1318 const b_int_num = const B<int, num>();
1306 const c_int_num = const C<int, num>();"""); 1319 const c_int_num = const C<int, num>();""");
1307 EvaluationResultImpl b_int_num = 1320 EvaluationResultImpl b_int_num =
1308 _evaluateTopLevelVariable(compilationUnit, "b_int_num"); 1321 _evaluateTopLevelVariable(compilationUnit, "b_int_num");
1309 Map<String, DartObjectImpl> b_int_num_fields = 1322 Map<String, DartObjectImpl> b_int_num_fields =
1310 _assertType(b_int_num, "B<int, num>"); 1323 _assertType(b_int_num, "B<int, num>");
1311 _assertFieldType(b_int_num_fields, GenericState.SUPERCLASS_FIELD, "A<int>"); 1324 _assertFieldType(b_int_num_fields, GenericState.SUPERCLASS_FIELD, "A<int>");
1312 EvaluationResultImpl c_int_num = 1325 EvaluationResultImpl c_int_num =
1313 _evaluateTopLevelVariable(compilationUnit, "c_int_num"); 1326 _evaluateTopLevelVariable(compilationUnit, "c_int_num");
1314 Map<String, DartObjectImpl> c_int_num_fields = 1327 Map<String, DartObjectImpl> c_int_num_fields =
1315 _assertType(c_int_num, "C<int, num>"); 1328 _assertType(c_int_num, "C<int, num>");
1316 _assertFieldType(c_int_num_fields, GenericState.SUPERCLASS_FIELD, "A<num>"); 1329 _assertFieldType(c_int_num_fields, GenericState.SUPERCLASS_FIELD, "A<num>");
1317 } 1330 }
1318 1331
1319 void _checkInstanceCreationOptionalParams( 1332 Future<Null> _checkInstanceCreationOptionalParams(
1320 bool isFieldFormal, bool isNamed, bool hasDefault) { 1333 bool isFieldFormal, bool isNamed, bool hasDefault) async {
1321 String fieldName = "j"; 1334 String fieldName = "j";
1322 String paramName = isFieldFormal ? fieldName : "i"; 1335 String paramName = isFieldFormal ? fieldName : "i";
1323 String formalParam = 1336 String formalParam =
1324 "${isFieldFormal ? "this." : "int "}$paramName${hasDefault ? " = 3" : "" }"; 1337 "${isFieldFormal ? "this." : "int "}$paramName${hasDefault ? " = 3" : "" }";
1325 CompilationUnit compilationUnit = resolveSource(""" 1338 CompilationUnit compilationUnit = await resolveSource("""
1326 const x = const A(); 1339 const x = const A();
1327 const y = const A(${isNamed ? '$paramName: ' : ''}10); 1340 const y = const A(${isNamed ? '$paramName: ' : ''}10);
1328 class A { 1341 class A {
1329 const A(${isNamed ? "{$formalParam}" : "[$formalParam]"})${isFieldFormal ? "" : " : $fieldName = $paramName"}; 1342 const A(${isNamed ? "{$formalParam}" : "[$formalParam]"})${isFieldFormal ? "" : " : $fieldName = $paramName"};
1330 final int $fieldName; 1343 final int $fieldName;
1331 }"""); 1344 }""");
1332 EvaluationResultImpl x = _evaluateTopLevelVariable(compilationUnit, "x"); 1345 EvaluationResultImpl x = _evaluateTopLevelVariable(compilationUnit, "x");
1333 Map<String, DartObjectImpl> fieldsOfX = _assertType(x, "A"); 1346 Map<String, DartObjectImpl> fieldsOfX = _assertType(x, "A");
1334 expect(fieldsOfX, hasLength(1)); 1347 expect(fieldsOfX, hasLength(1));
1335 if (hasDefault) { 1348 if (hasDefault) {
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1510 ConditionalExpression expression = AstTestFactory.conditionalExpression( 1523 ConditionalExpression expression = AstTestFactory.conditionalExpression(
1511 AstTestFactory.booleanLiteral(true), thenExpression, elseExpression); 1524 AstTestFactory.booleanLiteral(true), thenExpression, elseExpression);
1512 GatheringErrorListener errorListener = new GatheringErrorListener(); 1525 GatheringErrorListener errorListener = new GatheringErrorListener();
1513 ErrorReporter errorReporter = 1526 ErrorReporter errorReporter =
1514 new ErrorReporter(errorListener, _dummySource()); 1527 new ErrorReporter(errorListener, _dummySource());
1515 _assertValue(1, _evaluate(expression, errorReporter)); 1528 _assertValue(1, _evaluate(expression, errorReporter));
1516 errorListener.assertNoErrors(); 1529 errorListener.assertNoErrors();
1517 } 1530 }
1518 1531
1519 test_visitSimpleIdentifier_className() async { 1532 test_visitSimpleIdentifier_className() async {
1520 CompilationUnit compilationUnit = resolveSource(''' 1533 CompilationUnit compilationUnit = await resolveSource('''
1521 const a = C; 1534 const a = C;
1522 class C {} 1535 class C {}
1523 '''); 1536 ''');
1524 DartObjectImpl result = _evaluateConstant(compilationUnit, 'a', null); 1537 DartObjectImpl result = _evaluateConstant(compilationUnit, 'a', null);
1525 expect(result.type, typeProvider.typeType); 1538 expect(result.type, typeProvider.typeType);
1526 expect(result.toTypeValue().name, 'C'); 1539 expect(result.toTypeValue().name, 'C');
1527 } 1540 }
1528 1541
1529 test_visitSimpleIdentifier_dynamic() async { 1542 test_visitSimpleIdentifier_dynamic() async {
1530 CompilationUnit compilationUnit = resolveSource(''' 1543 CompilationUnit compilationUnit = await resolveSource('''
1531 const a = dynamic; 1544 const a = dynamic;
1532 '''); 1545 ''');
1533 DartObjectImpl result = _evaluateConstant(compilationUnit, 'a', null); 1546 DartObjectImpl result = _evaluateConstant(compilationUnit, 'a', null);
1534 expect(result.type, typeProvider.typeType); 1547 expect(result.type, typeProvider.typeType);
1535 expect(result.toTypeValue(), typeProvider.dynamicType); 1548 expect(result.toTypeValue(), typeProvider.dynamicType);
1536 } 1549 }
1537 1550
1538 test_visitSimpleIdentifier_inEnvironment() async { 1551 test_visitSimpleIdentifier_inEnvironment() async {
1539 CompilationUnit compilationUnit = resolveSource(r''' 1552 CompilationUnit compilationUnit = await resolveSource(r'''
1540 const a = b; 1553 const a = b;
1541 const b = 3;'''); 1554 const b = 3;''');
1542 Map<String, DartObjectImpl> environment = new Map<String, DartObjectImpl>(); 1555 Map<String, DartObjectImpl> environment = new Map<String, DartObjectImpl>();
1543 DartObjectImpl six = 1556 DartObjectImpl six =
1544 new DartObjectImpl(typeProvider.intType, new IntState(6)); 1557 new DartObjectImpl(typeProvider.intType, new IntState(6));
1545 environment["b"] = six; 1558 environment["b"] = six;
1546 _assertValue(6, _evaluateConstant(compilationUnit, "a", environment)); 1559 _assertValue(6, _evaluateConstant(compilationUnit, "a", environment));
1547 } 1560 }
1548 1561
1549 test_visitSimpleIdentifier_notInEnvironment() async { 1562 test_visitSimpleIdentifier_notInEnvironment() async {
1550 CompilationUnit compilationUnit = resolveSource(r''' 1563 CompilationUnit compilationUnit = await resolveSource(r'''
1551 const a = b; 1564 const a = b;
1552 const b = 3;'''); 1565 const b = 3;''');
1553 Map<String, DartObjectImpl> environment = new Map<String, DartObjectImpl>(); 1566 Map<String, DartObjectImpl> environment = new Map<String, DartObjectImpl>();
1554 DartObjectImpl six = 1567 DartObjectImpl six =
1555 new DartObjectImpl(typeProvider.intType, new IntState(6)); 1568 new DartObjectImpl(typeProvider.intType, new IntState(6));
1556 environment["c"] = six; 1569 environment["c"] = six;
1557 _assertValue(3, _evaluateConstant(compilationUnit, "a", environment)); 1570 _assertValue(3, _evaluateConstant(compilationUnit, "a", environment));
1558 } 1571 }
1559 1572
1560 test_visitSimpleIdentifier_withoutEnvironment() async { 1573 test_visitSimpleIdentifier_withoutEnvironment() async {
1561 CompilationUnit compilationUnit = resolveSource(r''' 1574 CompilationUnit compilationUnit = await resolveSource(r'''
1562 const a = b; 1575 const a = b;
1563 const b = 3;'''); 1576 const b = 3;''');
1564 _assertValue(3, _evaluateConstant(compilationUnit, "a", null)); 1577 _assertValue(3, _evaluateConstant(compilationUnit, "a", null));
1565 } 1578 }
1566 1579
1567 void _assertValue(int expectedValue, DartObjectImpl result) { 1580 void _assertValue(int expectedValue, DartObjectImpl result) {
1568 expect(result, isNotNull); 1581 expect(result, isNotNull);
1569 expect(result.type.name, "int"); 1582 expect(result.type.name, "int");
1570 expect(result.toIntValue(), expectedValue); 1583 expect(result.toIntValue(), expectedValue);
1571 } 1584 }
(...skipping 29 matching lines...) Expand all
1601 } 1614 }
1602 } 1615 }
1603 1616
1604 @reflectiveTest 1617 @reflectiveTest
1605 class StrongConstantValueComputerTest extends ConstantValueComputerTest { 1618 class StrongConstantValueComputerTest extends ConstantValueComputerTest {
1606 void setUp() { 1619 void setUp() {
1607 super.setUp(); 1620 super.setUp();
1608 resetWith(options: new AnalysisOptionsImpl()..strongMode = true); 1621 resetWith(options: new AnalysisOptionsImpl()..strongMode = true);
1609 } 1622 }
1610 } 1623 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/strong_mode_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698