dart-sdk/tests/language/unsorted/assignable_expression_test.dart
Robert Nystrom 91ef5b252b [flip-patterns] Update invalid assignable expression test expectations.
With pattern assignment, the error messages are now different in 2.19
libraries since a parenthesized expression looks like you might be
trying to do a pattern assignment.

Change-Id: I00105ea4cb5dbe8c8b328fb2e665200f3dc33722
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/286870
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Jake Macdonald <jakemac@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
2023-03-06 21:57:51 +00:00

127 lines
4.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.
//
// @dart=2.19
// SharedOptions=--enable-experiment=patterns,records
// Enable the experiments even though the test itself is pinned to 2.19 since
// the error messages relate to patterns.
// 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] The 'patterns' language feature is disabled for this library.
// ^
// [cfe] Only local variables or formal parameters can be used in pattern assignments.
// [cfe] The 'patterns' language feature is disabled for this library.
(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] The 'patterns' language feature is disabled for this library.
// ^
// [cfe] Refutable patterns can't be used in an irrefutable context.
(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] The 'patterns' language feature is disabled for this library.
// ^
// [cfe] Only local variables or formal parameters can be used in pattern assignments.
// [cfe] The 'patterns' language feature is disabled for this library.
// ^
// [cfe] Expected ')' before this.
(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] The 'patterns' language feature is disabled for this library.
// ^
// [cfe] Refutable patterns can't be used in an irrefutable context.
(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] The 'patterns' language feature is disabled for this library.
// ^
// [cfe] The 'patterns' language feature is disabled for this library.
(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] The 'patterns' language feature is disabled for this library.
// ^
// [cfe] The 'patterns' language feature is disabled for this library.
// ^
// [cfe] The 'patterns' language feature is disabled for this library.
}