member_name_alias.carbon 1.3 KB

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