dart-sdk/tests/language/external_abstract_fields/external_fields_syntax_error_test.dart
Erik Ernst f4d7951a88 For external/abstract fields: add tests and update Dart.g
This CL adds tests in language/external_abstract_fields, testing the
support for abstract instance variables, and for external top-level,
class, and instance variables. It is tested that the syntax of
supported declarations is accepted, and a number of non-supported
forms are rejected, and abstract fields are tested at run time as well.

The implementation of external fields is provided by an implementation
specific mechanism, and no tests are added for any such mechanisms
(that is, with external fields we only test errors).

This CL also updates the spec grammar Dart.g to include grammar
rules for the new kinds of declarations, and it has been verified that
the new tests are passing, respectively cause syntax errors, as
indicated in the test files.

The tests are a further development of the ones in
https://dart-review.googlesource.com/c/sdk/+/145862.

Change-Id: I13be746a05d5acf0117d8cb22151bd9863a71a78
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/148324
Commit-Queue: Erik Ernst <eernst@google.com>
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
2020-07-02 13:39:39 +00:00

84 lines
2.8 KiB
Dart

// Copyright (c) 2020, 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.
// Check that external variable declarations do not allow more
// than they should.
// Checks that only the syntactically correct declarations are allowed.
// External variables must not have initializers.
external var topInit = 0; //# 1: syntax error
// External variables must not be const.
external const topConst; //# 2: syntax error
// External variables must not have be late.
external late var topLate; //# 3: syntax error
// External variables must not have be abstract
// (and top-level declaration must not be abstract).
external abstract var topAbstract1; //# 4: syntax error
abstract external var topAbstract2; //# 5: syntax error
class StaticMembers {
// External static fields cannot have initializers.
external static int init1 = 0; //# 6: syntax error
// External static fields cannot be late.
external static late int late1; //# 7: syntax error
// External static fields cannot be late and final.
external static late final int late2; //# 8: syntax error
// External static fields cannot be const.
external static const int const1; //# 9: syntax error
external static const int const1 = 0; //# 10: syntax error
// External static fields cannot be final and covariant.
external static covariant final int covariant1; //# 11: syntax error
external static final covariant int covariant2; //# 12: syntax error
// External static fields cannot be abstract.
external static abstract int abstract1; //# 13: syntax error
}
class InstanceMembers {
// External fields cannot have initializers.
external int init1 = 0; //# 14: syntax error
// External fields cannot be late.
external late int late1; //# 15: syntax error
// External fields cannot be late and final.
external late final int late2; //# 16: syntax error
// External fields cannot be const.
external const int const1; //# 17: syntax error
// External fields cannot be final and covariant.
external covariant final int covariant1; //# 18: syntax error
external final covariant int covariant2; //# 19: syntax error
// External fields cannot be abstract.
external abstract int abstract1; //# 20: syntax error
abstract external int abstract2; //# 21: syntax error
}
void main() {
// No external local variables
external var x; //# 22: syntax error
// Ensure that the declarations are in use.
List _ = [
StaticMembers.init1, //# 6: continued
StaticMembers.late1, //# 7: continued
StaticMembers.late2, //# 8: continued
StaticMembers.const1, //# 9: continued
StaticMembers.covariant1, //# 10: continued
StaticMembers.covariant2, //# 11: continued
StaticMembers.abstract1, //# 12: continued
InstanceMembers(),
];
}