6f90c5531e
Change-Id: If844a28192c1eef4dcbb62075ae07e86297f2c92 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193920 Reviewed-by: Dmitry Stefantsov <dmitryas@google.com> Reviewed-by: Bob Nystrom <rnystrom@google.com> Reviewed-by: Jake Macdonald <jakemac@google.com> Commit-Queue: Kallen Tu <kallentu@google.com>
36 lines
818 B
Dart
36 lines
818 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 assert statements with const functions.
|
|
|
|
// SharedOptions=--enable-experiment=const-functions
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
const var1 = fn();
|
|
// ^^^^
|
|
// [analyzer] COMPILE_TIME_ERROR.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE
|
|
int fn() {
|
|
int x = 0;
|
|
assert(x == 0, "fail");
|
|
return x;
|
|
}
|
|
|
|
const var2 = fn2();
|
|
// ^^^^^
|
|
// [analyzer] COMPILE_TIME_ERROR.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE
|
|
int fn2() {
|
|
int x = 0;
|
|
assert(() {
|
|
var y = x + 1;
|
|
return y == 1;
|
|
}());
|
|
return x;
|
|
}
|
|
|
|
void main() {
|
|
Expect.equals(var1, 0);
|
|
Expect.equals(var2, 0);
|
|
}
|