mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 04:37:12 +00:00
91ef5b252b
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>
127 lines
4.4 KiB
Dart
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.
|
|
}
|