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

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

Issue 2837743002: Issue 29432. Instantiate the redirect constructor with the in-scope type arguments. (Closed)
Patch Set: Created 3 years, 8 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/compile_time_error_code_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 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 } 717 }
718 718
719 test_fromEnvironment_string_undeclared() async { 719 test_fromEnvironment_string_undeclared() async {
720 _assertValidUnknown(await _check_fromEnvironment_string(null, null)); 720 _assertValidUnknown(await _check_fromEnvironment_string(null, null));
721 } 721 }
722 722
723 test_fromEnvironment_string_undeclared_nullDefault() async { 723 test_fromEnvironment_string_undeclared_nullDefault() async {
724 _assertValidNull(await _check_fromEnvironment_string(null, "null")); 724 _assertValidNull(await _check_fromEnvironment_string(null, "null"));
725 } 725 }
726 726
727 test_getConstructor_redirectingFactory() async {
728 CompilationUnit compilationUnit = await resolveSource(r'''
729 class A {
730 factory const A() = B;
731 }
732
733 class B implements A {
734 const B();
735 }
736
737 class C {
738 @A()
739 f() {}
740 }
741 ''');
742 EvaluationResultImpl result =
743 _evaluateAnnotation(compilationUnit, "C", "f");
744 expect(result.value.getInvocation().constructor.isFactory, isTrue);
745 }
746
747 test_getConstructor_withArgs() async {
748 CompilationUnit compilationUnit = await resolveSource(r'''
749 class A {
750 final int i;
751 const A(this.i);
752 }
753
754 class C {
755 @A(5)
756 f() {}
757 }
758 ''');
759 EvaluationResultImpl result =
760 _evaluateAnnotation(compilationUnit, "C", "f");
761 ConstructorInvocation invocation = result.value.getInvocation();
762 expect(invocation.constructor, isNotNull);
763 expect(invocation.positionalArguments, hasLength(1));
764 expect(invocation.positionalArguments.single.toIntValue(), 5);
765 expect(invocation.namedArguments, isEmpty);
766 }
767
768 test_getConstructor_withNamedArgs() async {
769 CompilationUnit compilationUnit = await resolveSource(r'''
770 class A {
771 final int i;
772 const A({this.i});
773 }
774
775 class C {
776 @A(i: 5)
777 f() {}
778 }
779 ''');
780 EvaluationResultImpl result =
781 _evaluateAnnotation(compilationUnit, "C", "f");
782 ConstructorInvocation invocation = result.value.getInvocation();
783 expect(invocation.constructor, isNotNull);
784 expect(invocation.positionalArguments, isEmpty);
785 expect(invocation.namedArguments, isNotEmpty);
786 expect(invocation.namedArguments['i'].toIntValue(), 5);
787 }
788
727 test_instanceCreationExpression_computedField() async { 789 test_instanceCreationExpression_computedField() async {
728 CompilationUnit compilationUnit = await resolveSource(r''' 790 CompilationUnit compilationUnit = await resolveSource(r'''
729 const foo = const A(4, 5); 791 const foo = const A(4, 5);
730 class A { 792 class A {
731 const A(int i, int j) : k = 2 * i + j; 793 const A(int i, int j) : k = 2 * i + j;
732 final int k; 794 final int k;
733 }'''); 795 }''');
734 EvaluationResultImpl result = 796 EvaluationResultImpl result =
735 _evaluateTopLevelVariable(compilationUnit, "foo"); 797 _evaluateTopLevelVariable(compilationUnit, "foo");
736 Map<String, DartObjectImpl> fields = _assertType(result, "A"); 798 Map<String, DartObjectImpl> fields = _assertType(result, "A");
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 1060
999 test_instanceCreationExpression_redirect_external() async { 1061 test_instanceCreationExpression_redirect_external() async {
1000 CompilationUnit compilationUnit = await resolveSource(r''' 1062 CompilationUnit compilationUnit = await resolveSource(r'''
1001 const foo = const A(); 1063 const foo = const A();
1002 class A { 1064 class A {
1003 external const factory A(); 1065 external const factory A();
1004 }'''); 1066 }''');
1005 _assertValidUnknown(_evaluateTopLevelVariable(compilationUnit, "foo")); 1067 _assertValidUnknown(_evaluateTopLevelVariable(compilationUnit, "foo"));
1006 } 1068 }
1007 1069
1070 test_instanceCreationExpression_redirect_generic() async {
1071 CompilationUnit compilationUnit = await resolveSource(r'''
1072 const foo = const A<int>();
1073 class A<T> {
1074 const A() : this._();
1075 const A._();
1076 }
1077 ''');
1078 _assertType(_evaluateTopLevelVariable(compilationUnit, 'foo'), 'A<int>');
1079 }
1080
1008 test_instanceCreationExpression_redirect_nonConst() async { 1081 test_instanceCreationExpression_redirect_nonConst() async {
1009 // It is an error for a const factory constructor redirect to a non-const 1082 // It is an error for a const factory constructor redirect to a non-const
1010 // constructor; however, we need to make sure that even if the error 1083 // constructor; however, we need to make sure that even if the error
1011 // attempting to evaluate the constant won't cause a crash. 1084 // attempting to evaluate the constant won't cause a crash.
1012 CompilationUnit compilationUnit = await resolveSource(r''' 1085 CompilationUnit compilationUnit = await resolveSource(r'''
1013 const foo = const A(); 1086 const foo = const A();
1014 class A { 1087 class A {
1015 const factory A() = A.b; 1088 const factory A() = A.b;
1016 A.b(); 1089 A.b();
1017 }'''); 1090 }''');
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 await resolveSource("const voidSymbol = #void;"); 1247 await resolveSource("const voidSymbol = #void;");
1175 VariableDeclaration voidSymbol = 1248 VariableDeclaration voidSymbol =
1176 findTopLevelDeclaration(compilationUnit, "voidSymbol"); 1249 findTopLevelDeclaration(compilationUnit, "voidSymbol");
1177 EvaluationResultImpl voidSymbolResult = 1250 EvaluationResultImpl voidSymbolResult =
1178 (voidSymbol.element as VariableElementImpl).evaluationResult; 1251 (voidSymbol.element as VariableElementImpl).evaluationResult;
1179 DartObjectImpl value = voidSymbolResult.value; 1252 DartObjectImpl value = voidSymbolResult.value;
1180 expect(value.type, typeProvider.symbolType); 1253 expect(value.type, typeProvider.symbolType);
1181 expect(value.toSymbolValue(), "void"); 1254 expect(value.toSymbolValue(), "void");
1182 } 1255 }
1183 1256
1184 test_getConstructor_withArgs() async {
1185 CompilationUnit compilationUnit = await resolveSource(r'''
1186 class A {
1187 final int i;
1188 const A(this.i);
1189 }
1190
1191 class C {
1192 @A(5)
1193 f() {}
1194 }
1195 ''');
1196 EvaluationResultImpl result =
1197 _evaluateAnnotation(compilationUnit, "C", "f");
1198 ConstructorInvocation invocation = result.value.getInvocation();
1199 expect(invocation.constructor, isNotNull);
1200 expect(invocation.positionalArguments, hasLength(1));
1201 expect(invocation.positionalArguments.single.toIntValue(), 5);
1202 expect(invocation.namedArguments, isEmpty);
1203 }
1204
1205 test_getConstructor_withNamedArgs() async {
1206 CompilationUnit compilationUnit = await resolveSource(r'''
1207 class A {
1208 final int i;
1209 const A({this.i});
1210 }
1211
1212 class C {
1213 @A(i: 5)
1214 f() {}
1215 }
1216 ''');
1217 EvaluationResultImpl result =
1218 _evaluateAnnotation(compilationUnit, "C", "f");
1219 ConstructorInvocation invocation = result.value.getInvocation();
1220 expect(invocation.constructor, isNotNull);
1221 expect(invocation.positionalArguments, isEmpty);
1222 expect(invocation.namedArguments, isNotEmpty);
1223 expect(invocation.namedArguments['i'].toIntValue(), 5);
1224 }
1225
1226 test_getConstructor_redirectingFactory() async {
1227 CompilationUnit compilationUnit = await resolveSource(r'''
1228 class A {
1229 factory const A() = B;
1230 }
1231
1232 class B implements A {
1233 const B();
1234 }
1235
1236 class C {
1237 @A()
1238 f() {}
1239 }
1240 ''');
1241 EvaluationResultImpl result =
1242 _evaluateAnnotation(compilationUnit, "C", "f");
1243 expect(result.value.getInvocation().constructor.isFactory, isTrue);
1244 }
1245
1246 Map<String, DartObjectImpl> _assertFieldType( 1257 Map<String, DartObjectImpl> _assertFieldType(
1247 Map<String, DartObjectImpl> fields, 1258 Map<String, DartObjectImpl> fields,
1248 String fieldName, 1259 String fieldName,
1249 String expectedType) { 1260 String expectedType) {
1250 DartObjectImpl field = fields[fieldName]; 1261 DartObjectImpl field = fields[fieldName];
1251 expect(field.type.displayName, expectedType); 1262 expect(field.type.displayName, expectedType);
1252 return field.fields; 1263 return field.fields;
1253 } 1264 }
1254 1265
1255 void _assertIntField( 1266 void _assertIntField(
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
1691 } 1702 }
1692 } 1703 }
1693 1704
1694 @reflectiveTest 1705 @reflectiveTest
1695 class StrongConstantValueComputerTest extends ConstantValueComputerTest { 1706 class StrongConstantValueComputerTest extends ConstantValueComputerTest {
1696 void setUp() { 1707 void setUp() {
1697 super.setUp(); 1708 super.setUp();
1698 resetWith(options: new AnalysisOptionsImpl()..strongMode = true); 1709 resetWith(options: new AnalysisOptionsImpl()..strongMode = true);
1699 } 1710 }
1700 } 1711 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/compile_time_error_code_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698