fail_not_copyable.carbon 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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`.
  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+3]]:14: ERROR: Cannot copy value of type `X`.
  22. // CHECK:STDERR: var y: X = x;
  23. // CHECK:STDERR: ^
  24. var y: X = x;
  25. }
  26. // CHECK:STDOUT: --- fail_not_copyable.carbon
  27. // CHECK:STDOUT:
  28. // CHECK:STDOUT: constants {
  29. // CHECK:STDOUT: %X: type = class_type @X [template]
  30. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  31. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  32. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  33. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  34. // CHECK:STDOUT: %.3: type = ptr_type %.1 [template]
  35. // CHECK:STDOUT: %.4: type = ptr_type String [template]
  36. // CHECK:STDOUT: %.5: String = string_literal "hello" [template]
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT:
  39. // CHECK:STDOUT: file {
  40. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  41. // CHECK:STDOUT: .Core = %Core
  42. // CHECK:STDOUT: .X = %X.decl
  43. // CHECK:STDOUT: .F = %F.decl
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  46. // CHECK:STDOUT: %X.decl: type = class_decl @X [template = constants.%X] {}
  47. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  48. // CHECK:STDOUT: %X.ref: type = name_ref X, %X.decl [template = constants.%X]
  49. // CHECK:STDOUT: %x.loc14_6.1: %X = param x
  50. // CHECK:STDOUT: @F.%x: %X = bind_name x, %x.loc14_6.1
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: class @X {
  55. // CHECK:STDOUT: !members:
  56. // CHECK:STDOUT: .Self = constants.%X
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: fn @F(%x: %X) {
  60. // CHECK:STDOUT: !entry:
  61. // CHECK:STDOUT: %s.var: ref String = var s
  62. // CHECK:STDOUT: %s: ref String = bind_name s, %s.var
  63. // CHECK:STDOUT: %.loc21: String = string_literal "hello" [template = constants.%.5]
  64. // CHECK:STDOUT: assign %s.var, <error>
  65. // CHECK:STDOUT: %X.ref: type = name_ref X, file.%X.decl [template = constants.%X]
  66. // CHECK:STDOUT: %y.var: ref %X = var y
  67. // CHECK:STDOUT: %y: ref %X = bind_name y, %y.var
  68. // CHECK:STDOUT: %x.ref: %X = name_ref x, %x
  69. // CHECK:STDOUT: assign %y.var, <error>
  70. // CHECK:STDOUT: return
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT: