fail_not_in_function.carbon 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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+16]]:14: error: semantics TODO: `Control flow expressions are currently only supported inside functions.` [SemanticsTodo]
  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+12]]:22: error: semantics TODO: `Control flow expressions are currently only supported inside functions.` [SemanticsTodo]
  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+8]]:14: error: semantics TODO: `Control flow expressions are currently only supported inside functions.` [SemanticsTodo]
  19. // CHECK:STDERR: let x: i32 = if true then 1 else 0;
  20. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~
  21. // CHECK:STDERR:
  22. // CHECK:STDERR: fail_not_in_function.carbon:[[@LINE+4]]:14: error: semantics TODO: `Control flow expressions are currently only supported inside functions.` [SemanticsTodo]
  23. // CHECK:STDERR: let x: i32 = if true then 1 else 0;
  24. // CHECK:STDERR: ^~~~~~~
  25. // CHECK:STDERR:
  26. let x: i32 = if true then 1 else 0;
  27. // CHECK:STDERR: fail_not_in_function.carbon:[[@LINE+8]]: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. // CHECK:STDERR: fail_not_in_function.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. // CHECK:STDERR: fail_not_in_function.carbon:[[@LINE+8]]:9: error: semantics TODO: `Control flow expressions are currently only supported inside functions.` [SemanticsTodo]
  37. // CHECK:STDERR: fn F(a: if true then i32 else f64);
  38. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
  39. // CHECK:STDERR:
  40. // CHECK:STDERR: fail_not_in_function.carbon:[[@LINE+4]]:9: error: semantics TODO: `Control flow expressions are currently only supported inside functions.` [SemanticsTodo]
  41. // CHECK:STDERR: fn F(a: if true then i32 else f64);
  42. // CHECK:STDERR: ^~~~~~~
  43. // CHECK:STDERR:
  44. fn F(a: if true then i32 else f64);
  45. class C {
  46. // CHECK:STDERR: fail_not_in_function.carbon:[[@LINE+4]]: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. var n: if true then i32 else f64;
  51. }
  52. // CHECK:STDOUT: --- fail_not_in_function.carbon
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: constants {
  55. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  56. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  57. // CHECK:STDOUT: %true: bool = bool_literal true [concrete]
  58. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  59. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  60. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  61. // CHECK:STDOUT: %C.elem: type = unbound_element_type %C, %i32 [concrete]
  62. // CHECK:STDOUT: %struct_type.n: type = struct_type {.n: %i32} [concrete]
  63. // CHECK:STDOUT: %complete_type.54b: <witness> = complete_type_witness %struct_type.n [concrete]
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: imports {
  67. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  68. // CHECK:STDOUT: .Int = %Core.Int
  69. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  70. // CHECK:STDOUT: .Float = %Core.Float
  71. // CHECK:STDOUT: import Core//prelude
  72. // CHECK:STDOUT: import Core//prelude/...
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: file {
  77. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  78. // CHECK:STDOUT: .Core = imports.%Core
  79. // CHECK:STDOUT: .x = %x
  80. // CHECK:STDOUT: .y = %y
  81. // CHECK:STDOUT: .F = %F.decl
  82. // CHECK:STDOUT: .C = %C.decl
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT: %Core.import = import Core
  85. // CHECK:STDOUT: name_binding_decl {
  86. // CHECK:STDOUT: %x.patt: %i32 = binding_pattern x
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT: %.loc27: type = splice_block %i32 [concrete = constants.%i32] {
  89. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  90. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT: %x: %i32 = bind_name x, <unexpected>.inst1063.loc27_14
  93. // CHECK:STDOUT: name_binding_decl {
  94. // CHECK:STDOUT: %y.patt: %i32 = binding_pattern y
  95. // CHECK:STDOUT: %.loc37: %i32 = var_pattern %y.patt
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT: %y.var: ref %i32 = var y
  98. // CHECK:STDOUT: %y: ref %i32 = bind_name y, %y.var
  99. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  100. // CHECK:STDOUT: %a.patt: %i32 = binding_pattern a
  101. // CHECK:STDOUT: %a.param_patt: %i32 = value_param_pattern %a.patt, call_param0
  102. // CHECK:STDOUT: } {
  103. // CHECK:STDOUT: %a.param: %i32 = value_param call_param0
  104. // CHECK:STDOUT: %a: %i32 = bind_name a, %a.param
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: class @C {
  110. // CHECK:STDOUT: %.loc54_8: %C.elem = field_decl n, element0 [concrete]
  111. // CHECK:STDOUT: name_binding_decl {
  112. // CHECK:STDOUT: %.loc54_3: %C.elem = var_pattern %.loc54_8
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT: %.var: ref %C.elem = var <none>
  115. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.n [concrete = constants.%complete_type.54b]
  116. // CHECK:STDOUT: complete_type_witness = %complete_type
  117. // CHECK:STDOUT:
  118. // CHECK:STDOUT: !members:
  119. // CHECK:STDOUT: .Self = constants.%C
  120. // CHECK:STDOUT: .n = %.loc54_8
  121. // CHECK:STDOUT: }
  122. // CHECK:STDOUT:
  123. // CHECK:STDOUT: fn @F(%a.param_patt: %i32);
  124. // CHECK:STDOUT:
  125. // CHECK:STDOUT: fn @__global_init() {
  126. // CHECK:STDOUT: !entry:
  127. // CHECK:STDOUT: %true: bool = bool_literal true [concrete = constants.%true]
  128. // CHECK:STDOUT: if %true br !if.expr.then else br !if.expr.else
  129. // CHECK:STDOUT: }
  130. // CHECK:STDOUT: