default_fn.carbon 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 %.1, %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: <witness> = complete_type_witness %.6 [template]
  39. // CHECK:STDOUT: %.8: type = ptr_type %.6 [template]
  40. // CHECK:STDOUT: %struct: %C = struct_value () [template]
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT:
  43. // CHECK:STDOUT: file {
  44. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  45. // CHECK:STDOUT: .C = %C.decl
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT:
  50. // CHECK:STDOUT: interface @I {
  51. // CHECK:STDOUT: %Self: %.1 = bind_symbolic_name Self 0 [symbolic = constants.%Self]
  52. // CHECK:STDOUT: %F.decl: %F.type.1 = fn_decl @F.1 [template = constants.%F.1] {} {}
  53. // CHECK:STDOUT: %.loc14: %.3 = assoc_entity element0, %F.decl [template = constants.%.4]
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: !members:
  56. // CHECK:STDOUT: .Self = %Self
  57. // CHECK:STDOUT: .F = %.loc14
  58. // CHECK:STDOUT: witness = (%F.decl)
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT:
  61. // CHECK:STDOUT: impl @impl: %C as %.1 {
  62. // CHECK:STDOUT: %F.decl: %F.type.2 = fn_decl @F.2 [template = constants.%F.2] {} {}
  63. // CHECK:STDOUT: %.loc21: <witness> = interface_witness (%F.decl) [template = constants.%.5]
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: !members:
  66. // CHECK:STDOUT: .F = %F.decl
  67. // CHECK:STDOUT: witness = %.loc21
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: class @C {
  71. // CHECK:STDOUT: %I.decl: type = interface_decl @I [template = constants.%.1] {} {}
  72. // CHECK:STDOUT: impl_decl @impl {} {
  73. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  74. // CHECK:STDOUT: %I.ref: type = name_ref I, @C.%I.decl [template = constants.%.1]
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT: %.loc24: <witness> = complete_type_witness %.6 [template = constants.%.7]
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: !members:
  79. // CHECK:STDOUT: .Self = constants.%C
  80. // CHECK:STDOUT: .I = %I.decl
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: generic fn @F.1(@I.%Self: %.1) {
  84. // CHECK:STDOUT: !definition:
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: fn() {
  87. // CHECK:STDOUT: !entry:
  88. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  89. // CHECK:STDOUT: %c.var: ref %C = var c
  90. // CHECK:STDOUT: %c: ref %C = bind_name c, %c.var
  91. // CHECK:STDOUT: %.loc16_19.1: %.6 = struct_literal ()
  92. // CHECK:STDOUT: %.loc16_19.2: init %C = class_init (), %c.var [template = constants.%struct]
  93. // CHECK:STDOUT: %.loc16_20: init %C = converted %.loc16_19.1, %.loc16_19.2 [template = constants.%struct]
  94. // CHECK:STDOUT: assign %c.var, %.loc16_20
  95. // CHECK:STDOUT: %c.ref: ref %C = name_ref c, %c
  96. // CHECK:STDOUT: %I.ref: type = name_ref I, @C.%I.decl [template = constants.%.1]
  97. // CHECK:STDOUT: %F.ref: %.3 = name_ref F, @I.%.loc14 [template = constants.%.4]
  98. // CHECK:STDOUT: %.loc17: %F.type.1 = interface_witness_access @impl.%.loc21, element0 [template = constants.%F.2]
  99. // CHECK:STDOUT: %F.call: init %.2 = call %.loc17()
  100. // CHECK:STDOUT: return
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT:
  104. // CHECK:STDOUT: fn @F.2() {
  105. // CHECK:STDOUT: !entry:
  106. // CHECK:STDOUT: return
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: specific @F.1(constants.%Self) {}
  110. // CHECK:STDOUT:
  111. // CHECK:STDOUT: specific @F.1(constants.%C) {}
  112. // CHECK:STDOUT: