fail_not_in_function.carbon 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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/if_expr/fail_not_in_function.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/if_expr/fail_not_in_function.carbon
  10. // --- fail_basic.carbon
  11. library "[[@TEST_NAME]]";
  12. // CHECK:STDERR: fail_basic.carbon:[[@LINE+12]]:14: error: semantics TODO: `Control flow expressions are currently only supported inside functions.` [SemanticsTodo]
  13. // CHECK:STDERR: let x: i32 = if true then 1 else 0;
  14. // CHECK:STDERR: ^~~~~~~
  15. // CHECK:STDERR:
  16. // CHECK:STDERR: fail_basic.carbon:[[@LINE+8]]:22: 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+4]]:14: 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. let x: i32 = if true then 1 else 0;
  25. // --- fail_types.carbon
  26. library "[[@TEST_NAME]]";
  27. // CHECK:STDERR: fail_types.carbon:[[@LINE+4]]:8: error: semantics TODO: `Control flow expressions are currently only supported inside functions.` [SemanticsTodo]
  28. // CHECK:STDERR: var y: if true then i32 else f64;
  29. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
  30. // CHECK:STDERR:
  31. var y: if true then i32 else f64;
  32. // --- fail_in_param.carbon
  33. library "[[@TEST_NAME]]";
  34. // CHECK:STDERR: fail_in_param.carbon:[[@LINE+4]]:9: error: semantics TODO: `Control flow expressions are currently only supported inside functions.` [SemanticsTodo]
  35. // CHECK:STDERR: fn F(a: if true then i32 else f64);
  36. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
  37. // CHECK:STDERR:
  38. fn F(a: if true then i32 else f64);
  39. // --- fail_class.carbon
  40. library "[[@TEST_NAME]]";
  41. class C {
  42. // CHECK:STDERR: fail_class.carbon:[[@LINE+12]]:10: error: semantics TODO: `Control flow expressions are currently only supported inside functions.` [SemanticsTodo]
  43. // CHECK:STDERR: var n: if true then i32 else f64;
  44. // CHECK:STDERR: ^~~~~~~
  45. // CHECK:STDERR:
  46. // CHECK:STDERR: fail_class.carbon:[[@LINE+8]]:18: 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+4]]:10: 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. var n: if true then i32 else f64;
  55. }
  56. // --- fail_nested_class.carbon
  57. library "[[@TEST_NAME]]";
  58. base class C(T:! type) {}
  59. fn F() {
  60. class B {
  61. // CHECK:STDERR: fail_nested_class.carbon:[[@LINE+4]]:20: error: semantics TODO: `Control flow expressions are currently only supported inside functions.` [SemanticsTodo]
  62. // CHECK:STDERR: extend base: C(if true then i32 else i32);
  63. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
  64. // CHECK:STDERR:
  65. extend base: C(if true then i32 else i32);
  66. }
  67. }
  68. // CHECK:STDOUT: --- fail_basic.carbon
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: constants {
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: file {}
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: --- fail_types.carbon
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: constants {
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: file {}
  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: file {}
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: --- fail_class.carbon
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: constants {
  92. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  93. // CHECK:STDOUT: %true: bool = bool_literal true [concrete]
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT:
  96. // CHECK:STDOUT: file {}
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: class @C {
  99. // CHECK:STDOUT: %true: bool = bool_literal true [concrete = constants.%true]
  100. // CHECK:STDOUT: if %true br !if.expr.then else br !if.expr.else
  101. // CHECK:STDOUT: complete_type_witness = invalid
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: !members:
  104. // CHECK:STDOUT: .Self = constants.%C
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: --- fail_nested_class.carbon
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: constants {
  110. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
  111. // CHECK:STDOUT: %C.type: type = generic_class_type @C [concrete]
  112. // CHECK:STDOUT: %C.generic: %C.type = struct_value () [concrete]
  113. // CHECK:STDOUT: %C: type = class_type @C, @C(%T) [symbolic]
  114. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  115. // CHECK:STDOUT: %complete_type.357: <witness> = complete_type_witness %empty_struct_type [concrete]
  116. // CHECK:STDOUT: %B: type = class_type @B [concrete]
  117. // CHECK:STDOUT: %true: bool = bool_literal true [concrete]
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT:
  120. // CHECK:STDOUT: file {}
  121. // CHECK:STDOUT:
  122. // CHECK:STDOUT: generic class @C(<unexpected>.inst17.loc4_14: type) {
  123. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic = %T (constants.%T)]
  124. // CHECK:STDOUT:
  125. // CHECK:STDOUT: !definition:
  126. // CHECK:STDOUT:
  127. // CHECK:STDOUT: class {
  128. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  129. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type.357]
  130. // CHECK:STDOUT: complete_type_witness = %complete_type
  131. // CHECK:STDOUT:
  132. // CHECK:STDOUT: !members:
  133. // CHECK:STDOUT: .Self = constants.%C
  134. // CHECK:STDOUT: }
  135. // CHECK:STDOUT: }
  136. // CHECK:STDOUT:
  137. // CHECK:STDOUT: class @B {
  138. // CHECK:STDOUT: %C.ref: %C.type = name_ref C, <unexpected>.inst21.loc4_24 [concrete = constants.%C.generic]
  139. // CHECK:STDOUT: %true: bool = bool_literal true [concrete = constants.%true]
  140. // CHECK:STDOUT: if %true br !if.expr.then else br !if.expr.else
  141. // CHECK:STDOUT: complete_type_witness = invalid
  142. // CHECK:STDOUT:
  143. // CHECK:STDOUT: !members:
  144. // CHECK:STDOUT: .Self = constants.%B
  145. // CHECK:STDOUT: .C = <poisoned>
  146. // CHECK:STDOUT: }
  147. // CHECK:STDOUT:
  148. // CHECK:STDOUT: fn @F();
  149. // CHECK:STDOUT:
  150. // CHECK:STDOUT: specific @C(constants.%T) {
  151. // CHECK:STDOUT: %T => constants.%T
  152. // CHECK:STDOUT: }
  153. // CHECK:STDOUT: