mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 04:27:17 +00:00
2ac2871476
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>
29 lines
767 B
Dart
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;
|
|
}
|