fail_not_copyable.carbon 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. class X {
  7. }
  8. fn F(x: X) {
  9. // TODO: Strings should eventually be copyable, once we decide how to
  10. // represent them.
  11. // CHECK:STDERR: fail_not_copyable.carbon:[[@LINE+4]]:19: ERROR: Cannot copy value of type `String`.
  12. // CHECK:STDERR: var s: String = "hello";
  13. // CHECK:STDERR: ^~~~~~~
  14. // CHECK:STDERR:
  15. var s: String = "hello";
  16. // TODO: Decide on rules for when classes are copyable.
  17. // CHECK:STDERR: fail_not_copyable.carbon:[[@LINE+3]]:14: ERROR: Cannot copy value of type `X`.
  18. // CHECK:STDERR: var y: X = x;
  19. // CHECK:STDERR: ^
  20. var y: X = x;
  21. }
  22. // CHECK:STDOUT: --- fail_not_copyable.carbon
  23. // CHECK:STDOUT:
  24. // CHECK:STDOUT: constants {
  25. // CHECK:STDOUT: %X: type = class_type @X [template]
  26. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  27. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  28. // CHECK:STDOUT: %.3: type = ptr_type {} [template]
  29. // CHECK:STDOUT: %.4: type = ptr_type String [template]
  30. // CHECK:STDOUT: %.5: String = string_literal "hello" [template]
  31. // CHECK:STDOUT: }
  32. // CHECK:STDOUT:
  33. // CHECK:STDOUT: file {
  34. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  35. // CHECK:STDOUT: .X = %X.decl
  36. // CHECK:STDOUT: .F = %F
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT: %X.decl: type = class_decl @X [template = constants.%X] {}
  39. // CHECK:STDOUT: %F: <function> = fn_decl @F [template] {
  40. // CHECK:STDOUT: %X.ref: type = name_ref X, %X.decl [template = constants.%X]
  41. // CHECK:STDOUT: %x.loc10_6.1: X = param x
  42. // CHECK:STDOUT: @F.%x: X = bind_name x, %x.loc10_6.1
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: class @X {
  47. // CHECK:STDOUT: !members:
  48. // CHECK:STDOUT: .Self = constants.%X
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: fn @F(%x: X) {
  52. // CHECK:STDOUT: !entry:
  53. // CHECK:STDOUT: %s.var: ref String = var s
  54. // CHECK:STDOUT: %s: ref String = bind_name s, %s.var
  55. // CHECK:STDOUT: %.loc17: String = string_literal "hello" [template = constants.%.5]
  56. // CHECK:STDOUT: assign %s.var, <error>
  57. // CHECK:STDOUT: %X.ref: type = name_ref X, file.%X.decl [template = constants.%X]
  58. // CHECK:STDOUT: %y.var: ref X = var y
  59. // CHECK:STDOUT: %y: ref X = bind_name y, %y.var
  60. // CHECK:STDOUT: %x.ref: X = name_ref x, %x
  61. // CHECK:STDOUT: assign %y.var, <error>
  62. // CHECK:STDOUT: return
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT: