member_name_alias.carbon 1.5 KB

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