fail_not_in_function.carbon 6.6 KB

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