member_name_alias.carbon 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. // CHECK:STDOUT: result: 0
  7. package ExplorerTest api;
  8. interface I {
  9. fn F() -> i32;
  10. fn M[self: Self]() -> i32;
  11. }
  12. class A {
  13. var n: i32;
  14. impl as I {
  15. fn F() -> i32 { return 1; }
  16. fn M[self: Self]() -> i32 { return 2; }
  17. }
  18. fn G[self: Self]() -> i32 { return 3; }
  19. }
  20. impl i32 as I {
  21. fn F() -> i32 { return 4; }
  22. fn M[self: Self]() -> i32 { return 5; }
  23. }
  24. alias IF = I.F;
  25. alias IM = I.M;
  26. alias AIF = A.(IF);
  27. alias AIM = A.(IM);
  28. alias AG = A.G;
  29. alias i32IF = i32.(IF);
  30. alias i32IM = i32.(IM);
  31. fn Main() -> i32 {
  32. var a: A = {.n = 0};
  33. if (A.(IF)() != 1) {
  34. return 1;
  35. }
  36. if (a.(IF)() != 1) {
  37. return 2;
  38. }
  39. if (a.(IM)() != 2) {
  40. return 3;
  41. }
  42. if (a.(A.(IM))() != 2) {
  43. return 4;
  44. }
  45. if (AIF() != 1) {
  46. return 5;
  47. }
  48. if (a.(AIM)() != 2) {
  49. return 6;
  50. }
  51. if (a.(AG)() != 3) {
  52. return 7;
  53. }
  54. if (i32.(IF)() != 4) {
  55. return 8;
  56. }
  57. if (0.(IF)() != 4) {
  58. return 9;
  59. }
  60. if (0.(IM)() != 5) {
  61. return 10;
  62. }
  63. if (0.(i32.(IM))() != 5) {
  64. return 11;
  65. }
  66. if (i32IF() != 4) {
  67. return 12;
  68. }
  69. if (0.(i32IM)() != 5) {
  70. return 13;
  71. }
  72. return 0;
  73. }