fail_not_in_function.carbon 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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]]:14: 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]]:22: 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+4]]: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. var y: if true then i32 else f64;
  32. // CHECK:STDERR: fail_not_in_function.carbon:[[@LINE+8]]:9: error: semantics TODO: `Control flow expressions are currently only supported inside functions.` [SemanticsTodo]
  33. // CHECK:STDERR: fn F(a: if true then i32 else f64);
  34. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
  35. // CHECK:STDERR:
  36. // CHECK:STDERR: fail_not_in_function.carbon:[[@LINE+4]]: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. fn F(a: if true then i32 else f64);
  41. class C {
  42. // CHECK:STDERR: fail_not_in_function.carbon:[[@LINE+3]]:10: error: semantics TODO: `Control flow expressions are currently only supported inside functions.` [SemanticsTodo]
  43. // CHECK:STDERR: var n: if true then i32 else f64;
  44. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
  45. var n: if true then i32 else f64;
  46. }
  47. // CHECK:STDOUT: --- fail_not_in_function.carbon
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: constants {
  50. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  51. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  52. // CHECK:STDOUT: %true: bool = bool_literal true [template]
  53. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  54. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  55. // CHECK:STDOUT: %C: type = class_type @C [template]
  56. // CHECK:STDOUT: %C.elem: type = unbound_element_type %C, %i32 [template]
  57. // CHECK:STDOUT: %struct_type.n: type = struct_type {.n: %i32} [template]
  58. // CHECK:STDOUT: %complete_type.3: <witness> = complete_type_witness %struct_type.n [template]
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT:
  61. // CHECK:STDOUT: imports {
  62. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  63. // CHECK:STDOUT: .Int = %import_ref.1
  64. // CHECK:STDOUT: .ImplicitAs = %import_ref.5
  65. // CHECK:STDOUT: .Float = %import_ref.229
  66. // CHECK:STDOUT: import Core//prelude
  67. // CHECK:STDOUT: import Core//prelude/...
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: file {
  72. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  73. // CHECK:STDOUT: .Core = imports.%Core
  74. // CHECK:STDOUT: .x = <unexpected>.inst43.loc27_5
  75. // CHECK:STDOUT: .y = %y
  76. // CHECK:STDOUT: .F = %F.decl
  77. // CHECK:STDOUT: .C = %C.decl
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT: %Core.import = import Core
  80. // CHECK:STDOUT: %y.var: ref %i32 = var y
  81. // CHECK:STDOUT: %y: ref %i32 = bind_name y, %y.var
  82. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  83. // CHECK:STDOUT: %a.patt: %i32 = binding_pattern a
  84. // CHECK:STDOUT: %a.param_patt: %i32 = value_param_pattern %a.patt, runtime_param0
  85. // CHECK:STDOUT: } {
  86. // CHECK:STDOUT: %a.param: %i32 = value_param runtime_param0
  87. // CHECK:STDOUT: %a: %i32 = bind_name a, %a.param
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: class @C {
  93. // CHECK:STDOUT: %.loc49: %C.elem = field_decl n, element0 [template]
  94. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.n [template = constants.%complete_type.3]
  95. // CHECK:STDOUT:
  96. // CHECK:STDOUT: !members:
  97. // CHECK:STDOUT: .Self = constants.%C
  98. // CHECK:STDOUT: .n = %.loc49
  99. // CHECK:STDOUT: complete_type_witness = %complete_type
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT:
  102. // CHECK:STDOUT: fn @F(%a.param_patt: %i32);
  103. // CHECK:STDOUT:
  104. // CHECK:STDOUT: fn @__global_init() {
  105. // CHECK:STDOUT: !entry:
  106. // CHECK:STDOUT: %true: bool = bool_literal true [template = constants.%true]
  107. // CHECK:STDOUT: if %true br !if.expr.then else br !if.expr.else
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT: