dart-sdk/tests/language/unsorted/assignable_expression_test.dart
Robert Nystrom d4154ac6dc Migrate language_2/unsorted to NNBD.
Change-Id: Iad2963c7f9c184b089dc6d15aa4442f58d194bc2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151983
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
2020-06-26 18:34:14 +00:00

114 lines
3.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 dynamic field = 0;
}
dynamic variable = 0;
main() {
variable = 0;
(variable) = 0;
//^^^^^^^^^^
// [analyzer] SYNTACTIC_ERROR.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE
//^^^^^^^^^^
// [analyzer] SYNTACTIC_ERROR.MISSING_ASSIGNABLE_SELECTOR
// ^
// [cfe] Can't assign to a parenthesized expression.
(variable)++;
// ^
// [cfe] Can't assign to a parenthesized expression.
// ^^
// [analyzer] SYNTACTIC_ERROR.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE
++(variable);
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_ASSIGNABLE_SELECTOR
// [cfe] Can't assign to a parenthesized expression.
C.field = 0;
(C.field) = 0;
//^^^^^^^^^
// [analyzer] SYNTACTIC_ERROR.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE
//^^^^^^^^^
// [analyzer] SYNTACTIC_ERROR.MISSING_ASSIGNABLE_SELECTOR
// ^
// [cfe] Can't assign to a parenthesized expression.
(C.field)++;
// ^
// [cfe] Can't assign to a parenthesized expression.
// ^^
// [analyzer] SYNTACTIC_ERROR.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE
++(C.field);
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_ASSIGNABLE_SELECTOR
// [cfe] Can't assign to a parenthesized expression.
variable = [1, 2, 3];
variable[0] = 0;
(variable)[0] = 0;
(variable[0]) = 0;
//^^^^^^^^^^^^^
// [analyzer] SYNTACTIC_ERROR.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE
//^^^^^^^^^^^^^
// [analyzer] SYNTACTIC_ERROR.MISSING_ASSIGNABLE_SELECTOR
// ^
// [cfe] Can't assign to a parenthesized expression.
(variable[0])++;
// ^
// [cfe] Can't assign to a parenthesized expression.
// ^^
// [analyzer] SYNTACTIC_ERROR.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE
++(variable[0]);
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_ASSIGNABLE_SELECTOR
// [cfe] Can't assign to a parenthesized expression.
C.field = [1, 2, 3];
(C.field[0]) = 0;
//^^^^^^^^^^^^
// [analyzer] SYNTACTIC_ERROR.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE
//^^^^^^^^^^^^
// [analyzer] SYNTACTIC_ERROR.MISSING_ASSIGNABLE_SELECTOR
// ^
// [cfe] Can't assign to a parenthesized expression.
(C.field[0])++;
// ^
// [cfe] Can't assign to a parenthesized expression.
// ^^
// [analyzer] SYNTACTIC_ERROR.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE
++(C.field[0]);
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_ASSIGNABLE_SELECTOR
// [cfe] Can't assign to a parenthesized expression.
var a = 0;
(a) = 0;
//^^^
// [analyzer] SYNTACTIC_ERROR.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE
//^^^
// [analyzer] SYNTACTIC_ERROR.MISSING_ASSIGNABLE_SELECTOR
// ^
// [cfe] Can't assign to a parenthesized expression.
(a)++;
//^
// [cfe] Can't assign to a parenthesized expression.
// ^^
// [analyzer] SYNTACTIC_ERROR.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE
++(a);
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_ASSIGNABLE_SELECTOR
// [cfe] Can't assign to a parenthesized expression.
// Neat palindrome expression. x is assignable, ((x)) is not.
var funcnuf = (x) => ((x))=((x)) <= (x);
// ^^^^^
// [analyzer] SYNTACTIC_ERROR.MISSING_ASSIGNABLE_SELECTOR
// ^
// [cfe] Can't assign to a parenthesized expression.
}