nested_method.carbon 710 B

1234567891011121314151617181920212223242526272829303132333435
  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. // RUN: %{explorer} %s | %{FileCheck-strict} %s
  6. // RUN: %{explorer-trace} %s | %{FileCheck-allow-unmatched} %s
  7. // AUTOUPDATE: %{explorer} %s
  8. // CHECK:STDOUT: result: 0
  9. package ExplorerTest api;
  10. class B {
  11. var x: i32;
  12. fn GetSetX[addr me: Self*](x: i32) -> i32 {
  13. var oldX: auto = (*me).x;
  14. (*me).x = x;
  15. return oldX;
  16. }
  17. }
  18. class A {
  19. var b: B;
  20. }
  21. fn Main() -> i32 {
  22. var b: B = {.x = 0};
  23. var a: A = {.b = b};
  24. var x: auto = a.b.GetSetX(42);
  25. if (a.b.x == 42) {
  26. return x;
  27. }
  28. return 1;
  29. }