fail_not_copyable.carbon 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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: %F: type = fn_type @F [template]
  28. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  29. // CHECK:STDOUT: %struct: F = struct_value () [template]
  30. // CHECK:STDOUT: %.3: type = ptr_type {} [template]
  31. // CHECK:STDOUT: %.4: type = ptr_type String [template]
  32. // CHECK:STDOUT: %.5: String = string_literal "hello" [template]
  33. // CHECK:STDOUT: }
  34. // CHECK:STDOUT:
  35. // CHECK:STDOUT: file {
  36. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  37. // CHECK:STDOUT: .Core = %Core
  38. // CHECK:STDOUT: .X = %X.decl
  39. // CHECK:STDOUT: .F = %F.decl
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  42. // CHECK:STDOUT: %X.decl: type = class_decl @X [template = constants.%X] {}
  43. // CHECK:STDOUT: %F.decl: F = fn_decl @F [template = constants.%struct] {
  44. // CHECK:STDOUT: %X.ref: type = name_ref X, %X.decl [template = constants.%X]
  45. // CHECK:STDOUT: %x.loc10_6.1: X = param x
  46. // CHECK:STDOUT: @F.%x: X = bind_name x, %x.loc10_6.1
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT:
  50. // CHECK:STDOUT: class @X {
  51. // CHECK:STDOUT: !members:
  52. // CHECK:STDOUT: .Self = constants.%X
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: fn @F(%x: X) {
  56. // CHECK:STDOUT: !entry:
  57. // CHECK:STDOUT: %s.var: ref String = var s
  58. // CHECK:STDOUT: %s: ref String = bind_name s, %s.var
  59. // CHECK:STDOUT: %.loc17: String = string_literal "hello" [template = constants.%.5]
  60. // CHECK:STDOUT: assign %s.var, <error>
  61. // CHECK:STDOUT: %X.ref: type = name_ref X, file.%X.decl [template = constants.%X]
  62. // CHECK:STDOUT: %y.var: ref X = var y
  63. // CHECK:STDOUT: %y: ref X = bind_name y, %y.var
  64. // CHECK:STDOUT: %x.ref: X = name_ref x, %x
  65. // CHECK:STDOUT: assign %y.var, <error>
  66. // CHECK:STDOUT: return
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT: