mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 04:27:17 +00:00
4e2fac951d
Change-Id: Ieb8d3030c6132ccf9037e64cef3ba6c4eeaa90ea Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/197180 Reviewed-by: Jake Macdonald <jakemac@google.com> Reviewed-by: Dmitry Stefantsov <dmitryas@google.com> Commit-Queue: Kallen Tu <kallentu@google.com>
40 lines
969 B
Dart
40 lines
969 B
Dart
// Copyright (c) 2021, 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.
|
|
|
|
// Tests const constructors with a body which are enabled with const functions.
|
|
|
|
// SharedOptions=--enable-experiment=const-functions
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
const printString = "print";
|
|
const var1 = Simple(printString);
|
|
class Simple {
|
|
final String name;
|
|
|
|
const Simple(this.name) {
|
|
// ^
|
|
// [analyzer] SYNTACTIC_ERROR.CONST_CONSTRUCTOR_WITH_BODY
|
|
assert(this.name == printString);
|
|
}
|
|
}
|
|
|
|
const var2 = A();
|
|
class A {
|
|
const A() {
|
|
// ^
|
|
// [analyzer] SYNTACTIC_ERROR.CONST_CONSTRUCTOR_WITH_BODY
|
|
return;
|
|
}
|
|
}
|
|
|
|
const var3 = fn();
|
|
// ^^^^
|
|
// [analyzer] COMPILE_TIME_ERROR.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE
|
|
A fn() => A();
|
|
|
|
void main() {
|
|
Expect.equals(var1.name, printString);
|
|
}
|