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

Unified Diff: runtime/vm/parser.cc

Issue 11363012: Prevent mutation of final variables (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/ast.cc ('k') | tests/language/final_variable_assignment_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/parser.cc
===================================================================
--- runtime/vm/parser.cc (revision 14350)
+++ runtime/vm/parser.cc (working copy)
@@ -6776,7 +6776,8 @@
bool Parser::IsAssignableExpr(AstNode* expr) {
- return (expr->IsLoadLocalNode() && !expr->AsLoadLocalNode()->HasPseudo())
+ return (expr->IsLoadLocalNode() && !expr->AsLoadLocalNode()->HasPseudo()
+ && (!expr->AsLoadLocalNode()->local().is_final()))
|| expr->IsLoadStaticFieldNode()
|| expr->IsStaticGetterNode()
|| expr->IsInstanceGetterNode()
@@ -6987,6 +6988,9 @@
Field::SetterSymbol(original->AsStaticGetterNode()->field_name()));
result = ThrowNoSuchMethodError(original->token_pos(), setter_name);
}
+ // TODO(hausner): if we decide to throw a no such method error on
+ // assignment to a final variable, we need to do the same as in the
+ // StaticGetterNode above.
if ((result != NULL) &&
(result->IsStoreIndexedNode() ||
result->IsInstanceSetterNode() ||
@@ -7160,6 +7164,7 @@
expr,
new LiteralNode(op_pos, Smi::ZoneHandle(Smi::New(1))));
AstNode* store = CreateAssignmentNode(left_expr, add);
+ ASSERT(store != NULL);
expr = store;
} else {
expr = ParsePostfixExpr();
« no previous file with comments | « runtime/vm/ast.cc ('k') | tests/language/final_variable_assignment_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698