self_in_class.carbon 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. interface DefaultConstructible {
  7. fn Make() -> Self;
  8. }
  9. class A {
  10. impl i32 as DefaultConstructible {
  11. // `Self` here refers to `i32`, not `A`.
  12. // TODO: Revisit this once #3714 is resolved.
  13. fn Make() -> Self { return 0; }
  14. }
  15. }
  16. // CHECK:STDOUT: --- self_in_class.carbon
  17. // CHECK:STDOUT:
  18. // CHECK:STDOUT: constants {
  19. // CHECK:STDOUT: %.1: type = interface_type @DefaultConstructible [template]
  20. // CHECK:STDOUT: %.2: type = assoc_entity_type @DefaultConstructible, <function> [template]
  21. // CHECK:STDOUT: %.3: <associated <function> in DefaultConstructible> = assoc_entity element0, @DefaultConstructible.%Make [template]
  22. // CHECK:STDOUT: %A: type = class_type @A [template]
  23. // CHECK:STDOUT: %.4: i32 = int_literal 0 [template]
  24. // CHECK:STDOUT: %.5: <witness> = interface_witness (@impl.%Make) [template]
  25. // CHECK:STDOUT: %.6: type = struct_type {} [template]
  26. // CHECK:STDOUT: }
  27. // CHECK:STDOUT:
  28. // CHECK:STDOUT: file {
  29. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  30. // CHECK:STDOUT: .DefaultConstructible = %DefaultConstructible.decl
  31. // CHECK:STDOUT: .A = %A.decl
  32. // CHECK:STDOUT: }
  33. // CHECK:STDOUT: %DefaultConstructible.decl: type = interface_decl @DefaultConstructible [template = constants.%.1] {}
  34. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {}
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: interface @DefaultConstructible {
  38. // CHECK:STDOUT: %Self: DefaultConstructible = bind_symbolic_name Self [symbolic]
  39. // CHECK:STDOUT: %Make: <function> = fn_decl @Make.1 [template] {
  40. // CHECK:STDOUT: %Self.ref: DefaultConstructible = name_ref Self, %Self [symbolic = %Self]
  41. // CHECK:STDOUT: %.loc8_16.1: type = facet_type_access %Self.ref [symbolic = %Self]
  42. // CHECK:STDOUT: %.loc8_16.2: type = converted %Self.ref, %.loc8_16.1 [symbolic = %Self]
  43. // CHECK:STDOUT: %return.var: ref Self = var <return slot>
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT: %.loc8_20: <associated <function> in DefaultConstructible> = assoc_entity element0, %Make [template = constants.%.3]
  46. // CHECK:STDOUT:
  47. // CHECK:STDOUT: !members:
  48. // CHECK:STDOUT: .Self = %Self
  49. // CHECK:STDOUT: .Make = %.loc8_20
  50. // CHECK:STDOUT: witness = (%Make)
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: impl @impl: i32 as DefaultConstructible {
  54. // CHECK:STDOUT: %Make: <function> = fn_decl @Make.2 [template] {
  55. // CHECK:STDOUT: %Self.ref: type = name_ref Self, i32 [template = i32]
  56. // CHECK:STDOUT: %return.var: ref i32 = var <return slot>
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT: %.1: <witness> = interface_witness (%Make) [template = constants.%.5]
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: !members:
  61. // CHECK:STDOUT: .Make = %Make
  62. // CHECK:STDOUT: witness = %.1
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: class @A {
  66. // CHECK:STDOUT: impl_decl @impl {
  67. // CHECK:STDOUT: %DefaultConstructible.ref: type = name_ref DefaultConstructible, file.%DefaultConstructible.decl [template = constants.%.1]
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: !members:
  71. // CHECK:STDOUT: .Self = constants.%A
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: fn @Make.1() -> Self;
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: fn @Make.2() -> i32 {
  77. // CHECK:STDOUT: !entry:
  78. // CHECK:STDOUT: %.loc15: i32 = int_literal 0 [template = constants.%.4]
  79. // CHECK:STDOUT: return %.loc15
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT: