recursion.carbon 892 B

12345678910111213141516171819202122232425262728
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // TODO: Extend the "int" min_prelude to support basic integer operations, so we
  6. // can use it here.
  7. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/full.carbon
  8. //
  9. // AUTOUPDATE
  10. // TIP: To test this file alone, run:
  11. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/eval/recursion.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/eval/recursion.carbon
  14. // --- recursion.carbon
  15. library "[[@TEST_NAME]]";
  16. eval fn F(n: i32) -> type {
  17. if (n == 0) {
  18. return i32;
  19. }
  20. return F(n - 1);
  21. }
  22. var i: F(3) = 0;
  23. // TODO: Diagnose infinite recursion.