dart-sdk/tests/language/const_functions/const_functions_variable_declarations_error_test.dart
Kallen Tu 2ac2871476 [cfe] NullConstant variable declaration value.
Change-Id: I6d5adea4d70d8cd34f565a729034e2636935033e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/197120
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Reviewed-by: Jake Macdonald <jakemac@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2021-04-29 15:36:15 +00:00

29 lines
767 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 erroneous variable declaration usage within const functions.
// SharedOptions=--enable-experiment=const-functions
import "package:expect/expect.dart";
const var1 = fn1();
// ^^^^^
// [analyzer] COMPILE_TIME_ERROR.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE
// [cfe] Constant evaluation error:
int fn1() {
var a;
return a;
}
const var2 = fn2();
// ^^^^^
// [analyzer] COMPILE_TIME_ERROR.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE
// [cfe] Constant evaluation error:
int fn2() {
var x;
x = "string";
return x;
}