self_in_class.carbon 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/impl/no_prelude/self_in_class.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/no_prelude/self_in_class.carbon
  10. interface DefaultConstructible {
  11. fn Make() -> Self;
  12. }
  13. class C {}
  14. class A {
  15. impl C as DefaultConstructible {
  16. // `Self` here refers to `C`, not `A`.
  17. // TODO: Revisit this once #3714 is resolved.
  18. fn Make() -> Self { return {}; }
  19. }
  20. }
  21. // CHECK:STDOUT: --- self_in_class.carbon
  22. // CHECK:STDOUT:
  23. // CHECK:STDOUT: constants {
  24. // CHECK:STDOUT: %DefaultConstructible.type: type = facet_type <@DefaultConstructible> [concrete]
  25. // CHECK:STDOUT: %Self: %DefaultConstructible.type = bind_symbolic_name Self, 0 [symbolic]
  26. // CHECK:STDOUT: %Self.as_type: type = facet_access_type %Self [symbolic]
  27. // CHECK:STDOUT: %pattern_type.839: type = pattern_type %Self.as_type [symbolic]
  28. // CHECK:STDOUT: %Make.type.068: type = fn_type @Make.1 [concrete]
  29. // CHECK:STDOUT: %Make.606: %Make.type.068 = struct_value () [concrete]
  30. // CHECK:STDOUT: %DefaultConstructible.assoc_type: type = assoc_entity_type @DefaultConstructible [concrete]
  31. // CHECK:STDOUT: %assoc0: %DefaultConstructible.assoc_type = assoc_entity element0, @DefaultConstructible.%Make.decl [concrete]
  32. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  33. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  34. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  35. // CHECK:STDOUT: %A: type = class_type @A [concrete]
  36. // CHECK:STDOUT: %DefaultConstructible.impl_witness: <witness> = impl_witness @A.%DefaultConstructible.impl_witness_table [concrete]
  37. // CHECK:STDOUT: %pattern_type.c48: type = pattern_type %C [concrete]
  38. // CHECK:STDOUT: %Make.type.351: type = fn_type @Make.2 [concrete]
  39. // CHECK:STDOUT: %Make.b73: %Make.type.351 = struct_value () [concrete]
  40. // CHECK:STDOUT: %DefaultConstructible.facet: %DefaultConstructible.type = facet_value %C, (%DefaultConstructible.impl_witness) [concrete]
  41. // CHECK:STDOUT: %C.val: %C = struct_value () [concrete]
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: file {
  45. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  46. // CHECK:STDOUT: .DefaultConstructible = %DefaultConstructible.decl
  47. // CHECK:STDOUT: .C = %C.decl
  48. // CHECK:STDOUT: .A = %A.decl
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT: %DefaultConstructible.decl: type = interface_decl @DefaultConstructible [concrete = constants.%DefaultConstructible.type] {} {}
  51. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  52. // CHECK:STDOUT: %A.decl: type = class_decl @A [concrete = constants.%A] {} {}
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: interface @DefaultConstructible {
  56. // CHECK:STDOUT: %Self: %DefaultConstructible.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
  57. // CHECK:STDOUT: %Make.decl: %Make.type.068 = fn_decl @Make.1 [concrete = constants.%Make.606] {
  58. // CHECK:STDOUT: %return.patt: @Make.1.%pattern_type (%pattern_type.839) = return_slot_pattern [concrete]
  59. // CHECK:STDOUT: %return.param_patt: @Make.1.%pattern_type (%pattern_type.839) = out_param_pattern %return.patt, call_param0 [concrete]
  60. // CHECK:STDOUT: } {
  61. // CHECK:STDOUT: %Self.ref: %DefaultConstructible.type = name_ref Self, @DefaultConstructible.%Self [symbolic = %Self (constants.%Self)]
  62. // CHECK:STDOUT: %Self.as_type.loc12_16.2: type = facet_access_type %Self.ref [symbolic = %Self.as_type.loc12_16.1 (constants.%Self.as_type)]
  63. // CHECK:STDOUT: %.loc12: type = converted %Self.ref, %Self.as_type.loc12_16.2 [symbolic = %Self.as_type.loc12_16.1 (constants.%Self.as_type)]
  64. // CHECK:STDOUT: %return.param: ref @Make.1.%Self.as_type.loc12_16.1 (%Self.as_type) = out_param call_param0
  65. // CHECK:STDOUT: %return: ref @Make.1.%Self.as_type.loc12_16.1 (%Self.as_type) = return_slot %return.param
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT: %assoc0: %DefaultConstructible.assoc_type = assoc_entity element0, %Make.decl [concrete = constants.%assoc0]
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: !members:
  70. // CHECK:STDOUT: .Self = %Self
  71. // CHECK:STDOUT: .Make = %assoc0
  72. // CHECK:STDOUT: witness = (%Make.decl)
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: impl @impl: %C.ref as %DefaultConstructible.ref {
  76. // CHECK:STDOUT: %Make.decl: %Make.type.351 = fn_decl @Make.2 [concrete = constants.%Make.b73] {
  77. // CHECK:STDOUT: %return.patt: %pattern_type.c48 = return_slot_pattern [concrete]
  78. // CHECK:STDOUT: %return.param_patt: %pattern_type.c48 = out_param_pattern %return.patt, call_param0 [concrete]
  79. // CHECK:STDOUT: } {
  80. // CHECK:STDOUT: %Self.ref: type = name_ref Self, @impl.%C.ref [concrete = constants.%C]
  81. // CHECK:STDOUT: %return.param: ref %C = out_param call_param0
  82. // CHECK:STDOUT: %return: ref %C = return_slot %return.param
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: !members:
  86. // CHECK:STDOUT: .Make = %Make.decl
  87. // CHECK:STDOUT: witness = @A.%DefaultConstructible.impl_witness
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: class @C {
  91. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  92. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
  93. // CHECK:STDOUT: complete_type_witness = %complete_type
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: !members:
  96. // CHECK:STDOUT: .Self = constants.%C
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: class @A {
  100. // CHECK:STDOUT: impl_decl @impl [concrete] {} {
  101. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  102. // CHECK:STDOUT: %DefaultConstructible.ref: type = name_ref DefaultConstructible, file.%DefaultConstructible.decl [concrete = constants.%DefaultConstructible.type]
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT: %DefaultConstructible.impl_witness_table = impl_witness_table (@impl.%Make.decl), @impl [concrete]
  105. // CHECK:STDOUT: %DefaultConstructible.impl_witness: <witness> = impl_witness %DefaultConstructible.impl_witness_table [concrete = constants.%DefaultConstructible.impl_witness]
  106. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  107. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
  108. // CHECK:STDOUT: complete_type_witness = %complete_type
  109. // CHECK:STDOUT:
  110. // CHECK:STDOUT: !members:
  111. // CHECK:STDOUT: .Self = constants.%A
  112. // CHECK:STDOUT: .C = <poisoned>
  113. // CHECK:STDOUT: .DefaultConstructible = <poisoned>
  114. // CHECK:STDOUT: }
  115. // CHECK:STDOUT:
  116. // CHECK:STDOUT: generic fn @Make.1(@DefaultConstructible.%Self: %DefaultConstructible.type) {
  117. // CHECK:STDOUT: %Self: %DefaultConstructible.type = bind_symbolic_name Self, 0 [symbolic = %Self (constants.%Self)]
  118. // CHECK:STDOUT: %Self.as_type.loc12_16.1: type = facet_access_type %Self [symbolic = %Self.as_type.loc12_16.1 (constants.%Self.as_type)]
  119. // CHECK:STDOUT: %pattern_type: type = pattern_type %Self.as_type.loc12_16.1 [symbolic = %pattern_type (constants.%pattern_type.839)]
  120. // CHECK:STDOUT:
  121. // CHECK:STDOUT: fn() -> @Make.1.%Self.as_type.loc12_16.1 (%Self.as_type);
  122. // CHECK:STDOUT: }
  123. // CHECK:STDOUT:
  124. // CHECK:STDOUT: fn @Make.2() -> %return.param: %C {
  125. // CHECK:STDOUT: !entry:
  126. // CHECK:STDOUT: %.loc21_33.1: %empty_struct_type = struct_literal ()
  127. // CHECK:STDOUT: %.loc21_33.2: init %C = class_init (), %return [concrete = constants.%C.val]
  128. // CHECK:STDOUT: %.loc21_34: init %C = converted %.loc21_33.1, %.loc21_33.2 [concrete = constants.%C.val]
  129. // CHECK:STDOUT: return %.loc21_34 to %return
  130. // CHECK:STDOUT: }
  131. // CHECK:STDOUT:
  132. // CHECK:STDOUT: specific @Make.1(constants.%Self) {
  133. // CHECK:STDOUT: %Self => constants.%Self
  134. // CHECK:STDOUT: %Self.as_type.loc12_16.1 => constants.%Self.as_type
  135. // CHECK:STDOUT: %pattern_type => constants.%pattern_type.839
  136. // CHECK:STDOUT: }
  137. // CHECK:STDOUT:
  138. // CHECK:STDOUT: specific @Make.1(constants.%DefaultConstructible.facet) {
  139. // CHECK:STDOUT: %Self => constants.%DefaultConstructible.facet
  140. // CHECK:STDOUT: %Self.as_type.loc12_16.1 => constants.%C
  141. // CHECK:STDOUT: %pattern_type => constants.%pattern_type.c48
  142. // CHECK:STDOUT: }
  143. // CHECK:STDOUT: