default_fn.carbon 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. class C {
  7. interface I {
  8. // TODO: Use `default` here.
  9. fn F() {
  10. // I and F are both complete here, and the impl below is in scope.
  11. var c: C = {};
  12. c.(I.F)();
  13. }
  14. }
  15. impl C as I {
  16. fn F() {}
  17. }
  18. }
  19. // CHECK:STDOUT: --- default_fn.carbon
  20. // CHECK:STDOUT:
  21. // CHECK:STDOUT: constants {
  22. // CHECK:STDOUT: %C: type = class_type @C [template]
  23. // CHECK:STDOUT: %.1: type = interface_type @I [template]
  24. // CHECK:STDOUT: %.2: type = assoc_entity_type @I, <function> [template]
  25. // CHECK:STDOUT: %.3: <associated <function> in I> = assoc_entity element0, @I.%F [template]
  26. // CHECK:STDOUT: %.4: <witness> = interface_witness (@impl.%F) [template]
  27. // CHECK:STDOUT: %.5: type = struct_type {} [template]
  28. // CHECK:STDOUT: %.6: type = tuple_type () [template]
  29. // CHECK:STDOUT: %.7: type = ptr_type {} [template]
  30. // CHECK:STDOUT: %.8: C = struct_value () [template]
  31. // CHECK:STDOUT: }
  32. // CHECK:STDOUT:
  33. // CHECK:STDOUT: file {
  34. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  35. // CHECK:STDOUT: .Core = %Core
  36. // CHECK:STDOUT: .C = %C.decl
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  39. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: interface @I {
  43. // CHECK:STDOUT: %Self: I = bind_symbolic_name Self [symbolic]
  44. // CHECK:STDOUT: %F: <function> = fn_decl @F.1 [template] {}
  45. // CHECK:STDOUT: %.loc10: <associated <function> in I> = assoc_entity element0, %F [template = constants.%.3]
  46. // CHECK:STDOUT:
  47. // CHECK:STDOUT: !members:
  48. // CHECK:STDOUT: .Self = %Self
  49. // CHECK:STDOUT: .F = %.loc10
  50. // CHECK:STDOUT: witness = (%F)
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: impl @impl: C as I {
  54. // CHECK:STDOUT: %F: <function> = fn_decl @F.2 [template] {}
  55. // CHECK:STDOUT: %.1: <witness> = interface_witness (%F) [template = constants.%.4]
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: !members:
  58. // CHECK:STDOUT: .F = %F
  59. // CHECK:STDOUT: witness = %.1
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: class @C {
  63. // CHECK:STDOUT: %I.decl: type = interface_decl @I [template = constants.%.1] {}
  64. // CHECK:STDOUT: impl_decl @impl {
  65. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  66. // CHECK:STDOUT: %I.ref: type = name_ref I, %I.decl [template = constants.%.1]
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: !members:
  70. // CHECK:STDOUT: .Self = constants.%C
  71. // CHECK:STDOUT: .I = %I.decl
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: fn @F.1() {
  75. // CHECK:STDOUT: !entry:
  76. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  77. // CHECK:STDOUT: %c.var: ref C = var c
  78. // CHECK:STDOUT: %c: ref C = bind_name c, %c.var
  79. // CHECK:STDOUT: %.loc12_19.1: {} = struct_literal ()
  80. // CHECK:STDOUT: %.loc12_19.2: init C = class_init (), %c.var [template = constants.%.8]
  81. // CHECK:STDOUT: %.loc12_20: init C = converted %.loc12_19.1, %.loc12_19.2 [template = constants.%.8]
  82. // CHECK:STDOUT: assign %c.var, %.loc12_20
  83. // CHECK:STDOUT: %c.ref: ref C = name_ref c, %c
  84. // CHECK:STDOUT: %I.ref: type = name_ref I, @C.%I.decl [template = constants.%.1]
  85. // CHECK:STDOUT: %F.ref: <associated <function> in I> = name_ref F, @I.%.loc10 [template = constants.%.3]
  86. // CHECK:STDOUT: %.1: <function> = interface_witness_access @impl.%.1, element0 [template = @impl.%F]
  87. // CHECK:STDOUT: %F.call: init () = call %.1()
  88. // CHECK:STDOUT: return
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: fn @F.2() {
  92. // CHECK:STDOUT: !entry:
  93. // CHECK:STDOUT: return
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT: