fail_not_in_function.carbon 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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: --- fail_types.carbon
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: --- fail_in_param.carbon
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: --- fail_class.carbon
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: constants {
  81. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  82. // CHECK:STDOUT: %true: bool = bool_literal true [concrete]
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: class @C {
  86. // CHECK:STDOUT: %true: bool = bool_literal true [concrete = constants.%true]
  87. // CHECK:STDOUT: if %true br !if.expr.then else br !if.expr.else
  88. // CHECK:STDOUT: complete_type_witness = invalid
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: !members:
  91. // CHECK:STDOUT: .Self = constants.%C
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: --- fail_nested_class.carbon
  95. // CHECK:STDOUT:
  96. // CHECK:STDOUT: constants {
  97. // CHECK:STDOUT: %T: type = symbolic_binding T, 0 [symbolic]
  98. // CHECK:STDOUT: %C.type: type = generic_class_type @C [concrete]
  99. // CHECK:STDOUT: %C.generic: %C.type = struct_value () [concrete]
  100. // CHECK:STDOUT: %C: type = class_type @C, @C(%T) [symbolic]
  101. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  102. // CHECK:STDOUT: %complete_type.357: <witness> = complete_type_witness %empty_struct_type [concrete]
  103. // CHECK:STDOUT: %B: type = class_type @B [concrete]
  104. // CHECK:STDOUT: %true: bool = bool_literal true [concrete]
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: generic class @C(<unexpected>.inst{{[0-9A-F]+}}.loc4_15: type) {
  108. // CHECK:STDOUT: %T: type = symbolic_binding T, 0 [symbolic = %T (constants.%T)]
  109. // CHECK:STDOUT:
  110. // CHECK:STDOUT: !definition:
  111. // CHECK:STDOUT:
  112. // CHECK:STDOUT: class {
  113. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type.357]
  114. // CHECK:STDOUT: complete_type_witness = %complete_type
  115. // CHECK:STDOUT:
  116. // CHECK:STDOUT: !members:
  117. // CHECK:STDOUT: .Self = constants.%C
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT: }
  120. // CHECK:STDOUT:
  121. // CHECK:STDOUT: class @B {
  122. // CHECK:STDOUT: %C.ref: %C.type = name_ref C, <unexpected>.inst{{[0-9A-F]+}}.loc4_24 [concrete = constants.%C.generic]
  123. // CHECK:STDOUT: %true: bool = bool_literal true [concrete = constants.%true]
  124. // CHECK:STDOUT: if %true br !if.expr.then else br !if.expr.else
  125. // CHECK:STDOUT: complete_type_witness = invalid
  126. // CHECK:STDOUT:
  127. // CHECK:STDOUT: !members:
  128. // CHECK:STDOUT: .Self = constants.%B
  129. // CHECK:STDOUT: .C = <poisoned>
  130. // CHECK:STDOUT: }
  131. // CHECK:STDOUT:
  132. // CHECK:STDOUT: fn @F();
  133. // CHECK:STDOUT:
  134. // CHECK:STDOUT: specific @C(constants.%T) {
  135. // CHECK:STDOUT: %T => constants.%T
  136. // CHECK:STDOUT: }
  137. // CHECK:STDOUT: