todo_define_not_default.carbon 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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/todo_define_not_default.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interface/todo_define_not_default.carbon
  10. interface I {
  11. // TODO: A definition without `default` in an interface should be rejected.
  12. fn F() {}
  13. fn G(a: i32, b: i32) -> i32 = "int.sadd";
  14. // TODO: An associated constant with an initializer without `default` in an
  15. // interface should be rejected.
  16. let T:! type = (i32, i32);
  17. let N:! i32 = 42;
  18. }
  19. // CHECK:STDOUT: --- todo_define_not_default.carbon
  20. // CHECK:STDOUT:
  21. // CHECK:STDOUT: constants {
  22. // CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
  23. // CHECK:STDOUT: %Self.826: %I.type = bind_symbolic_name Self, 0 [symbolic]
  24. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  25. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  26. // CHECK:STDOUT: %I.assoc_type: type = assoc_entity_type @I [concrete]
  27. // CHECK:STDOUT: %assoc0.82e: %I.assoc_type = assoc_entity element0, @I.%F.decl [concrete]
  28. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  29. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  30. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  31. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  32. // CHECK:STDOUT: %assoc1: %I.assoc_type = assoc_entity element1, @I.%G.decl [concrete]
  33. // CHECK:STDOUT: %assoc2: %I.assoc_type = assoc_entity element2, @I.%T [concrete]
  34. // CHECK:STDOUT: %tuple.type.24b: type = tuple_type (type, type) [concrete]
  35. // CHECK:STDOUT: %tuple.type.d07: type = tuple_type (%i32, %i32) [concrete]
  36. // CHECK:STDOUT: %assoc3: %I.assoc_type = assoc_entity element3, @I.%N [concrete]
  37. // CHECK:STDOUT: %int_42.20e: Core.IntLiteral = int_value 42 [concrete]
  38. // CHECK:STDOUT: %ImplicitAs.type.205: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [concrete]
  39. // CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [concrete]
  40. // CHECK:STDOUT: %impl_witness.d39: <witness> = impl_witness (imports.%Core.import_ref.a5b), @impl.4f9(%int_32) [concrete]
  41. // CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @impl.4f9(%int_32) [concrete]
  42. // CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [concrete]
  43. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.205 = facet_value Core.IntLiteral, (%impl_witness.d39) [concrete]
  44. // CHECK:STDOUT: %.be7: type = fn_type_with_self_type %Convert.type.1b6, %ImplicitAs.facet [concrete]
  45. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_42.20e, %Convert.956 [concrete]
  46. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.956, @Convert.2(%int_32) [concrete]
  47. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %int_42.20e, %Convert.specific_fn [concrete]
  48. // CHECK:STDOUT: %int_42.c68: %i32 = int_value 42 [concrete]
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: imports {
  52. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  53. // CHECK:STDOUT: .Int = %Core.Int
  54. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  55. // CHECK:STDOUT: import Core//prelude
  56. // CHECK:STDOUT: import Core//prelude/...
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: file {
  61. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  62. // CHECK:STDOUT: .Core = imports.%Core
  63. // CHECK:STDOUT: .I = %I.decl
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT: %Core.import = import Core
  66. // CHECK:STDOUT: %I.decl: type = interface_decl @I [concrete = constants.%I.type] {} {}
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: interface @I {
  70. // CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self.826]
  71. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
  72. // CHECK:STDOUT: %assoc0: %I.assoc_type = assoc_entity element0, %F.decl [concrete = constants.%assoc0.82e]
  73. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {
  74. // CHECK:STDOUT: %a.patt: %i32 = binding_pattern a
  75. // CHECK:STDOUT: %a.param_patt: %i32 = value_param_pattern %a.patt, call_param0
  76. // CHECK:STDOUT: %b.patt: %i32 = binding_pattern b
  77. // CHECK:STDOUT: %b.param_patt: %i32 = value_param_pattern %b.patt, call_param1
  78. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  79. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, call_param2
  80. // CHECK:STDOUT: } {
  81. // CHECK:STDOUT: %int_32.loc14_27: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  82. // CHECK:STDOUT: %i32.loc14_27: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  83. // CHECK:STDOUT: %a.param: %i32 = value_param call_param0
  84. // CHECK:STDOUT: %.loc14_11: type = splice_block %i32.loc14_11 [concrete = constants.%i32] {
  85. // CHECK:STDOUT: %int_32.loc14_11: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  86. // CHECK:STDOUT: %i32.loc14_11: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT: %a: %i32 = bind_name a, %a.param
  89. // CHECK:STDOUT: %b.param: %i32 = value_param call_param1
  90. // CHECK:STDOUT: %.loc14_19: type = splice_block %i32.loc14_19 [concrete = constants.%i32] {
  91. // CHECK:STDOUT: %int_32.loc14_19: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  92. // CHECK:STDOUT: %i32.loc14_19: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT: %b: %i32 = bind_name b, %b.param
  95. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param2
  96. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT: %assoc1: %I.assoc_type = assoc_entity element1, %G.decl [concrete = constants.%assoc1]
  99. // CHECK:STDOUT: %T: type = assoc_const_decl @T [concrete] {
  100. // CHECK:STDOUT: %assoc2: %I.assoc_type = assoc_entity element2, @I.%T [concrete = constants.%assoc2]
  101. // CHECK:STDOUT: %int_32.loc18_19: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  102. // CHECK:STDOUT: %i32.loc18_19: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  103. // CHECK:STDOUT: %int_32.loc18_24: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  104. // CHECK:STDOUT: %i32.loc18_24: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  105. // CHECK:STDOUT: %.loc18_27: %tuple.type.24b = tuple_literal (%i32.loc18_19, %i32.loc18_24)
  106. // CHECK:STDOUT: %.loc18_28: type = converted %.loc18_27, constants.%tuple.type.d07 [concrete = constants.%tuple.type.d07]
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT: %N: %i32 = assoc_const_decl @N [concrete] {
  109. // CHECK:STDOUT: %assoc3: %I.assoc_type = assoc_entity element3, @I.%N [concrete = constants.%assoc3]
  110. // CHECK:STDOUT: %int_42: Core.IntLiteral = int_value 42 [concrete = constants.%int_42.20e]
  111. // CHECK:STDOUT: %impl.elem0: %.be7 = impl_witness_access constants.%impl_witness.d39, element0 [concrete = constants.%Convert.956]
  112. // CHECK:STDOUT: %bound_method.loc19_19.1: <bound method> = bound_method %int_42, %impl.elem0 [concrete = constants.%Convert.bound]
  113. // CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn]
  114. // CHECK:STDOUT: %bound_method.loc19_19.2: <bound method> = bound_method %int_42, %specific_fn [concrete = constants.%bound_method]
  115. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %bound_method.loc19_19.2(%int_42) [concrete = constants.%int_42.c68]
  116. // CHECK:STDOUT: %.loc19_19.1: %i32 = value_of_initializer %int.convert_checked [concrete = constants.%int_42.c68]
  117. // CHECK:STDOUT: %.loc19_19.2: %i32 = converted %int_42, %.loc19_19.1 [concrete = constants.%int_42.c68]
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT:
  120. // CHECK:STDOUT: !members:
  121. // CHECK:STDOUT: .Self = %Self
  122. // CHECK:STDOUT: .F = %assoc0
  123. // CHECK:STDOUT: .G = %assoc1
  124. // CHECK:STDOUT: .T = @T.%assoc2
  125. // CHECK:STDOUT: .N = @N.%assoc3
  126. // CHECK:STDOUT: witness = (%F.decl, %G.decl, %T, %N)
  127. // CHECK:STDOUT: }
  128. // CHECK:STDOUT:
  129. // CHECK:STDOUT: generic assoc_const @T(@I.%Self: %I.type) {
  130. // CHECK:STDOUT: !definition:
  131. // CHECK:STDOUT:
  132. // CHECK:STDOUT: assoc_const T:! type = %.loc18_28;
  133. // CHECK:STDOUT: }
  134. // CHECK:STDOUT:
  135. // CHECK:STDOUT: generic assoc_const @N(@I.%Self: %I.type) {
  136. // CHECK:STDOUT: !definition:
  137. // CHECK:STDOUT:
  138. // CHECK:STDOUT: assoc_const N:! %i32 = %.loc19_19.2;
  139. // CHECK:STDOUT: }
  140. // CHECK:STDOUT:
  141. // CHECK:STDOUT: generic fn @F(@I.%Self: %I.type) {
  142. // CHECK:STDOUT: !definition:
  143. // CHECK:STDOUT:
  144. // CHECK:STDOUT: fn() {
  145. // CHECK:STDOUT: !entry:
  146. // CHECK:STDOUT: return
  147. // CHECK:STDOUT: }
  148. // CHECK:STDOUT: }
  149. // CHECK:STDOUT:
  150. // CHECK:STDOUT: generic fn @G(@I.%Self: %I.type) {
  151. // CHECK:STDOUT: !definition:
  152. // CHECK:STDOUT:
  153. // CHECK:STDOUT: fn(%a.param_patt: %i32, %b.param_patt: %i32) -> %i32 = "int.sadd";
  154. // CHECK:STDOUT: }
  155. // CHECK:STDOUT:
  156. // CHECK:STDOUT: specific @F(constants.%Self.826) {}
  157. // CHECK:STDOUT:
  158. // CHECK:STDOUT: specific @G(constants.%Self.826) {}
  159. // CHECK:STDOUT:
  160. // CHECK:STDOUT: specific @T(constants.%Self.826) {}
  161. // CHECK:STDOUT:
  162. // CHECK:STDOUT: specific @N(constants.%Self.826) {}
  163. // CHECK:STDOUT: