self_in_class.carbon 4.7 KB

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