fail_not_in_function.carbon 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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/primitives.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/if_expr/fail_not_in_function.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/if_expr/fail_not_in_function.carbon
  14. // --- fail_basic.carbon
  15. library "[[@TEST_NAME]]";
  16. // CHECK:STDERR: fail_basic.carbon:[[@LINE+12]]:14: error: semantics TODO: `Control flow expressions are currently only supported inside functions.` [SemanticsTodo]
  17. // CHECK:STDERR: let x: i32 = if true then 1 else 0;
  18. // CHECK:STDERR: ^~~~~~~
  19. // CHECK:STDERR:
  20. // CHECK:STDERR: fail_basic.carbon:[[@LINE+8]]:22: error: semantics TODO: `Control flow expressions are currently only supported inside functions.` [SemanticsTodo]
  21. // CHECK:STDERR: let x: i32 = if true then 1 else 0;
  22. // CHECK:STDERR: ^~~~~~
  23. // CHECK:STDERR:
  24. // CHECK:STDERR: fail_basic.carbon:[[@LINE+4]]:14: error: semantics TODO: `Control flow expressions are currently only supported inside functions.` [SemanticsTodo]
  25. // CHECK:STDERR: let x: i32 = if true then 1 else 0;
  26. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~
  27. // CHECK:STDERR:
  28. let x: i32 = if true then 1 else 0;
  29. // --- fail_types.carbon
  30. library "[[@TEST_NAME]]";
  31. // CHECK:STDERR: fail_types.carbon:[[@LINE+4]]:8: error: semantics TODO: `Control flow expressions are currently only supported inside functions.` [SemanticsTodo]
  32. // CHECK:STDERR: var y: if true then i32 else f64;
  33. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
  34. // CHECK:STDERR:
  35. var y: if true then i32 else f64;
  36. // --- fail_in_param.carbon
  37. library "[[@TEST_NAME]]";
  38. // CHECK:STDERR: fail_in_param.carbon:[[@LINE+4]]:9: error: semantics TODO: `Control flow expressions are currently only supported inside functions.` [SemanticsTodo]
  39. // CHECK:STDERR: fn F(a: if true then i32 else f64);
  40. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
  41. // CHECK:STDERR:
  42. fn F(a: if true then i32 else f64);
  43. // --- fail_class.carbon
  44. library "[[@TEST_NAME]]";
  45. class C {
  46. // CHECK:STDERR: fail_class.carbon:[[@LINE+12]]:10: error: semantics TODO: `Control flow expressions are currently only supported inside functions.` [SemanticsTodo]
  47. // CHECK:STDERR: var n: if true then i32 else f64;
  48. // CHECK:STDERR: ^~~~~~~
  49. // CHECK:STDERR:
  50. // CHECK:STDERR: fail_class.carbon:[[@LINE+8]]:18: error: semantics TODO: `Control flow expressions are currently only supported inside functions.` [SemanticsTodo]
  51. // CHECK:STDERR: var n: if true then i32 else f64;
  52. // CHECK:STDERR: ^~~~~~~~
  53. // CHECK:STDERR:
  54. // CHECK:STDERR: fail_class.carbon:[[@LINE+4]]:10: error: semantics TODO: `Control flow expressions are currently only supported inside functions.` [SemanticsTodo]
  55. // CHECK:STDERR: var n: if true then i32 else f64;
  56. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
  57. // CHECK:STDERR:
  58. var n: if true then i32 else f64;
  59. }
  60. // --- fail_nested_class.carbon
  61. library "[[@TEST_NAME]]";
  62. base class C(T:! type) {}
  63. fn F() {
  64. class B {
  65. // CHECK:STDERR: fail_nested_class.carbon:[[@LINE+4]]:20: error: semantics TODO: `Control flow expressions are currently only supported inside functions.` [SemanticsTodo]
  66. // CHECK:STDERR: extend base: C(if true then i32 else i32);
  67. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
  68. // CHECK:STDERR:
  69. extend base: C(if true then i32 else i32);
  70. }
  71. }
  72. // CHECK:STDOUT: --- fail_basic.carbon
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: constants {
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: --- fail_types.carbon
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: constants {
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: --- fail_in_param.carbon
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: constants {
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: --- fail_class.carbon
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: constants {
  90. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  91. // CHECK:STDOUT: %true: bool = bool_literal true [concrete]
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: class @C {
  95. // CHECK:STDOUT: %true: bool = bool_literal true [concrete = constants.%true]
  96. // CHECK:STDOUT: if %true br !if.expr.then else br !if.expr.else
  97. // CHECK:STDOUT: complete_type_witness = invalid
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: !members:
  100. // CHECK:STDOUT: .Self = constants.%C
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: --- fail_nested_class.carbon
  104. // CHECK:STDOUT:
  105. // CHECK:STDOUT: constants {
  106. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
  107. // CHECK:STDOUT: %C.type: type = generic_class_type @C [concrete]
  108. // CHECK:STDOUT: %C.generic: %C.type = struct_value () [concrete]
  109. // CHECK:STDOUT: %C: type = class_type @C, @C(%T) [symbolic]
  110. // CHECK:STDOUT: %Destroy.type: type = facet_type <@Destroy> [concrete]
  111. // CHECK:STDOUT: %pattern_type.f6d: type = pattern_type auto [concrete]
  112. // CHECK:STDOUT: %Destroy.impl_witness: <witness> = impl_witness @C.%Destroy.impl_witness_table, @C.as.Destroy.impl(%T) [symbolic]
  113. // CHECK:STDOUT: %ptr.7d2: type = ptr_type %C [symbolic]
  114. // CHECK:STDOUT: %pattern_type.1d2: type = pattern_type %ptr.7d2 [symbolic]
  115. // CHECK:STDOUT: %C.as.Destroy.impl.Op.type: type = fn_type @C.as.Destroy.impl.Op, @C.as.Destroy.impl(%T) [symbolic]
  116. // CHECK:STDOUT: %C.as.Destroy.impl.Op: %C.as.Destroy.impl.Op.type = struct_value () [symbolic]
  117. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  118. // CHECK:STDOUT: %complete_type.357: <witness> = complete_type_witness %empty_struct_type [concrete]
  119. // CHECK:STDOUT: %B: type = class_type @B [concrete]
  120. // CHECK:STDOUT: %true: bool = bool_literal true [concrete]
  121. // CHECK:STDOUT: }
  122. // CHECK:STDOUT:
  123. // CHECK:STDOUT: generic impl @C.as.Destroy.impl(<unexpected>.inst19.loc4_14: type) {
  124. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic = %T (constants.%T)]
  125. // CHECK:STDOUT: %C: type = class_type @C, @C(%T) [symbolic = %C (constants.%C)]
  126. // CHECK:STDOUT: %Destroy.impl_witness: <witness> = impl_witness @C.%Destroy.impl_witness_table, @C.as.Destroy.impl(%T) [symbolic = %Destroy.impl_witness (constants.%Destroy.impl_witness)]
  127. // CHECK:STDOUT:
  128. // CHECK:STDOUT: !definition:
  129. // CHECK:STDOUT: %C.as.Destroy.impl.Op.type: type = fn_type @C.as.Destroy.impl.Op, @C.as.Destroy.impl(%T) [symbolic = %C.as.Destroy.impl.Op.type (constants.%C.as.Destroy.impl.Op.type)]
  130. // CHECK:STDOUT: %C.as.Destroy.impl.Op: @C.as.Destroy.impl.%C.as.Destroy.impl.Op.type (%C.as.Destroy.impl.Op.type) = struct_value () [symbolic = %C.as.Destroy.impl.Op (constants.%C.as.Destroy.impl.Op)]
  131. // CHECK:STDOUT:
  132. // CHECK:STDOUT: impl: @C.%Self.ref as constants.%Destroy.type {
  133. // CHECK:STDOUT: %C.as.Destroy.impl.Op.decl: @C.as.Destroy.impl.%C.as.Destroy.impl.Op.type (%C.as.Destroy.impl.Op.type) = fn_decl @C.as.Destroy.impl.Op [symbolic = @C.as.Destroy.impl.%C.as.Destroy.impl.Op (constants.%C.as.Destroy.impl.Op)] {
  134. // CHECK:STDOUT: %self.patt: @C.as.Destroy.impl.Op.%pattern_type (%pattern_type.1d2) = binding_pattern self [concrete]
  135. // CHECK:STDOUT: %self.param_patt: @C.as.Destroy.impl.Op.%pattern_type (%pattern_type.1d2) = value_param_pattern %self.patt, call_param0 [concrete]
  136. // CHECK:STDOUT: %.loc4_24.1: %pattern_type.f6d = addr_pattern %self.param_patt [concrete]
  137. // CHECK:STDOUT: } {
  138. // CHECK:STDOUT: %self.param: @C.as.Destroy.impl.Op.%ptr (%ptr.7d2) = value_param call_param0
  139. // CHECK:STDOUT: %.loc4_24.2: type = splice_block %Self.ref [symbolic = %C (constants.%C)] {
  140. // CHECK:STDOUT: %.loc4_24.3: type = specific_constant constants.%C, @C(constants.%T) [symbolic = %C (constants.%C)]
  141. // CHECK:STDOUT: %Self.ref: type = name_ref Self, %.loc4_24.3 [symbolic = %C (constants.%C)]
  142. // CHECK:STDOUT: }
  143. // CHECK:STDOUT: %self: @C.as.Destroy.impl.Op.%ptr (%ptr.7d2) = bind_name self, %self.param
  144. // CHECK:STDOUT: }
  145. // CHECK:STDOUT:
  146. // CHECK:STDOUT: !members:
  147. // CHECK:STDOUT: .Op = %C.as.Destroy.impl.Op.decl
  148. // CHECK:STDOUT: witness = @C.%Destroy.impl_witness
  149. // CHECK:STDOUT: }
  150. // CHECK:STDOUT: }
  151. // CHECK:STDOUT:
  152. // CHECK:STDOUT: generic class @C(<unexpected>.inst19.loc4_14: type) {
  153. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic = %T (constants.%T)]
  154. // CHECK:STDOUT:
  155. // CHECK:STDOUT: !definition:
  156. // CHECK:STDOUT:
  157. // CHECK:STDOUT: class {
  158. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [symbolic = @C.as.Destroy.impl.%C (constants.%C)]
  159. // CHECK:STDOUT: impl_decl @C.as.Destroy.impl [concrete] {} {}
  160. // CHECK:STDOUT: %Destroy.impl_witness_table = impl_witness_table (@C.as.Destroy.impl.%C.as.Destroy.impl.Op.decl), @C.as.Destroy.impl [concrete]
  161. // CHECK:STDOUT: %Destroy.impl_witness: <witness> = impl_witness %Destroy.impl_witness_table, @C.as.Destroy.impl(constants.%T) [symbolic = @C.as.Destroy.impl.%Destroy.impl_witness (constants.%Destroy.impl_witness)]
  162. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type.357]
  163. // CHECK:STDOUT: complete_type_witness = %complete_type
  164. // CHECK:STDOUT:
  165. // CHECK:STDOUT: !members:
  166. // CHECK:STDOUT: .Self = constants.%C
  167. // CHECK:STDOUT: }
  168. // CHECK:STDOUT: }
  169. // CHECK:STDOUT:
  170. // CHECK:STDOUT: class @B {
  171. // CHECK:STDOUT: %C.ref: %C.type = name_ref C, <unexpected>.inst24.loc4_24 [concrete = constants.%C.generic]
  172. // CHECK:STDOUT: %true: bool = bool_literal true [concrete = constants.%true]
  173. // CHECK:STDOUT: if %true br !if.expr.then else br !if.expr.else
  174. // CHECK:STDOUT: complete_type_witness = invalid
  175. // CHECK:STDOUT:
  176. // CHECK:STDOUT: !members:
  177. // CHECK:STDOUT: .Self = constants.%B
  178. // CHECK:STDOUT: .C = <poisoned>
  179. // CHECK:STDOUT: }
  180. // CHECK:STDOUT:
  181. // CHECK:STDOUT: generic fn @C.as.Destroy.impl.Op(<unexpected>.inst19.loc4_14: type) {
  182. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic = %T (constants.%T)]
  183. // CHECK:STDOUT: %C: type = class_type @C, @C(%T) [symbolic = %C (constants.%C)]
  184. // CHECK:STDOUT: %ptr: type = ptr_type %C [symbolic = %ptr (constants.%ptr.7d2)]
  185. // CHECK:STDOUT: %pattern_type: type = pattern_type %ptr [symbolic = %pattern_type (constants.%pattern_type.1d2)]
  186. // CHECK:STDOUT:
  187. // CHECK:STDOUT: !definition:
  188. // CHECK:STDOUT:
  189. // CHECK:STDOUT: fn(%self.param: @C.as.Destroy.impl.Op.%ptr (%ptr.7d2)) = "no_op";
  190. // CHECK:STDOUT: }
  191. // CHECK:STDOUT:
  192. // CHECK:STDOUT: fn @F();
  193. // CHECK:STDOUT:
  194. // CHECK:STDOUT: specific @C(constants.%T) {
  195. // CHECK:STDOUT: %T => constants.%T
  196. // CHECK:STDOUT: }
  197. // CHECK:STDOUT:
  198. // CHECK:STDOUT: specific @C.as.Destroy.impl(constants.%T) {
  199. // CHECK:STDOUT: %T => constants.%T
  200. // CHECK:STDOUT: %C => constants.%C
  201. // CHECK:STDOUT: %Destroy.impl_witness => constants.%Destroy.impl_witness
  202. // CHECK:STDOUT: }
  203. // CHECK:STDOUT:
  204. // CHECK:STDOUT: specific @C.as.Destroy.impl.Op(constants.%T) {
  205. // CHECK:STDOUT: %T => constants.%T
  206. // CHECK:STDOUT: %C => constants.%C
  207. // CHECK:STDOUT: %ptr => constants.%ptr.7d2
  208. // CHECK:STDOUT: %pattern_type => constants.%pattern_type.1d2
  209. // CHECK:STDOUT: }
  210. // CHECK:STDOUT: