fail_not_copyable.carbon 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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: %.2: <witness> = complete_type_witness %.1 [template]
  32. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  33. // CHECK:STDOUT: %.3: type = tuple_type () [template]
  34. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  35. // CHECK:STDOUT: %.4: type = ptr_type %.1 [template]
  36. // CHECK:STDOUT: %.5: type = ptr_type String [template]
  37. // CHECK:STDOUT: %.6: String = string_literal "hello" [template]
  38. // CHECK:STDOUT: }
  39. // CHECK:STDOUT:
  40. // CHECK:STDOUT: imports {
  41. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  42. // CHECK:STDOUT: import Core//prelude
  43. // CHECK:STDOUT: import Core//prelude/operators
  44. // CHECK:STDOUT: import Core//prelude/types
  45. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  46. // CHECK:STDOUT: import Core//prelude/operators/as
  47. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  48. // CHECK:STDOUT: import Core//prelude/operators/comparison
  49. // CHECK:STDOUT: import Core//prelude/types/bool
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: file {
  54. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  55. // CHECK:STDOUT: .Core = imports.%Core
  56. // CHECK:STDOUT: .X = %X.decl
  57. // CHECK:STDOUT: .F = %F.decl
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: %Core.import = import Core
  60. // CHECK:STDOUT: %X.decl: type = class_decl @X [template = constants.%X] {} {}
  61. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  62. // CHECK:STDOUT: %x.patt: %X = binding_pattern x
  63. // CHECK:STDOUT: %x.param_patt: %X = param_pattern %x.patt, runtime_param0
  64. // CHECK:STDOUT: } {
  65. // CHECK:STDOUT: %X.ref.loc14: type = name_ref X, file.%X.decl [template = constants.%X]
  66. // CHECK:STDOUT: %param: %X = param runtime_param0
  67. // CHECK:STDOUT: %x: %X = bind_name x, %param
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: class @X {
  72. // CHECK:STDOUT: %.loc12: <witness> = complete_type_witness %.1 [template = constants.%.2]
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: !members:
  75. // CHECK:STDOUT: .Self = constants.%X
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: fn @F(%x.param_patt: %X) {
  79. // CHECK:STDOUT: !entry:
  80. // CHECK:STDOUT: %s.var: ref String = var s
  81. // CHECK:STDOUT: %s: ref String = bind_name s, %s.var
  82. // CHECK:STDOUT: %.loc21: String = string_literal "hello" [template = constants.%.6]
  83. // CHECK:STDOUT: assign %s.var, <error>
  84. // CHECK:STDOUT: %X.ref.loc27: type = name_ref X, file.%X.decl [template = constants.%X]
  85. // CHECK:STDOUT: %y.var: ref %X = var y
  86. // CHECK:STDOUT: %y: ref %X = bind_name y, %y.var
  87. // CHECK:STDOUT: %x.ref: %X = name_ref x, %x
  88. // CHECK:STDOUT: assign %y.var, <error>
  89. // CHECK:STDOUT: return
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT: