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

Side by Side Diff: pkg/analyzer/test/src/summary/summary_common.dart

Issue 1840843003: Handle redirected constructors when generating summaries from ASTs. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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/lib/src/summary/link.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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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.src.summary.summary_common; 5 library analyzer.test.src.summary.summary_common;
6 6
7 import 'package:analyzer/analyzer.dart'; 7 import 'package:analyzer/analyzer.dart';
8 import 'package:analyzer/dart/ast/ast.dart'; 8 import 'package:analyzer/dart/ast/ast.dart';
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/src/dart/scanner/reader.dart'; 10 import 'package:analyzer/src/dart/scanner/reader.dart';
(...skipping 3927 matching lines...) Expand 10 before | Expand all | Expand 10 after
3938 } 3938 }
3939 class D { 3939 class D {
3940 final x; 3940 final x;
3941 D() : x = new C(); 3941 D() : x = new C();
3942 } 3942 }
3943 '''); 3943 ''');
3944 expect(findClass('C').executables[0].constCycleSlot, 0); 3944 expect(findClass('C').executables[0].constCycleSlot, 0);
3945 expect(findClass('D').executables[0].constCycleSlot, 0); 3945 expect(findClass('D').executables[0].constCycleSlot, 0);
3946 } 3946 }
3947 3947
3948 test_constructorCycle_redirectToImplicitConstructor() {
3949 serializeLibraryText(
3950 '''
3951 class C {
3952 const factory C() = D;
3953 }
3954 class D extends C {}
3955 ''',
3956 allowErrors: true);
3957 checkConstCycle('C', hasCycle: false);
3958 }
3959
3960 test_constructorCycle_redirectToNonConstConstructor() {
3961 // It's not valid Dart but we need to make sure it doesn't crash
3962 // summary generation.
3963 serializeLibraryText(
3964 '''
3965 class C {
3966 const factory C() = D;
3967 }
3968 class D extends C {
3969 D();
3970 }
3971 ''',
3972 allowErrors: true);
3973 checkConstCycle('C', hasCycle: false);
3974 }
3975
3976 test_constructorCycle_redirectToSymbolConstructor() {
3977 // The symbol constructor has some special case behaviors in analyzer.
3978 // Make sure those special case behaviors don't cause problems.
3979 serializeLibraryText(
3980 '''
3981 class C {
3982 const factory C(String name) = Symbol;
3983 }
3984 ''',
3985 allowErrors: true);
3986 checkConstCycle('C', hasCycle: false);
3987 }
3988
3948 test_constructorCycle_referenceToClass() { 3989 test_constructorCycle_referenceToClass() {
3949 serializeLibraryText(''' 3990 serializeLibraryText('''
3950 class C { 3991 class C {
3951 final x; 3992 final x;
3952 const C() : x = C; 3993 const C() : x = C;
3953 } 3994 }
3954 '''); 3995 ''');
3955 checkConstCycle('C', hasCycle: false); 3996 checkConstCycle('C', hasCycle: false);
3956 } 3997 }
3957 3998
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
4081 addNamedSource('/a.dart', ''); 4122 addNamedSource('/a.dart', '');
4082 serializeLibraryText( 4123 serializeLibraryText(
4083 ''' 4124 '''
4084 import 'a.dart' as a; 4125 import 'a.dart' as a;
4085 class C { 4126 class C {
4086 final x; 4127 final x;
4087 const C() : x = a.foo; 4128 const C() : x = a.foo;
4088 } 4129 }
4089 ''', 4130 ''',
4090 allowErrors: true); 4131 allowErrors: true);
4132 checkConstCycle('C', hasCycle: false);
4091 } 4133 }
4092 4134
4093 test_constructorCycle_referenceToUndefinedName_viaPrefix_nonExistentFile() { 4135 test_constructorCycle_referenceToUndefinedName_viaPrefix_nonExistentFile() {
4094 // It's not valid Dart but we need to make sure it doesn't crash 4136 // It's not valid Dart but we need to make sure it doesn't crash
4095 // summary generation. 4137 // summary generation.
4096 allowMissingFiles = true; 4138 allowMissingFiles = true;
4097 serializeLibraryText( 4139 serializeLibraryText(
4098 ''' 4140 '''
4099 import 'a.dart' as a; 4141 import 'a.dart' as a;
4100 class C { 4142 class C {
4101 final x; 4143 final x;
4102 const C() : x = a.foo; 4144 const C() : x = a.foo;
4103 } 4145 }
4104 ''', 4146 ''',
4105 allowErrors: true); 4147 allowErrors: true);
4148 checkConstCycle('C', hasCycle: false);
4149 }
4150
4151 test_constructorCycle_viaFactoryRedirect() {
4152 serializeLibraryText(
4153 '''
4154 class C {
4155 const C();
4156 const factory C.named() = D;
4157 }
4158 class D extends C {
4159 final x;
4160 const D() : x = y;
4161 }
4162 const y = const C.named();
4163 ''',
4164 allowErrors: true);
4165 checkConstCycle('C', hasCycle: false);
4166 checkConstCycle('C', name: 'named');
4167 checkConstCycle('D');
4106 } 4168 }
4107 4169
4108 test_constructorCycle_viaFinalField() { 4170 test_constructorCycle_viaFinalField() {
4109 serializeLibraryText( 4171 serializeLibraryText(
4110 ''' 4172 '''
4111 class C { 4173 class C {
4112 final x = const C(); 4174 final x = const C();
4113 const C(); 4175 const C();
4114 } 4176 }
4115 ''', 4177 ''',
4116 allowErrors: true); 4178 allowErrors: true);
4117 checkConstCycle('C'); 4179 checkConstCycle('C');
4118 } 4180 }
4119 4181
4120 test_constructorCycle_viaNamedConstructor() { 4182 test_constructorCycle_viaNamedConstructor() {
4121 serializeLibraryText(''' 4183 serializeLibraryText('''
4122 class C { 4184 class C {
4123 final x; 4185 final x;
4124 const C() : x = const D.named(); 4186 const C() : x = const D.named();
4125 } 4187 }
4126 class D { 4188 class D {
4127 final x; 4189 final x;
4128 const D.named() : x = const C(); 4190 const D.named() : x = const C();
4129 } 4191 }
4130 '''); 4192 ''');
4131 checkConstCycle('C'); 4193 checkConstCycle('C');
4132 checkConstCycle('D', name: 'named'); 4194 checkConstCycle('D', name: 'named');
4133 } 4195 }
4134 4196
4197 test_constructorCycle_viaOrdinaryRedirect() {
4198 serializeLibraryText('''
4199 class C {
4200 final x;
4201 const C() : this.named();
4202 const C.named() : x = const C();
4203 }
4204 ''');
4205 checkConstCycle('C');
4206 checkConstCycle('C', name: 'named');
4207 }
4208
4209 test_constructorCycle_viaOrdinaryRedirect_suppressSupertype() {
4210 // Since C redirects to C.named, it doesn't implicitly refer to B's unnamed
4211 // constructor. Therefore there is no cycle.
4212 serializeLibraryText('''
4213 class B {
4214 final x;
4215 const B() : x = const C();
4216 const B.named() : x = null;
4217 }
4218 class C extends B {
4219 const C() : this.named();
4220 const C.named() : super.named();
4221 }
4222 ''');
4223 checkConstCycle('B', hasCycle: false);
4224 checkConstCycle('B', name: 'named', hasCycle: false);
4225 checkConstCycle('C', hasCycle: false);
4226 checkConstCycle('C', name: 'named', hasCycle: false);
4227 }
4228
4135 test_constructorCycle_viaStaticField_inOtherClass() { 4229 test_constructorCycle_viaStaticField_inOtherClass() {
4136 serializeLibraryText( 4230 serializeLibraryText(
4137 ''' 4231 '''
4138 class C { 4232 class C {
4139 final x; 4233 final x;
4140 const C() : x = D.y; 4234 const C() : x = D.y;
4141 } 4235 }
4142 class D { 4236 class D {
4143 static const y = const C(); 4237 static const y = const C();
4144 } 4238 }
(...skipping 3978 matching lines...) Expand 10 before | Expand all | Expand 10 after
8123 class _PrefixExpectation { 8217 class _PrefixExpectation {
8124 final ReferenceKind kind; 8218 final ReferenceKind kind;
8125 final String name; 8219 final String name;
8126 final String absoluteUri; 8220 final String absoluteUri;
8127 final String relativeUri; 8221 final String relativeUri;
8128 final int numTypeParameters; 8222 final int numTypeParameters;
8129 8223
8130 _PrefixExpectation(this.kind, this.name, 8224 _PrefixExpectation(this.kind, this.name,
8131 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0}); 8225 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0});
8132 } 8226 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/link.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698