todo_define_not_default.carbon 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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> [template]
  23. // CHECK:STDOUT: %Self.fb7: %I.type = bind_symbolic_name Self, 0 [symbolic]
  24. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  25. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  26. // CHECK:STDOUT: %F.assoc_type: type = assoc_entity_type %I.type, %F.type [template]
  27. // CHECK:STDOUT: %assoc0.389: %F.assoc_type = assoc_entity element0, @I.%F.decl [template]
  28. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  29. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  30. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  31. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  32. // CHECK:STDOUT: %G.assoc_type: type = assoc_entity_type %I.type, %G.type [template]
  33. // CHECK:STDOUT: %assoc1: %G.assoc_type = assoc_entity element1, @I.%G.decl [template]
  34. // CHECK:STDOUT: %tuple.type.24b: type = tuple_type (type, type) [template]
  35. // CHECK:STDOUT: %tuple.type.471: type = tuple_type (%i32, %i32) [template]
  36. // CHECK:STDOUT: %assoc_type.579: type = assoc_entity_type %I.type, type [template]
  37. // CHECK:STDOUT: %assoc2: %assoc_type.579 = assoc_entity element2, @I.%T [template]
  38. // CHECK:STDOUT: %int_42.20e: Core.IntLiteral = int_value 42 [template]
  39. // CHECK:STDOUT: %Convert.type.cd1: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  40. // CHECK:STDOUT: %impl_witness.5b0: <witness> = impl_witness (imports.%import_ref.723), @impl.1(%int_32) [template]
  41. // CHECK:STDOUT: %Convert.type.466: type = fn_type @Convert.2, @impl.1(%int_32) [template]
  42. // CHECK:STDOUT: %Convert.925: %Convert.type.466 = struct_value () [template]
  43. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_42.20e, %Convert.925 [template]
  44. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.bound, @Convert.2(%int_32) [template]
  45. // CHECK:STDOUT: %int_42.b93: %i32 = int_value 42 [template]
  46. // CHECK:STDOUT: %assoc_type.b2b: type = assoc_entity_type %I.type, %i32 [template]
  47. // CHECK:STDOUT: %assoc3: %assoc_type.b2b = assoc_entity element3, @I.%N [template]
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT:
  50. // CHECK:STDOUT: imports {
  51. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  52. // CHECK:STDOUT: .Int = %import_ref.187
  53. // CHECK:STDOUT: .ImplicitAs = %import_ref.a69
  54. // CHECK:STDOUT: import Core//prelude
  55. // CHECK:STDOUT: import Core//prelude/...
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: file {
  60. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  61. // CHECK:STDOUT: .Core = imports.%Core
  62. // CHECK:STDOUT: .I = %I.decl
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT: %Core.import = import Core
  65. // CHECK:STDOUT: %I.decl: type = interface_decl @I [template = constants.%I.type] {} {}
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: interface @I {
  69. // CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self.fb7]
  70. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
  71. // CHECK:STDOUT: %assoc0: %F.assoc_type = assoc_entity element0, %F.decl [template = constants.%assoc0.389]
  72. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  73. // CHECK:STDOUT: %a.patt: %i32 = binding_pattern a
  74. // CHECK:STDOUT: %a.param_patt: %i32 = value_param_pattern %a.patt, runtime_param0
  75. // CHECK:STDOUT: %b.patt: %i32 = binding_pattern b
  76. // CHECK:STDOUT: %b.param_patt: %i32 = value_param_pattern %b.patt, runtime_param1
  77. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  78. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param2
  79. // CHECK:STDOUT: } {
  80. // CHECK:STDOUT: %int_32.loc14_27: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  81. // CHECK:STDOUT: %i32.loc14_27: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  82. // CHECK:STDOUT: %a.param: %i32 = value_param runtime_param0
  83. // CHECK:STDOUT: %.loc14_11: type = splice_block %i32.loc14_11 [template = constants.%i32] {
  84. // CHECK:STDOUT: %int_32.loc14_11: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  85. // CHECK:STDOUT: %i32.loc14_11: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT: %a: %i32 = bind_name a, %a.param
  88. // CHECK:STDOUT: %b.param: %i32 = value_param runtime_param1
  89. // CHECK:STDOUT: %.loc14_19: type = splice_block %i32.loc14_19 [template = constants.%i32] {
  90. // CHECK:STDOUT: %int_32.loc14_19: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  91. // CHECK:STDOUT: %i32.loc14_19: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT: %b: %i32 = bind_name b, %b.param
  94. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param2
  95. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT: %assoc1: %G.assoc_type = assoc_entity element1, %G.decl [template = constants.%assoc1]
  98. // CHECK:STDOUT: %int_32.loc18_19: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  99. // CHECK:STDOUT: %i32.loc18_19: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  100. // CHECK:STDOUT: %int_32.loc18_24: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  101. // CHECK:STDOUT: %i32.loc18_24: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  102. // CHECK:STDOUT: %.loc18_27: %tuple.type.24b = tuple_literal (%i32.loc18_19, %i32.loc18_24)
  103. // CHECK:STDOUT: %.loc18_28: type = converted %.loc18_27, constants.%tuple.type.471 [template = constants.%tuple.type.471]
  104. // CHECK:STDOUT: %T: type = assoc_const_decl T [template]
  105. // CHECK:STDOUT: %assoc2: %assoc_type.579 = assoc_entity element2, %T [template = constants.%assoc2]
  106. // CHECK:STDOUT: %int_42: Core.IntLiteral = int_value 42 [template = constants.%int_42.20e]
  107. // CHECK:STDOUT: %impl.elem0: %Convert.type.cd1 = impl_witness_access constants.%impl_witness.5b0, element0 [template = constants.%Convert.925]
  108. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_42, %impl.elem0 [template = constants.%Convert.bound]
  109. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.bound, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn]
  110. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %Convert.specific_fn(%int_42) [template = constants.%int_42.b93]
  111. // CHECK:STDOUT: %.loc19_19.1: %i32 = value_of_initializer %int.convert_checked [template = constants.%int_42.b93]
  112. // CHECK:STDOUT: %.loc19_19.2: %i32 = converted %int_42, %.loc19_19.1 [template = constants.%int_42.b93]
  113. // CHECK:STDOUT: %N: %i32 = assoc_const_decl N [template]
  114. // CHECK:STDOUT: %assoc3: %assoc_type.b2b = assoc_entity element3, %N [template = constants.%assoc3]
  115. // CHECK:STDOUT:
  116. // CHECK:STDOUT: !members:
  117. // CHECK:STDOUT: .Self = %Self
  118. // CHECK:STDOUT: .F = %assoc0
  119. // CHECK:STDOUT: .G = %assoc1
  120. // CHECK:STDOUT: .T = %assoc2
  121. // CHECK:STDOUT: .N = %assoc3
  122. // CHECK:STDOUT: witness = (%F.decl, %G.decl, %T, %N)
  123. // CHECK:STDOUT: }
  124. // CHECK:STDOUT:
  125. // CHECK:STDOUT: generic fn @F(@I.%Self: %I.type) {
  126. // CHECK:STDOUT: !definition:
  127. // CHECK:STDOUT:
  128. // CHECK:STDOUT: fn() {
  129. // CHECK:STDOUT: !entry:
  130. // CHECK:STDOUT: return
  131. // CHECK:STDOUT: }
  132. // CHECK:STDOUT: }
  133. // CHECK:STDOUT:
  134. // CHECK:STDOUT: generic fn @G(@I.%Self: %I.type) {
  135. // CHECK:STDOUT: !definition:
  136. // CHECK:STDOUT:
  137. // CHECK:STDOUT: fn(%a.param_patt: %i32, %b.param_patt: %i32) -> %i32 = "int.sadd";
  138. // CHECK:STDOUT: }
  139. // CHECK:STDOUT:
  140. // CHECK:STDOUT: specific @F(constants.%Self.fb7) {}
  141. // CHECK:STDOUT:
  142. // CHECK:STDOUT: specific @G(constants.%Self.fb7) {}
  143. // CHECK:STDOUT: