expression.carbon 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/none.carbon
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/patterns/expression.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/patterns/expression.carbon
  12. // --- fail_todo_let.carbon
  13. library "[[@TEST_NAME]]";
  14. // TODO: We should reject this for using a refutable pattern in an irrefutable pattern context.
  15. let a: () = ();
  16. // CHECK:STDERR: fail_todo_let.carbon:[[@LINE+4]]:5: error: semantics TODO: `expression pattern` [SemanticsTodo]
  17. // CHECK:STDERR: let a = ();
  18. // CHECK:STDERR: ^
  19. // CHECK:STDERR:
  20. let a = ();
  21. // --- fail_todo_in_tuple.carbon
  22. library "[[@TEST_NAME]]";
  23. // TODO: We should reject this for using a refutable pattern in an irrefutable pattern context.
  24. let a: () = ();
  25. // CHECK:STDERR: fail_todo_in_tuple.carbon:[[@LINE+4]]:13: error: semantics TODO: `expression pattern` [SemanticsTodo]
  26. // CHECK:STDERR: let (b: (), a, c: ()) = ((), (), ());
  27. // CHECK:STDERR: ^
  28. // CHECK:STDERR:
  29. let (b: (), a, c: ()) = ((), (), ());
  30. // --- fail_todo_in_function_param.carbon
  31. library "[[@TEST_NAME]]";
  32. // TODO: We should reject this for using a refutable pattern in an irrefutable pattern context.
  33. let a: () = ();
  34. // CHECK:STDERR: fail_todo_in_function_param.carbon:[[@LINE+4]]:6: error: semantics TODO: `expression pattern` [SemanticsTodo]
  35. // CHECK:STDERR: fn F(a) {}
  36. // CHECK:STDERR: ^
  37. // CHECK:STDERR:
  38. fn F(a) {}
  39. // --- fail_todo_parens.carbon
  40. library "[[@TEST_NAME]]";
  41. let a: () = ();
  42. // TODO: Replace this with a valid expression pattern once we support refutable
  43. // pattern contexts.
  44. // Note that this is a parenthesized zero-tuple expression pattern, not a
  45. // one-tuple pattern containing a zero-tuple.
  46. // CHECK:STDERR: fail_todo_parens.carbon:[[@LINE+4]]:6: error: semantics TODO: `expression pattern` [SemanticsTodo]
  47. // CHECK:STDERR: let (a) = ();
  48. // CHECK:STDERR: ^
  49. // CHECK:STDERR:
  50. let (a) = ();
  51. // --- fail_todo_control_flow.carbon
  52. library "[[@TEST_NAME]]";
  53. fn F() {
  54. // TODO: Replace this with a valid expression pattern once we support refutable
  55. // pattern contexts.
  56. //@dump-sem-ir-begin
  57. // CHECK:STDERR: fail_todo_control_flow.carbon:[[@LINE+8]]:8: error: semantics TODO: `expression pattern` [SemanticsTodo]
  58. // CHECK:STDERR: let (if true then true else false, true and true) = (true, true);
  59. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
  60. // CHECK:STDERR:
  61. // CHECK:STDERR: fail_todo_control_flow.carbon:[[@LINE+4]]:38: error: semantics TODO: `expression pattern` [SemanticsTodo]
  62. // CHECK:STDERR: let (if true then true else false, true and true) = (true, true);
  63. // CHECK:STDERR: ^~~~~~~~~~~~~
  64. // CHECK:STDERR:
  65. let (if true then true else false, true and true) = (true, true);
  66. //@dump-sem-ir-end
  67. }
  68. // CHECK:STDOUT: --- fail_todo_control_flow.carbon
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: constants {
  71. // CHECK:STDOUT: %true: bool = bool_literal true [concrete]
  72. // CHECK:STDOUT: %false: bool = bool_literal false [concrete]
  73. // CHECK:STDOUT: %pattern_type.831: type = pattern_type bool [concrete]
  74. // CHECK:STDOUT: %tuple.type: type = tuple_type (bool, bool) [concrete]
  75. // CHECK:STDOUT: %pattern_type.860: type = pattern_type %tuple.type [concrete]
  76. // CHECK:STDOUT: %tuple: %tuple.type = tuple_value (%true, %true) [concrete]
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: fn @F() {
  80. // CHECK:STDOUT: !entry:
  81. // CHECK:STDOUT: name_binding_decl {
  82. // CHECK:STDOUT: %expr_patt.loc16_26: %pattern_type.831 = expr_pattern %.loc16_8 in [concrete] {
  83. // CHECK:STDOUT: %true.loc16_11: bool = bool_literal true [concrete = constants.%true]
  84. // CHECK:STDOUT: if %true.loc16_11 br !if.expr.then else br !if.expr.else
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: !if.expr.then:
  87. // CHECK:STDOUT: %true.loc16_21: bool = bool_literal true [concrete = constants.%true]
  88. // CHECK:STDOUT: br !if.expr.result(%true.loc16_21)
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: !if.expr.else:
  91. // CHECK:STDOUT: %false.loc16_31: bool = bool_literal false [concrete = constants.%false]
  92. // CHECK:STDOUT: br !if.expr.result(%false.loc16_31)
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: !if.expr.result:
  95. // CHECK:STDOUT: %.loc16_8: bool = block_arg !if.expr.result [concrete = constants.%true]
  96. // CHECK:STDOUT: <elided>
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT: %expr_patt.loc16_43: %pattern_type.831 = expr_pattern %.loc16_43 in [concrete] {
  99. // CHECK:STDOUT: %true.loc16_38: bool = bool_literal true [concrete = constants.%true]
  100. // CHECK:STDOUT: %false.loc16_43: bool = bool_literal false [concrete = constants.%false]
  101. // CHECK:STDOUT: if %true.loc16_38 br !and.rhs else br !.loc16(%false.loc16_43)
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: !and.rhs:
  104. // CHECK:STDOUT: %true.loc16_47: bool = bool_literal true [concrete = constants.%true]
  105. // CHECK:STDOUT: br !.loc16(%true.loc16_47)
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: !.loc16:
  108. // CHECK:STDOUT: %.loc16_43: bool = block_arg !.loc16 [concrete = constants.%true]
  109. // CHECK:STDOUT: <elided>
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT: %.loc16_51: %pattern_type.860 = tuple_pattern (%expr_patt.loc16_26, %expr_patt.loc16_43) [concrete]
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT: %true.loc16_56: bool = bool_literal true [concrete = constants.%true]
  114. // CHECK:STDOUT: %true.loc16_62: bool = bool_literal true [concrete = constants.%true]
  115. // CHECK:STDOUT: %.loc16_66: %tuple.type = tuple_literal (%true.loc16_56, %true.loc16_62) [concrete = constants.%tuple]
  116. // CHECK:STDOUT: <elided>
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT: