fail_not_in_function.carbon 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.` [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+8]]: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+4]]:22: 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. 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.` [SemanticsTodo]
  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.` [SemanticsTodo]
  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.` [SemanticsTodo]
  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: %int_32: Core.IntLiteral = int_value 32 [template]
  41. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  42. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  43. // CHECK:STDOUT: %i32: type = int_type signed, %int_32 [template]
  44. // CHECK:STDOUT: %true: bool = bool_literal true [template]
  45. // CHECK:STDOUT: %C: type = class_type @C [template]
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT:
  48. // CHECK:STDOUT: imports {
  49. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  50. // CHECK:STDOUT: .Int = %import_ref.1
  51. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  52. // CHECK:STDOUT: .Float = %import_ref.38
  53. // CHECK:STDOUT: import Core//prelude
  54. // CHECK:STDOUT: import Core//prelude/...
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: file {
  59. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  60. // CHECK:STDOUT: .Core = imports.%Core
  61. // CHECK:STDOUT: .x = <unexpected>.inst+18.loc23_5
  62. // CHECK:STDOUT: .C = %C.decl
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT: %Core.import = import Core
  65. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  66. // CHECK:STDOUT: %int.make_type_signed: init type = call constants.%Int(%int_32) [template = constants.%i32]
  67. // CHECK:STDOUT: %.loc23_8.1: type = value_of_initializer %int.make_type_signed [template = constants.%i32]
  68. // CHECK:STDOUT: %.loc23_8.2: type = converted %int.make_type_signed, %.loc23_8.1 [template = constants.%i32]
  69. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: class @C {
  73. // CHECK:STDOUT: %true: bool = bool_literal true [template = constants.%true]
  74. // CHECK:STDOUT: if %true br !if.expr.then else br !if.expr.else
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: !members:
  77. // CHECK:STDOUT: .Self = constants.%C
  78. // CHECK:STDOUT: .n = <unexpected>.inst+357.loc37_8
  79. // CHECK:STDOUT: complete_type_witness = <unexpected>.inst+359.loc38_1
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: fn @__global_init() {
  83. // CHECK:STDOUT: !entry:
  84. // CHECK:STDOUT: %true: bool = bool_literal true [template = constants.%true]
  85. // CHECK:STDOUT: if %true br !if.expr.then else br !if.expr.else
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT: