member_name_alias.carbon 1.6 KB

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