default_fn.carbon 4.4 KB

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