fail_not_copyable.carbon 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  6. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  7. //
  8. // AUTOUPDATE
  9. // TIP: To test this file alone, run:
  10. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/var/fail_not_copyable.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/var/fail_not_copyable.carbon
  13. class X {
  14. }
  15. fn F(x: X) {
  16. // TODO: Strings should eventually be copyable, once we decide how to
  17. // represent them.
  18. // CHECK:STDERR: fail_not_copyable.carbon:[[@LINE+4]]:19: error: cannot copy value of type `String` [CopyOfUncopyableType]
  19. // CHECK:STDERR: var s: String = "hello";
  20. // CHECK:STDERR: ^~~~~~~
  21. // CHECK:STDERR:
  22. var s: String = "hello";
  23. // TODO: Decide on rules for when classes are copyable.
  24. // CHECK:STDERR: fail_not_copyable.carbon:[[@LINE+4]]:14: error: cannot copy value of type `X` [CopyOfUncopyableType]
  25. // CHECK:STDERR: var y: X = x;
  26. // CHECK:STDERR: ^
  27. // CHECK:STDERR:
  28. var y: X = x;
  29. }
  30. // CHECK:STDOUT: --- fail_not_copyable.carbon
  31. // CHECK:STDOUT:
  32. // CHECK:STDOUT: constants {
  33. // CHECK:STDOUT: %X: type = class_type @X [concrete]
  34. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  35. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  36. // CHECK:STDOUT: %pattern_type.019: type = pattern_type %X [concrete]
  37. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  38. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  39. // CHECK:STDOUT: %pattern_type.b05: type = pattern_type String [concrete]
  40. // CHECK:STDOUT: %str: String = string_literal "hello" [concrete]
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT:
  43. // CHECK:STDOUT: imports {
  44. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  45. // CHECK:STDOUT: import Core//prelude
  46. // CHECK:STDOUT: import Core//prelude/...
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT:
  50. // CHECK:STDOUT: file {
  51. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  52. // CHECK:STDOUT: .Core = imports.%Core
  53. // CHECK:STDOUT: .X = %X.decl
  54. // CHECK:STDOUT: .F = %F.decl
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT: %Core.import = import Core
  57. // CHECK:STDOUT: %X.decl: type = class_decl @X [concrete = constants.%X] {} {}
  58. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  59. // CHECK:STDOUT: %x.patt: %pattern_type.019 = binding_pattern x [concrete]
  60. // CHECK:STDOUT: %x.param_patt: %pattern_type.019 = value_param_pattern %x.patt, call_param0 [concrete]
  61. // CHECK:STDOUT: } {
  62. // CHECK:STDOUT: %x.param: %X = value_param call_param0
  63. // CHECK:STDOUT: %X.ref.loc17: type = name_ref X, file.%X.decl [concrete = constants.%X]
  64. // CHECK:STDOUT: %x: %X = bind_name x, %x.param
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: class @X {
  69. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  70. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
  71. // CHECK:STDOUT: complete_type_witness = %complete_type
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: !members:
  74. // CHECK:STDOUT: .Self = constants.%X
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: fn @F(%x.param: %X) {
  78. // CHECK:STDOUT: !entry:
  79. // CHECK:STDOUT: name_binding_decl {
  80. // CHECK:STDOUT: %s.patt: %pattern_type.b05 = binding_pattern s [concrete]
  81. // CHECK:STDOUT: %s.var_patt: %pattern_type.b05 = var_pattern %s.patt [concrete]
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT: %s.var: ref String = var %s.var_patt
  84. // CHECK:STDOUT: %str: String = string_literal "hello" [concrete = constants.%str]
  85. // CHECK:STDOUT: assign %s.var, <error>
  86. // CHECK:STDOUT: %s: ref String = bind_name s, %s.var
  87. // CHECK:STDOUT: name_binding_decl {
  88. // CHECK:STDOUT: %y.patt: %pattern_type.019 = binding_pattern y [concrete]
  89. // CHECK:STDOUT: %y.var_patt: %pattern_type.019 = var_pattern %y.patt [concrete]
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT: %y.var: ref %X = var %y.var_patt
  92. // CHECK:STDOUT: %x.ref: %X = name_ref x, %x
  93. // CHECK:STDOUT: assign %y.var, <error>
  94. // CHECK:STDOUT: %X.ref.loc31: type = name_ref X, file.%X.decl [concrete = constants.%X]
  95. // CHECK:STDOUT: %y: ref %X = bind_name y, %y.var
  96. // CHECK:STDOUT: return
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT: