dart-sdk/tests/language/const_functions/const_functions_const_ctor_disabled_test.dart
Kallen Tu c86af3c39b [analyzer] Refactor visitMethodInvocation in the const evaluator.
Change-Id: I9ae6c17967c98770ed06dead200c8bd87ae7f2a9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309829
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-06-30 18:32:27 +00:00

24 lines
746 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 are disabled without const functions.
import "package:expect/expect.dart";
const printString = "print";
const var1 = Simple(printString);
// ^
// [cfe] Cannot invoke a non-'const' constructor where a const expression is expected.
class Simple {
final String name;
const Simple(this.name) {
//^
// [cfe] A const constructor can't have a body.
// ^
// [analyzer] SYNTACTIC_ERROR.CONST_CONSTRUCTOR_WITH_BODY
assert(this.name == printString);
}
}