self_in_class.carbon 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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: <witness> = interface_witness (@impl.%Make) [template]
  24. // CHECK:STDOUT: %.5: type = struct_type {} [template]
  25. // CHECK:STDOUT: %.6: i32 = int_literal 0 [template]
  26. // CHECK:STDOUT: }
  27. // CHECK:STDOUT:
  28. // CHECK:STDOUT: file {
  29. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  30. // CHECK:STDOUT: .Core = %Core
  31. // CHECK:STDOUT: .DefaultConstructible = %DefaultConstructible.decl
  32. // CHECK:STDOUT: .A = %A.decl
  33. // CHECK:STDOUT: }
  34. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  35. // CHECK:STDOUT: %DefaultConstructible.decl: type = interface_decl @DefaultConstructible [template = constants.%.1] {}
  36. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {}
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT:
  39. // CHECK:STDOUT: interface @DefaultConstructible {
  40. // CHECK:STDOUT: %Self: DefaultConstructible = bind_symbolic_name Self [symbolic]
  41. // CHECK:STDOUT: %Make: <function> = fn_decl @Make.1 [template] {
  42. // CHECK:STDOUT: %Self.ref: DefaultConstructible = name_ref Self, %Self [symbolic = %Self]
  43. // CHECK:STDOUT: %.loc8_16.1: type = facet_type_access %Self.ref [symbolic = %Self]
  44. // CHECK:STDOUT: %.loc8_16.2: type = converted %Self.ref, %.loc8_16.1 [symbolic = %Self]
  45. // CHECK:STDOUT: %return.var: ref Self = var <return slot>
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT: %.loc8_20: <associated <function> in DefaultConstructible> = assoc_entity element0, %Make [template = constants.%.3]
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: !members:
  50. // CHECK:STDOUT: .Self = %Self
  51. // CHECK:STDOUT: .Make = %.loc8_20
  52. // CHECK:STDOUT: witness = (%Make)
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: impl @impl: i32 as DefaultConstructible {
  56. // CHECK:STDOUT: %Make: <function> = fn_decl @Make.2 [template] {
  57. // CHECK:STDOUT: %Self.ref: type = name_ref Self, i32 [template = i32]
  58. // CHECK:STDOUT: %return.var: ref i32 = var <return slot>
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT: %.1: <witness> = interface_witness (%Make) [template = constants.%.4]
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: !members:
  63. // CHECK:STDOUT: .Make = %Make
  64. // CHECK:STDOUT: witness = %.1
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: class @A {
  68. // CHECK:STDOUT: impl_decl @impl {
  69. // CHECK:STDOUT: %DefaultConstructible.ref: type = name_ref DefaultConstructible, file.%DefaultConstructible.decl [template = constants.%.1]
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: !members:
  73. // CHECK:STDOUT: .Self = constants.%A
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: fn @Make.1() -> Self;
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: fn @Make.2() -> i32 {
  79. // CHECK:STDOUT: !entry:
  80. // CHECK:STDOUT: %.loc15: i32 = int_literal 0 [template = constants.%.6]
  81. // CHECK:STDOUT: return %.loc15
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT: