Files
sdk/tests/language/assignable_expression_test.dart
T
hausner@google.com 2e3b0fd8bf Detect illegal assignable expressions
The AST cannot distinguish between (x) and x. Adding a check
to the VM compiler that detects syntactically illegal assignments
like (x) = 0. The existing checks only analyze the AST so we
didn’t detect some illegal cases.

Looking at the source to detect syntactically illegal left hand
expressions is a bit ugly because we can’t easily look at
previous tokens. This change rewinds the token iterator a few
positions and then moves forward to check whether the last token
of the expression is an identifier or a closing bracket ].

Added new test. We did not have a single test case for this :)

R=regis@google.com

Review URL: https://codereview.chromium.org//106843002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@30904 260f80e4-7a28-3924-810f-c04153c831b5
2013-12-05 18:15:21 +00:00

45 lines
1.4 KiB
Dart

// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test to detect syntactically illegal left-hand-side (assignable)
// expressions.
class C {
static var static_field = 0;
}
var tl_static_var = 0;
main() {
tl_static_var = 0;
(tl_static_var) = 0; /// 01: compile-time error
(tl_static_var)++; /// 02: compile-time error
++(tl_static_var); /// 03: compile-time error
C.static_field = 0;
(C.static_field) = 0; /// 11: compile-time error
(C.static_field)++; /// 12: compile-time error
++(C.static_field); /// 13: compile-time error
tl_static_var = [1, 2, 3];
tl_static_var[0] = 0;
(tl_static_var)[0] = 0;
(tl_static_var[0]) = 0; /// 21: compile-time error
(tl_static_var[0])++; /// 22: compile-time error
++(tl_static_var[0]); /// 23: compile-time error
C.static_field = [1, 2, 3];
(C.static_field[0]) = 0; /// 31: compile-time error
(C.static_field[0])++; /// 32: compile-time error
++(C.static_field[0]); /// 33: compile-time error
var a = 0;
(a) = 0; /// 41: compile-time error
(a)++; /// 42: compile-time error
++(a); /// 43: compile-time error
// Neat palindrome expression. x is assignable, ((x)) is not.
var funcnuf = (x) => ((x))=((x)) <= (x); /// 50: compile-time error
}