fail_not_copyable.carbon 4.1 KB

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