convert.carbon 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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/int.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/let/convert.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/let/convert.carbon
  12. // --- convert.carbon
  13. library "[[@TEST_NAME]]";
  14. fn F() -> i32 {
  15. var v: (i32, i32, i32) = (1, 2, 3);
  16. // Convert from object representation to value representation.
  17. //@dump-sem-ir-begin
  18. let w: (i32, i32, i32) = v;
  19. //@dump-sem-ir-end
  20. return w.1;
  21. }
  22. // --- fail_let_bound_to_ref_not_mutable.carbon
  23. library "[[@TEST_NAME]]";
  24. fn G() {
  25. var a: i32 = 0;
  26. let n: i32 = a;
  27. // CHECK:STDERR: fail_let_bound_to_ref_not_mutable.carbon:[[@LINE+4]]:3: error: expression is not assignable [AssignmentToNonAssignable]
  28. // CHECK:STDERR: n = 1;
  29. // CHECK:STDERR: ^
  30. // CHECK:STDERR:
  31. n = 1;
  32. }
  33. // CHECK:STDOUT: --- convert.carbon
  34. // CHECK:STDOUT:
  35. // CHECK:STDOUT: constants {
  36. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  37. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  38. // CHECK:STDOUT: %tuple.type.ff9: type = tuple_type (type, type, type) [concrete]
  39. // CHECK:STDOUT: %tuple.e64: %tuple.type.ff9 = tuple_value (%i32, %i32, %i32) [concrete]
  40. // CHECK:STDOUT: %tuple.type.189: type = tuple_type (%i32, %i32, %i32) [concrete]
  41. // CHECK:STDOUT: %pattern_type.b5a: type = pattern_type %tuple.type.189 [concrete]
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: imports {
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT:
  47. // CHECK:STDOUT: fn @F() -> %i32 {
  48. // CHECK:STDOUT: !entry:
  49. // CHECK:STDOUT: <elided>
  50. // CHECK:STDOUT: name_binding_decl {
  51. // CHECK:STDOUT: %w.patt: %pattern_type.b5a = value_binding_pattern w [concrete]
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT: %v.ref: ref %tuple.type.189 = name_ref v, %v
  54. // CHECK:STDOUT: %.loc8_24.1: type = splice_block %.loc8_24.3 [concrete = constants.%tuple.type.189] {
  55. // CHECK:STDOUT: %int_32.loc8_11: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  56. // CHECK:STDOUT: %i32.loc8_11: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  57. // CHECK:STDOUT: %int_32.loc8_16: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  58. // CHECK:STDOUT: %i32.loc8_16: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  59. // CHECK:STDOUT: %int_32.loc8_21: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  60. // CHECK:STDOUT: %i32.loc8_21: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  61. // CHECK:STDOUT: %.loc8_24.2: %tuple.type.ff9 = tuple_literal (%i32.loc8_11, %i32.loc8_16, %i32.loc8_21) [concrete = constants.%tuple.e64]
  62. // CHECK:STDOUT: %.loc8_24.3: type = converted %.loc8_24.2, constants.%tuple.type.189 [concrete = constants.%tuple.type.189]
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT: %tuple.elem0.loc8: ref %i32 = tuple_access %v.ref, element0
  65. // CHECK:STDOUT: %.loc8_28.1: %i32 = acquire_value %tuple.elem0.loc8
  66. // CHECK:STDOUT: %tuple.elem1.loc8: ref %i32 = tuple_access %v.ref, element1
  67. // CHECK:STDOUT: %.loc8_28.2: %i32 = acquire_value %tuple.elem1.loc8
  68. // CHECK:STDOUT: %tuple.elem2.loc8: ref %i32 = tuple_access %v.ref, element2
  69. // CHECK:STDOUT: %.loc8_28.3: %i32 = acquire_value %tuple.elem2.loc8
  70. // CHECK:STDOUT: %tuple: %tuple.type.189 = tuple_value (%.loc8_28.1, %.loc8_28.2, %.loc8_28.3)
  71. // CHECK:STDOUT: %.loc8_28.4: %tuple.type.189 = converted %v.ref, %tuple
  72. // CHECK:STDOUT: %w: %tuple.type.189 = value_binding w, %.loc8_28.4
  73. // CHECK:STDOUT: <elided>
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT: