Files
sdk/pkg/front_end/testcases/const_functions/const_functions_recursion.dart
Kallen Tu 45c9d8a25e [cfe] Enable recursive function calls for const functions.
Change-Id: Ia164adaf5da313cae4db2b3b326a909e57d8c07c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192200
Reviewed-by: Jake Macdonald <jakemac@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2021-03-19 17:56:17 +00:00

29 lines
611 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 recursive function calls for const functions.
import "package:expect/expect.dart";
const b = fn(4);
int fn(int a) {
if (a == 1) return 1;
return a * fn(a - 1);
}
int localTest() {
int fnLocal(int a) {
if (a == 1) return 1;
return a * fnLocal(a - 1);
}
const c = fnLocal(4);
return c;
}
void main() {
Expect.equals(b, 24);
Expect.equals(localTest(), 24);
}