mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 04:27:17 +00:00
21cc667dca
This adds support for having a final field and an external constructor without error, assuming that the external constructor initializes the final field. This supports the inline class with external members use case. Change-Id: I33b78275e967636ed0697d17f7921e9eee30401b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279095 Reviewed-by: Srujan Gaddam <srujzs@google.com> Commit-Queue: Johnni Winther <johnniwinther@google.com> Reviewed-by: Jens Johansen <jensj@google.com>
101 lines
3.3 KiB
Dart
101 lines
3.3 KiB
Dart
// Copyright (c) 2012, 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.
|
|
|
|
class Bar {
|
|
Bar(val);
|
|
}
|
|
|
|
class Foo {
|
|
// ^
|
|
// [cfe] The non-abstract class 'Foo' is missing implementations for these members:
|
|
var x = -1;
|
|
f() {}
|
|
|
|
Foo() : x = 0;
|
|
//^^^
|
|
// [analyzer] COMPILE_TIME_ERROR.NOT_INITIALIZED_NON_NULLABLE_INSTANCE_FIELD
|
|
// [cfe] This constructor should initialize field 'external' because its type 'int' doesn't allow null.
|
|
|
|
external var x01;
|
|
external int x02;
|
|
|
|
external f11() { }
|
|
// ^
|
|
// [analyzer] SYNTACTIC_ERROR.EXTERNAL_METHOD_WITH_BODY
|
|
// [cfe] An external or native method can't have a body.
|
|
external f12() => 1;
|
|
// ^^
|
|
// [analyzer] SYNTACTIC_ERROR.EXTERNAL_METHOD_WITH_BODY
|
|
// [cfe] An external or native method can't have a body.
|
|
// ^
|
|
// [cfe] An external or native method can't have a body.
|
|
static external f14();
|
|
// ^^^^^^^^
|
|
// [analyzer] SYNTACTIC_ERROR.MODIFIER_OUT_OF_ORDER
|
|
// [cfe] The modifier 'external' should be before the modifier 'static'.
|
|
int external f16();
|
|
// ^^^^^^^^
|
|
// [analyzer] SYNTACTIC_ERROR.EXPECTED_TOKEN
|
|
// [cfe] Expected ';' after this.
|
|
// ^^^^^^
|
|
// [analyzer] COMPILE_TIME_ERROR.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER
|
|
|
|
external Foo.n21(val) : x = 1;
|
|
// ^
|
|
// [analyzer] SYNTACTIC_ERROR.EXTERNAL_CONSTRUCTOR_WITH_INITIALIZER
|
|
// [cfe] An external constructor can't have any initializers.
|
|
external Foo.n22(val) { x = 1; }
|
|
// ^
|
|
// [analyzer] SYNTACTIC_ERROR.EXTERNAL_METHOD_WITH_BODY
|
|
// [cfe] An external or native method can't have a body.
|
|
external factory Foo.n23(val) => new Foo();
|
|
// ^^
|
|
// [analyzer] SYNTACTIC_ERROR.EXTERNAL_FACTORY_WITH_BODY
|
|
// [cfe] External factories can't have a body.
|
|
// ^
|
|
// [cfe] An external or native method can't have a body.
|
|
external Foo.n24(this.x);
|
|
// ^
|
|
// [cfe] An external constructor can't initialize fields.
|
|
external factory Foo.n25(val) = Bar;
|
|
// ^
|
|
// [analyzer] SYNTACTIC_ERROR.EXTERNAL_FACTORY_REDIRECTION
|
|
// [cfe] A redirecting factory can't be external.
|
|
// ^^^
|
|
// [analyzer] COMPILE_TIME_ERROR.REDIRECT_TO_INVALID_RETURN_TYPE
|
|
// [cfe] The constructor function type 'Bar Function(dynamic)' isn't a subtype of 'Foo Function(dynamic)'.
|
|
}
|
|
|
|
external int t06(int i) { return 1; }
|
|
// [error column 1, length 8]
|
|
// [analyzer] SYNTACTIC_ERROR.EXTERNAL_METHOD_WITH_BODY
|
|
// [cfe] An external or native method can't have a body.
|
|
// ^
|
|
// [cfe] An external or native method can't have a body.
|
|
external int t07(int i) => i + 1;
|
|
// [error column 1, length 8]
|
|
// [analyzer] SYNTACTIC_ERROR.EXTERNAL_METHOD_WITH_BODY
|
|
// [cfe] An external or native method can't have a body.
|
|
// ^
|
|
// [cfe] An external or native method can't have a body.
|
|
|
|
main() {
|
|
// Ensure Foo class is compiled.
|
|
var foo = new Foo();
|
|
|
|
new Foo().f11();
|
|
new Foo().f12();
|
|
Foo.f14();
|
|
new Foo().f16();
|
|
|
|
new Foo.n21(1);
|
|
new Foo.n22(1);
|
|
new Foo.n23(1);
|
|
new Foo.n24(1);
|
|
new Foo.n25(1);
|
|
|
|
t06(1);
|
|
t07(1);
|
|
}
|