todo_define_not_default.carbon 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/int.carbon
  6. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  7. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  8. //
  9. // AUTOUPDATE
  10. // TIP: To test this file alone, run:
  11. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interface/todo_define_not_default.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interface/todo_define_not_default.carbon
  14. interface I {
  15. // TODO: A definition without `default` in an interface should be rejected.
  16. fn F() {}
  17. fn G(a: i32, b: i32) -> i32 = "int.sadd";
  18. // TODO: An associated constant with an initializer without `default` in an
  19. // interface should be rejected.
  20. let T:! type = (i32, i32);
  21. let N:! i32 = 42;
  22. }
  23. // CHECK:STDOUT: --- todo_define_not_default.carbon
  24. // CHECK:STDOUT:
  25. // CHECK:STDOUT: constants {
  26. // CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
  27. // CHECK:STDOUT: %Self.1c6: %I.type = symbolic_binding Self, 0 [symbolic]
  28. // CHECK:STDOUT: %I.F.type: type = fn_type @I.F [concrete]
  29. // CHECK:STDOUT: %I.F: %I.F.type = struct_value () [concrete]
  30. // CHECK:STDOUT: %I.assoc_type: type = assoc_entity_type @I [concrete]
  31. // CHECK:STDOUT: %assoc0.82e: %I.assoc_type = assoc_entity element0, @I.%I.F.decl [concrete]
  32. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  33. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  34. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  35. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  36. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  37. // CHECK:STDOUT: %I.G.type: type = fn_type @I.G [concrete]
  38. // CHECK:STDOUT: %I.G: %I.G.type = struct_value () [concrete]
  39. // CHECK:STDOUT: %assoc1: %I.assoc_type = assoc_entity element1, @I.%I.G.decl [concrete]
  40. // CHECK:STDOUT: %assoc2: %I.assoc_type = assoc_entity element2, @I.%T [concrete]
  41. // CHECK:STDOUT: %tuple.type.24b: type = tuple_type (type, type) [concrete]
  42. // CHECK:STDOUT: %tuple: %tuple.type.24b = tuple_value (%i32, %i32) [concrete]
  43. // CHECK:STDOUT: %tuple.type.d07: type = tuple_type (%i32, %i32) [concrete]
  44. // CHECK:STDOUT: %assoc3: %I.assoc_type = assoc_entity element3, @I.%N [concrete]
  45. // CHECK:STDOUT: %int_42.20e: Core.IntLiteral = int_value 42 [concrete]
  46. // CHECK:STDOUT: %ImplicitAs.type.cc7: type = generic_interface_type @ImplicitAs [concrete]
  47. // CHECK:STDOUT: %ImplicitAs.generic: %ImplicitAs.type.cc7 = struct_value () [concrete]
  48. // CHECK:STDOUT: %ImplicitAs.type.d14: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [concrete]
  49. // CHECK:STDOUT: %ImplicitAs.Convert.type.1b6: type = fn_type @ImplicitAs.Convert, @ImplicitAs(%i32) [concrete]
  50. // CHECK:STDOUT: %To: Core.IntLiteral = symbolic_binding To, 0 [symbolic]
  51. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.412: type = fn_type @Core.IntLiteral.as.ImplicitAs.impl.Convert, @Core.IntLiteral.as.ImplicitAs.impl(%To) [symbolic]
  52. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.740: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.412 = struct_value () [symbolic]
  53. // CHECK:STDOUT: %ImplicitAs.impl_witness.ec0: <witness> = impl_witness imports.%ImplicitAs.impl_witness_table.99e, @Core.IntLiteral.as.ImplicitAs.impl(%int_32) [concrete]
  54. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.84b: type = fn_type @Core.IntLiteral.as.ImplicitAs.impl.Convert, @Core.IntLiteral.as.ImplicitAs.impl(%int_32) [concrete]
  55. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.6f0: %Core.IntLiteral.as.ImplicitAs.impl.Convert.type.84b = struct_value () [concrete]
  56. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.d14 = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.ec0) [concrete]
  57. // CHECK:STDOUT: %.d28: type = fn_type_with_self_type %ImplicitAs.Convert.type.1b6, %ImplicitAs.facet [concrete]
  58. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.bound: <bound method> = bound_method %int_42.20e, %Core.IntLiteral.as.ImplicitAs.impl.Convert.6f0 [concrete]
  59. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn: <specific function> = specific_function %Core.IntLiteral.as.ImplicitAs.impl.Convert.6f0, @Core.IntLiteral.as.ImplicitAs.impl.Convert(%int_32) [concrete]
  60. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %int_42.20e, %Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn [concrete]
  61. // CHECK:STDOUT: %int_42.c68: %i32 = int_value 42 [concrete]
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: imports {
  65. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  66. // CHECK:STDOUT: .Int = %Core.Int
  67. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  68. // CHECK:STDOUT: import Core//prelude
  69. // CHECK:STDOUT: import Core//prelude/...
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/parts/int, Int, loaded [concrete = constants.%Int.generic]
  72. // CHECK:STDOUT: %Core.ImplicitAs: %ImplicitAs.type.cc7 = import_ref Core//prelude/parts/as, ImplicitAs, loaded [concrete = constants.%ImplicitAs.generic]
  73. // CHECK:STDOUT: %Core.import_ref.3e1: @Core.IntLiteral.as.ImplicitAs.impl.%Core.IntLiteral.as.ImplicitAs.impl.Convert.type (%Core.IntLiteral.as.ImplicitAs.impl.Convert.type.412) = import_ref Core//prelude/parts/int, loc{{\d+_\d+}}, loaded [symbolic = @Core.IntLiteral.as.ImplicitAs.impl.%Core.IntLiteral.as.ImplicitAs.impl.Convert (constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.740)]
  74. // CHECK:STDOUT: %ImplicitAs.impl_witness_table.99e = impl_witness_table (%Core.import_ref.3e1), @Core.IntLiteral.as.ImplicitAs.impl [concrete]
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: file {
  78. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  79. // CHECK:STDOUT: .Core = imports.%Core
  80. // CHECK:STDOUT: .I = %I.decl
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT: %Core.import = import Core
  83. // CHECK:STDOUT: %I.decl: type = interface_decl @I [concrete = constants.%I.type] {} {}
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: interface @I {
  87. // CHECK:STDOUT: %Self: %I.type = symbolic_binding Self, 0 [symbolic = constants.%Self.1c6]
  88. // CHECK:STDOUT: %I.F.decl: %I.F.type = fn_decl @I.F [concrete = constants.%I.F] {} {}
  89. // CHECK:STDOUT: %assoc0: %I.assoc_type = assoc_entity element0, %I.F.decl [concrete = constants.%assoc0.82e]
  90. // CHECK:STDOUT: %I.G.decl: %I.G.type = fn_decl @I.G [concrete = constants.%I.G] {
  91. // CHECK:STDOUT: %a.patt: %pattern_type.7ce = value_binding_pattern a [concrete]
  92. // CHECK:STDOUT: %a.param_patt: %pattern_type.7ce = value_param_pattern %a.patt, call_param0 [concrete]
  93. // CHECK:STDOUT: %b.patt: %pattern_type.7ce = value_binding_pattern b [concrete]
  94. // CHECK:STDOUT: %b.param_patt: %pattern_type.7ce = value_param_pattern %b.patt, call_param1 [concrete]
  95. // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
  96. // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param2 [concrete]
  97. // CHECK:STDOUT: } {
  98. // CHECK:STDOUT: %int_32.loc18_27: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  99. // CHECK:STDOUT: %i32.loc18_27: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  100. // CHECK:STDOUT: %a.param: %i32 = value_param call_param0
  101. // CHECK:STDOUT: %.loc18_11: type = splice_block %i32.loc18_11 [concrete = constants.%i32] {
  102. // CHECK:STDOUT: %int_32.loc18_11: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  103. // CHECK:STDOUT: %i32.loc18_11: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  104. // CHECK:STDOUT: }
  105. // CHECK:STDOUT: %a: %i32 = value_binding a, %a.param
  106. // CHECK:STDOUT: %b.param: %i32 = value_param call_param1
  107. // CHECK:STDOUT: %.loc18_19: type = splice_block %i32.loc18_19 [concrete = constants.%i32] {
  108. // CHECK:STDOUT: %int_32.loc18_19: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  109. // CHECK:STDOUT: %i32.loc18_19: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT: %b: %i32 = value_binding b, %b.param
  112. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param2
  113. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  114. // CHECK:STDOUT: }
  115. // CHECK:STDOUT: %assoc1: %I.assoc_type = assoc_entity element1, %I.G.decl [concrete = constants.%assoc1]
  116. // CHECK:STDOUT: %T: type = assoc_const_decl @T [concrete] {
  117. // CHECK:STDOUT: %assoc2: %I.assoc_type = assoc_entity element2, @I.%T [concrete = constants.%assoc2]
  118. // CHECK:STDOUT: %int_32.loc22_19: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  119. // CHECK:STDOUT: %i32.loc22_19: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  120. // CHECK:STDOUT: %int_32.loc22_24: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  121. // CHECK:STDOUT: %i32.loc22_24: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  122. // CHECK:STDOUT: %.loc22_27: %tuple.type.24b = tuple_literal (%i32.loc22_19, %i32.loc22_24) [concrete = constants.%tuple]
  123. // CHECK:STDOUT: %.loc22_28: type = converted %.loc22_27, constants.%tuple.type.d07 [concrete = constants.%tuple.type.d07]
  124. // CHECK:STDOUT: }
  125. // CHECK:STDOUT: %N: %i32 = assoc_const_decl @N [concrete] {
  126. // CHECK:STDOUT: %assoc3: %I.assoc_type = assoc_entity element3, @I.%N [concrete = constants.%assoc3]
  127. // CHECK:STDOUT: %int_42: Core.IntLiteral = int_value 42 [concrete = constants.%int_42.20e]
  128. // CHECK:STDOUT: %impl.elem0: %.d28 = impl_witness_access constants.%ImplicitAs.impl_witness.ec0, element0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.6f0]
  129. // CHECK:STDOUT: %bound_method.loc23_19.1: <bound method> = bound_method %int_42, %impl.elem0 [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.bound]
  130. // CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Core.IntLiteral.as.ImplicitAs.impl.Convert(constants.%int_32) [concrete = constants.%Core.IntLiteral.as.ImplicitAs.impl.Convert.specific_fn]
  131. // CHECK:STDOUT: %bound_method.loc23_19.2: <bound method> = bound_method %int_42, %specific_fn [concrete = constants.%bound_method]
  132. // CHECK:STDOUT: %Core.IntLiteral.as.ImplicitAs.impl.Convert.call: init %i32 = call %bound_method.loc23_19.2(%int_42) [concrete = constants.%int_42.c68]
  133. // CHECK:STDOUT: %.loc23_19.1: %i32 = value_of_initializer %Core.IntLiteral.as.ImplicitAs.impl.Convert.call [concrete = constants.%int_42.c68]
  134. // CHECK:STDOUT: %.loc23_19.2: %i32 = converted %int_42, %.loc23_19.1 [concrete = constants.%int_42.c68]
  135. // CHECK:STDOUT: }
  136. // CHECK:STDOUT:
  137. // CHECK:STDOUT: !members:
  138. // CHECK:STDOUT: .Self = %Self
  139. // CHECK:STDOUT: .F = %assoc0
  140. // CHECK:STDOUT: .G = %assoc1
  141. // CHECK:STDOUT: .T = @T.%assoc2
  142. // CHECK:STDOUT: .N = @N.%assoc3
  143. // CHECK:STDOUT: witness = (%I.F.decl, %I.G.decl, %T, %N)
  144. // CHECK:STDOUT:
  145. // CHECK:STDOUT: !requires:
  146. // CHECK:STDOUT: }
  147. // CHECK:STDOUT:
  148. // CHECK:STDOUT: generic assoc_const @T(@I.%Self: %I.type) {
  149. // CHECK:STDOUT: !definition:
  150. // CHECK:STDOUT:
  151. // CHECK:STDOUT: assoc_const T:! type = %.loc22_28;
  152. // CHECK:STDOUT: }
  153. // CHECK:STDOUT:
  154. // CHECK:STDOUT: generic assoc_const @N(@I.%Self: %I.type) {
  155. // CHECK:STDOUT: !definition:
  156. // CHECK:STDOUT:
  157. // CHECK:STDOUT: assoc_const N:! %i32 = %.loc23_19.2;
  158. // CHECK:STDOUT: }
  159. // CHECK:STDOUT:
  160. // CHECK:STDOUT: generic fn @I.F(@I.%Self: %I.type) {
  161. // CHECK:STDOUT: !definition:
  162. // CHECK:STDOUT:
  163. // CHECK:STDOUT: fn() {
  164. // CHECK:STDOUT: !entry:
  165. // CHECK:STDOUT: return
  166. // CHECK:STDOUT: }
  167. // CHECK:STDOUT: }
  168. // CHECK:STDOUT:
  169. // CHECK:STDOUT: generic fn @I.G(@I.%Self: %I.type) {
  170. // CHECK:STDOUT: !definition:
  171. // CHECK:STDOUT:
  172. // CHECK:STDOUT: fn(%a.param: %i32, %b.param: %i32) -> %i32 = "int.sadd";
  173. // CHECK:STDOUT: }
  174. // CHECK:STDOUT:
  175. // CHECK:STDOUT: specific @I.F(constants.%Self.1c6) {}
  176. // CHECK:STDOUT:
  177. // CHECK:STDOUT: specific @I.G(constants.%Self.1c6) {}
  178. // CHECK:STDOUT:
  179. // CHECK:STDOUT: specific @T(constants.%Self.1c6) {}
  180. // CHECK:STDOUT:
  181. // CHECK:STDOUT: specific @N(constants.%Self.1c6) {}
  182. // CHECK:STDOUT: