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

Side by Side Diff: frog/member.dart

Issue 8921009: frog: check that const constructors have potentially const initializers. Also (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | frog/minfrog » ('j') | tests/language/language.status » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 /** A formal parameter to a [Method]. */ 5 /** A formal parameter to a [Method]. */
6 class Parameter { 6 class Parameter {
7 FormalNode definition; 7 FormalNode definition;
8 Member method; 8 Member method;
9 9
10 String name; 10 String name;
(...skipping 1125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 for (var fname in value.fields.getKeys()) { 1136 for (var fname in value.fields.getKeys()) {
1137 fields[fname] = value.fields[fname]; 1137 fields[fname] = value.fields[fname];
1138 } 1138 }
1139 } 1139 }
1140 } else { 1140 } else {
1141 // Normal field initializer assignment. 1141 // Normal field initializer assignment.
1142 BinaryExpression assign = init; 1142 BinaryExpression assign = init;
1143 var x = assign.x; // DotExpression or VarExpression 1143 var x = assign.x; // DotExpression or VarExpression
1144 var fname = x.name.name; 1144 var fname = x.name.name;
1145 var val = generator.visitValue(assign.y); 1145 var val = generator.visitValue(assign.y);
1146 if (!val.isConst) {
1147 world.error('invalid non-const initializer in const constructor',
1148 assign.y.span);
jimhug 2011/12/12 18:14:30 Could this be val.span instead? It doesn't really
Siggi Cherem (dart-lang) 2011/12/12 18:20:55 For some reason in this case they are not the same
1149 }
1146 fields[fname] = val; 1150 fields[fname] = val;
1147 } 1151 }
1148 } 1152 }
1149 1153
1150 generator._popBlock(); 1154 generator._popBlock();
1151 } 1155 }
1152 1156
1153 // Add default values only if they weren't overriden in the constructor. 1157 // Add default values only if they weren't overriden in the constructor.
1154 for (var f in declaringType.members.getValues()) { 1158 for (var f in declaringType.members.getValues()) {
1155 if (f is FieldMember && !f.isStatic && f.value != null 1159 if (f is FieldMember && !f.isStatic && !fields.containsKey(f.name)) {
1156 && !fields.containsKey(f.name)) { 1160 if (!f.isFinal) {
1157 fields[f.name] = f.computeValue(); 1161 world.error('const class "${declaringType.name}" has non-final '
1162 + 'field "${f.name}"', f.span);
1163 }
1164 if (f.value != null) {
1165 fields[f.name] = f.computeValue();
1166 }
1158 } 1167 }
1159 } 1168 }
1160 1169
1161 return world.gen.globalForConst( 1170 return world.gen.globalForConst(
1162 new ConstObjectValue(target.type, fields, code, node.span), 1171 new ConstObjectValue(target.type, fields, code, node.span),
1163 args.values); 1172 args.values);
1164 } 1173 }
1165 1174
1166 1175
1167 Value _invokeBuiltin(MethodGenerator context, Node node, Value target, 1176 Value _invokeBuiltin(MethodGenerator context, Node node, Value target,
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after
1769 } 1778 }
1770 1779
1771 void forEach(void f(Member member)) { 1780 void forEach(void f(Member member)) {
1772 factories.forEach((_, Map constructors) { 1781 factories.forEach((_, Map constructors) {
1773 constructors.forEach((_, Member member) { 1782 constructors.forEach((_, Member member) {
1774 f(member); 1783 f(member);
1775 }); 1784 });
1776 }); 1785 });
1777 } 1786 }
1778 } 1787 }
OLDNEW
« no previous file with comments | « no previous file | frog/minfrog » ('j') | tests/language/language.status » ('J')

Powered by Google App Engine
This is Rietveld 408576698