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

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 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 return null; 441 return null;
442 } 442 }
443 } else { 443 } else {
444 reporter.reportErrorMessage(link.head, MessageKind.INVALID_INITIALIZER); 444 reporter.reportErrorMessage(link.head, MessageKind.INVALID_INITIALIZER);
445 } 445 }
446 } 446 }
447 if (!resolvedSuper) { 447 if (!resolvedSuper) {
448 constructorInvocation = resolveImplicitSuperConstructorSend(); 448 constructorInvocation = resolveImplicitSuperConstructorSend();
449 } 449 }
450 if (isConst && isValidAsConstant) { 450 if (isConst && isValidAsConstant) {
451 constructor.constantConstructor = new GenerativeConstantConstructor( 451 constructor.enclosingClass.forEachInstanceField((_, FieldElement field) {
452 constructor.enclosingClass.thisType, 452 if (!fieldInitializers.containsKey(field)) {
453 defaultValues, 453 visitor.resolution.ensureResolved(field);
454 fieldInitializers, 454 // TODO(johnniwinther): Report error if `field.constant` is `null`.
455 constructorInvocation); 455 if (field.constant != null) {
456 fieldInitializers[field] = field.constant;
457 } else {
458 isValidAsConstant = false;
459 }
460 }
461 });
462 if (isValidAsConstant) {
463 constructor.constantConstructor = new GenerativeConstantConstructor(
464 constructor.enclosingClass.thisType,
465 defaultValues,
466 fieldInitializers,
467 constructorInvocation);
468 }
456 } 469 }
457 visitor.scope = oldScope; 470 visitor.scope = oldScope;
458 return null; // If there was no redirection always return null. 471 return null; // If there was no redirection always return null.
459 } 472 }
460 } 473 }
461 474
462 class ConstructorResolver extends CommonResolverVisitor<ConstructorResult> { 475 class ConstructorResolver extends CommonResolverVisitor<ConstructorResult> {
463 final ResolverVisitor resolver; 476 final ResolverVisitor resolver;
464 final bool inConstContext; 477 final bool inConstContext;
465 478
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 // constructors. 888 // constructors.
876 return null; 889 return null;
877 } 890 }
878 // TODO(johnniwinther): Use [Name] for lookup. 891 // TODO(johnniwinther): Use [Name] for lookup.
879 ConstructorElement constructor = cls.lookupConstructor(constructorName); 892 ConstructorElement constructor = cls.lookupConstructor(constructorName);
880 if (constructor != null) { 893 if (constructor != null) {
881 constructor = constructor.declaration; 894 constructor = constructor.declaration;
882 } 895 }
883 return constructor; 896 return constructor;
884 } 897 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/backend.dart ('k') | pkg/compiler/lib/src/resolution/resolution.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698