fail_not_in_function.carbon 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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: imports {
  55. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  56. // CHECK:STDOUT: .Int32 = %import_ref.1
  57. // CHECK:STDOUT: .Float = %import_ref.2
  58. // CHECK:STDOUT: import Core//prelude
  59. // CHECK:STDOUT: import Core//prelude/operators
  60. // CHECK:STDOUT: import Core//prelude/types
  61. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  62. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  63. // CHECK:STDOUT: import Core//prelude/operators/comparison
  64. // CHECK:STDOUT: import Core//prelude/types/bool
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  67. // CHECK:STDOUT: %import_ref.2: %Float.type = import_ref Core//prelude/types, inst+32, loaded [template = constants.%Float]
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: file {
  71. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  72. // CHECK:STDOUT: .Core = imports.%Core
  73. // CHECK:STDOUT: .x = <unexpected>.inst+12.loc23_5
  74. // CHECK:STDOUT: .C = %C.decl
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT: %Core.import = import Core
  77. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  78. // CHECK:STDOUT: %.loc23_8.1: type = value_of_initializer %int.make_type_32 [template = i32]
  79. // CHECK:STDOUT: %.loc23_8.2: type = converted %int.make_type_32, %.loc23_8.1 [template = i32]
  80. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: class @C {
  84. // CHECK:STDOUT: %.loc37: bool = bool_literal true [template = constants.%.2]
  85. // CHECK:STDOUT: if %.loc37 br !if.expr.then else br !if.expr.else
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: !members:
  88. // CHECK:STDOUT: .Self = constants.%C
  89. // CHECK:STDOUT: .n = <unexpected>.inst+48.loc37_8
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: fn @Float(%size: i32) -> type = "float.make_type";
  95. // CHECK:STDOUT:
  96. // CHECK:STDOUT: fn @__global_init() {
  97. // CHECK:STDOUT: !entry:
  98. // CHECK:STDOUT: %.loc23: bool = bool_literal true [template = constants.%.2]
  99. // CHECK:STDOUT: if %.loc23 br !if.expr.then else br !if.expr.else
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT: