member_access.carbon 635 B

12345678910111213141516171819202122232425262728293031
  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. package ExplorerTest api;
  7. interface GetX {
  8. fn DoIt[self: Self]() -> i32;
  9. }
  10. impl forall [template T:! type] T as GetX {
  11. fn DoIt[self: Self]() -> i32 { return self.x; }
  12. }
  13. class C {
  14. var x: i32;
  15. }
  16. fn Main() -> i32 {
  17. var a: auto = {.x = 1, .y = 2};
  18. var b: C = {.x = 3};
  19. Print("{0}", a.(GetX.DoIt)());
  20. Print("{0}", b.(GetX.DoIt)());
  21. return 0;
  22. }
  23. // CHECK:STDOUT: 1
  24. // CHECK:STDOUT: 3
  25. // CHECK:STDOUT: result: 0