class_fn_body_reorder.carbon 645 B

12345678910111213141516171819202122232425
  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. // AUTOUPDATE
  6. // RUN: %{explorer-run}
  7. // RUN: %{explorer-run-trace}
  8. // CHECK:STDOUT: result: 3
  9. package ExplorerTest api;
  10. // The bodies of member functions are processed after all immediately enclosing
  11. // classes, impl declarations, and interfaces.
  12. class A {
  13. fn F[self: Self]() -> i32 {
  14. return G() + self.H();
  15. }
  16. fn G() -> i32 { return 1; }
  17. fn H[self: Self]() -> i32 { return 2; }
  18. }
  19. fn Main() -> i32 {
  20. var a: A = {};
  21. return a.F();
  22. }