extend_impl.carbon 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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/extend_impl.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/extend_impl.carbon
  10. interface HasF {
  11. fn F();
  12. }
  13. class C {
  14. extend impl as HasF {
  15. fn F() {}
  16. }
  17. }
  18. fn G(c: C) {
  19. C.F();
  20. c.F();
  21. }
  22. // CHECK:STDOUT: --- extend_impl.carbon
  23. // CHECK:STDOUT:
  24. // CHECK:STDOUT: constants {
  25. // CHECK:STDOUT: %.1: type = interface_type @HasF [template]
  26. // CHECK:STDOUT: %Self: %.1 = bind_symbolic_name Self 0 [symbolic]
  27. // CHECK:STDOUT: %F.type.1: type = fn_type @F.1 [template]
  28. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  29. // CHECK:STDOUT: %F.1: %F.type.1 = struct_value () [template]
  30. // CHECK:STDOUT: %.3: type = assoc_entity_type @HasF, %F.type.1 [template]
  31. // CHECK:STDOUT: %.4: %.3 = assoc_entity element0, @HasF.%F.decl [template]
  32. // CHECK:STDOUT: %C: type = class_type @C [template]
  33. // CHECK:STDOUT: %F.type.2: type = fn_type @F.2 [template]
  34. // CHECK:STDOUT: %F.2: %F.type.2 = struct_value () [template]
  35. // CHECK:STDOUT: %.5: <witness> = interface_witness (%F.2) [template]
  36. // CHECK:STDOUT: %.6: type = struct_type {} [template]
  37. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  38. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  39. // CHECK:STDOUT: %.7: type = ptr_type %.6 [template]
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: file {
  43. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  44. // CHECK:STDOUT: .Core = %Core
  45. // CHECK:STDOUT: .HasF = %HasF.decl
  46. // CHECK:STDOUT: .C = %C.decl
  47. // CHECK:STDOUT: .G = %G.decl
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  50. // CHECK:STDOUT: %HasF.decl: type = interface_decl @HasF [template = constants.%.1] {}
  51. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  52. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  53. // CHECK:STDOUT: %C.ref: type = name_ref C, %C.decl [template = constants.%C]
  54. // CHECK:STDOUT: %c.loc21_6.1: %C = param c
  55. // CHECK:STDOUT: @G.%c: %C = bind_name c, %c.loc21_6.1
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: interface @HasF {
  60. // CHECK:STDOUT: %Self: %.1 = bind_symbolic_name Self 0 [symbolic = constants.%Self]
  61. // CHECK:STDOUT: %F.decl: %F.type.1 = fn_decl @F.1 [template = constants.%F.1] {}
  62. // CHECK:STDOUT: %.loc12: %.3 = assoc_entity element0, %F.decl [template = constants.%.4]
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: !members:
  65. // CHECK:STDOUT: .Self = %Self
  66. // CHECK:STDOUT: .F = %.loc12
  67. // CHECK:STDOUT: witness = (%F.decl)
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: impl @impl: %C as %.1 {
  71. // CHECK:STDOUT: %F.decl: %F.type.2 = fn_decl @F.2 [template = constants.%F.2] {}
  72. // CHECK:STDOUT: %.1: <witness> = interface_witness (%F.decl) [template = constants.%.5]
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: !members:
  75. // CHECK:STDOUT: .F = %F.decl
  76. // CHECK:STDOUT: witness = %.1
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: class @C {
  80. // CHECK:STDOUT: impl_decl @impl {
  81. // CHECK:STDOUT: %HasF.ref: type = name_ref HasF, file.%HasF.decl [template = constants.%.1]
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: !members:
  85. // CHECK:STDOUT: .Self = constants.%C
  86. // CHECK:STDOUT: extend name_scope2
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: fn @F.1()
  90. // CHECK:STDOUT: generic [@HasF.%Self: %.1];
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: fn @F.2() {
  93. // CHECK:STDOUT: !entry:
  94. // CHECK:STDOUT: return
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: fn @G(%c: %C) {
  98. // CHECK:STDOUT: !entry:
  99. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  100. // CHECK:STDOUT: %F.ref.loc22: %.3 = name_ref F, @HasF.%.loc12 [template = constants.%.4]
  101. // CHECK:STDOUT: %.1: %F.type.1 = interface_witness_access @impl.%.1, element0 [template = constants.%F.2]
  102. // CHECK:STDOUT: %F.call.loc22: init %.2 = call %.1()
  103. // CHECK:STDOUT: %c.ref: %C = name_ref c, %c
  104. // CHECK:STDOUT: %F.ref.loc23: %.3 = name_ref F, @HasF.%.loc12 [template = constants.%.4]
  105. // CHECK:STDOUT: %.2: %F.type.1 = interface_witness_access @impl.%.1, element0 [template = constants.%F.2]
  106. // CHECK:STDOUT: %F.call.loc23: init %.2 = call %.2()
  107. // CHECK:STDOUT: return
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT: