fail_not_in_function.carbon 4.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. // CHECK:STDERR: fail_not_in_function.carbon:[[@LINE+12]]:14: ERROR: Semantics TODO: `Control flow expressions are currently only supported inside functions.`.
  11. // CHECK:STDERR: let x: i32 = if true then 1 else 0;
  12. // CHECK:STDERR: ^~~~~~~
  13. // CHECK:STDERR:
  14. // CHECK:STDERR: fail_not_in_function.carbon:[[@LINE+8]]:14: ERROR: Semantics TODO: `Control flow expressions are currently only supported inside functions.`.
  15. // CHECK:STDERR: let x: i32 = if true then 1 else 0;
  16. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~
  17. // CHECK:STDERR:
  18. // CHECK:STDERR: fail_not_in_function.carbon:[[@LINE+4]]:22: ERROR: Semantics TODO: `Control flow expressions are currently only supported inside functions.`.
  19. // CHECK:STDERR: let x: i32 = if true then 1 else 0;
  20. // CHECK:STDERR: ^~~~~~
  21. // CHECK:STDERR:
  22. let x: i32 = if true then 1 else 0;
  23. class C {
  24. // CHECK:STDERR: fail_not_in_function.carbon:[[@LINE+11]]:10: ERROR: Semantics TODO: `Control flow expressions are currently only supported inside functions.`.
  25. // CHECK:STDERR: var n: if true then i32 else f64;
  26. // CHECK:STDERR: ^~~~~~~
  27. // CHECK:STDERR:
  28. // CHECK:STDERR: fail_not_in_function.carbon:[[@LINE+7]]:10: ERROR: Semantics TODO: `Control flow expressions are currently only supported inside functions.`.
  29. // CHECK:STDERR: var n: if true then i32 else f64;
  30. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
  31. // CHECK:STDERR:
  32. // CHECK:STDERR: fail_not_in_function.carbon:[[@LINE+3]]:18: ERROR: Semantics TODO: `Control flow expressions are currently only supported inside functions.`.
  33. // CHECK:STDERR: var n: if true then i32 else f64;
  34. // CHECK:STDERR: ^~~~~~~~
  35. var n: if true then i32 else f64;
  36. }
  37. // CHECK:STDOUT: --- fail_not_in_function.carbon
  38. // CHECK:STDOUT:
  39. // CHECK:STDOUT: constants {
  40. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  41. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  42. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  43. // CHECK:STDOUT: %.2: bool = bool_literal true [template]
  44. // CHECK:STDOUT: %.3: i32 = int_literal 1 [template]
  45. // CHECK:STDOUT: %.4: i32 = int_literal 0 [template]
  46. // CHECK:STDOUT: %C: type = class_type @C [template]
  47. // CHECK:STDOUT: %.5: i32 = int_literal 64 [template]
  48. // CHECK:STDOUT: %Float.type: type = fn_type @Float [template]
  49. // CHECK:STDOUT: %Float: %Float.type = struct_value () [template]
  50. // CHECK:STDOUT: %.6: type = unbound_element_type %C, i32 [template]
  51. // CHECK:STDOUT: %.7: type = struct_type {.n: i32} [template]
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: file {
  55. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  56. // CHECK:STDOUT: .Core = %Core
  57. // CHECK:STDOUT: .x = <unexpected instref inst+11>
  58. // CHECK:STDOUT: .C = %C.decl
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  61. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  62. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  63. // CHECK:STDOUT: %.loc23_8.1: type = value_of_initializer %int.make_type_32 [template = i32]
  64. // CHECK:STDOUT: %.loc23_8.2: type = converted %int.make_type_32, %.loc23_8.1 [template = i32]
  65. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  66. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  67. // CHECK:STDOUT: %import_ref.3: %Float.type = import_ref ir3, inst+31, loaded [template = constants.%Float]
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: class @C {
  71. // CHECK:STDOUT: %.loc37: bool = bool_literal true [template = constants.%.2]
  72. // CHECK:STDOUT: if %.loc37 br !if.expr.then else br !if.expr.else
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: !members:
  75. // CHECK:STDOUT: .Self = constants.%C
  76. // CHECK:STDOUT: .n = <unexpected instref inst+48>
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: fn @Float(%size: i32) -> type = "float.make_type";
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: fn @__global_init() {
  84. // CHECK:STDOUT: !entry:
  85. // CHECK:STDOUT: %.loc23: bool = bool_literal true [template = constants.%.2]
  86. // CHECK:STDOUT: if %.loc23 br !if.expr.then else br !if.expr.else
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT: