fail_not_copyable.carbon 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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/full.carbon
  6. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  7. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  8. //
  9. // AUTOUPDATE
  10. // TIP: To test this file alone, run:
  11. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/var/fail_not_copyable.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/var/fail_not_copyable.carbon
  14. class X {
  15. }
  16. fn F(x: X) {
  17. // TODO: Strings should eventually be copyable, once we decide how to
  18. // represent them.
  19. // CHECK:STDERR: fail_not_copyable.carbon:[[@LINE+4]]:19: error: cannot copy value of type `String` [CopyOfUncopyableType]
  20. // CHECK:STDERR: var s: String = "hello";
  21. // CHECK:STDERR: ^~~~~~~
  22. // CHECK:STDERR:
  23. var s: String = "hello";
  24. // TODO: Decide on rules for when classes are copyable.
  25. // CHECK:STDERR: fail_not_copyable.carbon:[[@LINE+4]]:14: error: cannot copy value of type `X` [CopyOfUncopyableType]
  26. // CHECK:STDERR: var y: X = x;
  27. // CHECK:STDERR: ^
  28. // CHECK:STDERR:
  29. var y: X = x;
  30. }
  31. // CHECK:STDOUT: --- fail_not_copyable.carbon
  32. // CHECK:STDOUT:
  33. // CHECK:STDOUT: constants {
  34. // CHECK:STDOUT: %X: type = class_type @X [concrete]
  35. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  36. // CHECK:STDOUT: %complete_type.357: <witness> = complete_type_witness %empty_struct_type [concrete]
  37. // CHECK:STDOUT: %pattern_type.019: type = pattern_type %X [concrete]
  38. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  39. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  40. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  41. // CHECK:STDOUT: %ptr.a45: type = ptr_type String [concrete]
  42. // CHECK:STDOUT: %pattern_type.b05: type = pattern_type String [concrete]
  43. // CHECK:STDOUT: %str: String = string_literal "hello" [concrete]
  44. // CHECK:STDOUT: %Destroy.type: type = facet_type <@Destroy> [concrete]
  45. // CHECK:STDOUT: %Op.type.9e1: type = fn_type @Op.2, @Destroy.impl(%X) [concrete]
  46. // CHECK:STDOUT: %Op.33a: %Op.type.9e1 = struct_value () [concrete]
  47. // CHECK:STDOUT: %ptr.d17: type = ptr_type %X [concrete]
  48. // CHECK:STDOUT: %Op.specific_fn.d1f: <specific function> = specific_function %Op.33a, @Op.2(%X) [concrete]
  49. // CHECK:STDOUT: %Op.type.051: type = fn_type @Op.2, @Destroy.impl(String) [concrete]
  50. // CHECK:STDOUT: %Op.5ef: %Op.type.051 = struct_value () [concrete]
  51. // CHECK:STDOUT: %Op.specific_fn.93f: <specific function> = specific_function %Op.5ef, @Op.2(String) [concrete]
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: imports {
  55. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  56. // CHECK:STDOUT: .Destroy = %Core.Destroy
  57. // CHECK:STDOUT: import Core//prelude
  58. // CHECK:STDOUT: import Core//prelude/...
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT: %Core.Destroy: type = import_ref Core//prelude/destroy, Destroy, loaded [concrete = constants.%Destroy.type]
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: file {
  64. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  65. // CHECK:STDOUT: .Core = imports.%Core
  66. // CHECK:STDOUT: .X = %X.decl
  67. // CHECK:STDOUT: .F = %F.decl
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT: %Core.import = import Core
  70. // CHECK:STDOUT: %X.decl: type = class_decl @X [concrete = constants.%X] {} {}
  71. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  72. // CHECK:STDOUT: %x.patt: %pattern_type.019 = binding_pattern x [concrete]
  73. // CHECK:STDOUT: %x.param_patt: %pattern_type.019 = value_param_pattern %x.patt, call_param0 [concrete]
  74. // CHECK:STDOUT: } {
  75. // CHECK:STDOUT: %x.param: %X = value_param call_param0
  76. // CHECK:STDOUT: %X.ref.loc18: type = name_ref X, file.%X.decl [concrete = constants.%X]
  77. // CHECK:STDOUT: %x: %X = bind_name x, %x.param
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: class @X {
  82. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  83. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type.357]
  84. // CHECK:STDOUT: complete_type_witness = %complete_type
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: !members:
  87. // CHECK:STDOUT: .Self = constants.%X
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: fn @F(%x.param: %X) {
  91. // CHECK:STDOUT: !entry:
  92. // CHECK:STDOUT: name_binding_decl {
  93. // CHECK:STDOUT: %s.patt: %pattern_type.b05 = binding_pattern s [concrete]
  94. // CHECK:STDOUT: %s.var_patt: %pattern_type.b05 = var_pattern %s.patt [concrete]
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT: %s.var: ref String = var %s.var_patt
  97. // CHECK:STDOUT: %str: String = string_literal "hello" [concrete = constants.%str]
  98. // CHECK:STDOUT: assign %s.var, <error>
  99. // CHECK:STDOUT: %s: ref String = bind_name s, %s.var
  100. // CHECK:STDOUT: name_binding_decl {
  101. // CHECK:STDOUT: %y.patt: %pattern_type.019 = binding_pattern y [concrete]
  102. // CHECK:STDOUT: %y.var_patt: %pattern_type.019 = var_pattern %y.patt [concrete]
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT: %y.var: ref %X = var %y.var_patt
  105. // CHECK:STDOUT: %x.ref: %X = name_ref x, %x
  106. // CHECK:STDOUT: assign %y.var, <error>
  107. // CHECK:STDOUT: %X.ref.loc32: type = name_ref X, file.%X.decl [concrete = constants.%X]
  108. // CHECK:STDOUT: %y: ref %X = bind_name y, %y.var
  109. // CHECK:STDOUT: %Op.bound.loc32: <bound method> = bound_method %y.var, constants.%Op.33a
  110. // CHECK:STDOUT: %Op.specific_fn.1: <specific function> = specific_function constants.%Op.33a, @Op.2(constants.%X) [concrete = constants.%Op.specific_fn.d1f]
  111. // CHECK:STDOUT: %bound_method.loc32: <bound method> = bound_method %y.var, %Op.specific_fn.1
  112. // CHECK:STDOUT: %addr.loc32: %ptr.d17 = addr_of %y.var
  113. // CHECK:STDOUT: %no_op.loc32: init %empty_tuple.type = call %bound_method.loc32(%addr.loc32)
  114. // CHECK:STDOUT: %Op.bound.loc25: <bound method> = bound_method %s.var, constants.%Op.5ef
  115. // CHECK:STDOUT: %Op.specific_fn.2: <specific function> = specific_function constants.%Op.5ef, @Op.2(String) [concrete = constants.%Op.specific_fn.93f]
  116. // CHECK:STDOUT: %bound_method.loc25: <bound method> = bound_method %s.var, %Op.specific_fn.2
  117. // CHECK:STDOUT: %addr.loc25: %ptr.a45 = addr_of %s.var
  118. // CHECK:STDOUT: %no_op.loc25: init %empty_tuple.type = call %bound_method.loc25(%addr.loc25)
  119. // CHECK:STDOUT: return
  120. // CHECK:STDOUT: }
  121. // CHECK:STDOUT: