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

Side by Side Diff: pkg/compiler/lib/src/resolution/constructors.dart

Issue 2104843002: Handle fields with initializers in constant constructors. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fix invariants Created 4 years, 5 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
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 dart2js.resolution.constructors; 5 library dart2js.resolution.constructors;
6 6
7 import '../common.dart'; 7 import '../common.dart';
8 import '../common/resolution.dart' show Feature; 8 import '../common/resolution.dart' show Feature;
9 import '../compiler.dart' show Compiler; 9 import '../compiler.dart' show Compiler;
10 import '../constants/constructors.dart' 10 import '../constants/constructors.dart'
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 return null; 417 return null;
418 } 418 }
419 } else { 419 } else {
420 reporter.reportErrorMessage(link.head, MessageKind.INVALID_INITIALIZER); 420 reporter.reportErrorMessage(link.head, MessageKind.INVALID_INITIALIZER);
421 } 421 }
422 } 422 }
423 if (!resolvedSuper) { 423 if (!resolvedSuper) {
424 constructorInvocation = resolveImplicitSuperConstructorSend(); 424 constructorInvocation = resolveImplicitSuperConstructorSend();
425 } 425 }
426 if (isConst && isValidAsConstant) { 426 if (isConst && isValidAsConstant) {
427 constructor.constantConstructor = new GenerativeConstantConstructor( 427 constructor.enclosingClass.forEachInstanceField((_, FieldElement field) {
428 constructor.enclosingClass.thisType, 428 if (!fieldInitializers.containsKey(field)) {
429 defaultValues, 429 visitor.resolution.ensureResolved(field);
430 fieldInitializers, 430 // TODO(johnniwinther): Report error if `field.constant` is `null`.
431 constructorInvocation); 431 if (field.constant != null) {
432 fieldInitializers[field] = field.constant;
433 } else {
434 isValidAsConstant = false;
435 }
436 }
437 });
438 if (isValidAsConstant) {
439 constructor.constantConstructor = new GenerativeConstantConstructor(
440 constructor.enclosingClass.thisType,
441 defaultValues,
442 fieldInitializers,
443 constructorInvocation);
444 }
432 } 445 }
433 return null; // If there was no redirection always return null. 446 return null; // If there was no redirection always return null.
434 } 447 }
435 } 448 }
436 449
437 class ConstructorResolver extends CommonResolverVisitor<ConstructorResult> { 450 class ConstructorResolver extends CommonResolverVisitor<ConstructorResult> {
438 final ResolverVisitor resolver; 451 final ResolverVisitor resolver;
439 final bool inConstContext; 452 final bool inConstContext;
440 453
441 ConstructorResolver(Compiler compiler, this.resolver, 454 ConstructorResolver(Compiler compiler, this.resolver,
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 // constructors. 863 // constructors.
851 return null; 864 return null;
852 } 865 }
853 // TODO(johnniwinther): Use [Name] for lookup. 866 // TODO(johnniwinther): Use [Name] for lookup.
854 ConstructorElement constructor = cls.lookupConstructor(constructorName); 867 ConstructorElement constructor = cls.lookupConstructor(constructorName);
855 if (constructor != null) { 868 if (constructor != null) {
856 constructor = constructor.declaration; 869 constructor = constructor.declaration;
857 } 870 }
858 return constructor; 871 return constructor;
859 } 872 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698