fail_init_as_inplace.carbon 1.4 KB

123456789101112131415161718192021222324252627282930313233
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/int.carbon
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/fail_init_as_inplace.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/fail_init_as_inplace.carbon
  12. class Class {
  13. var a: i32;
  14. var b: i32;
  15. }
  16. fn G(p: Class*);
  17. fn F() {
  18. // TODO: This case should presumably work: `{...} as Class` should be an
  19. // initializing expression, not a value expression.
  20. //
  21. // CHECK:STDERR: fail_init_as_inplace.carbon:[[@LINE+7]]:18: error: cannot copy value of type `Class` [CopyOfUncopyableType]
  22. // CHECK:STDERR: var c: Class = {.a = 1, .b = 2} as Class;
  23. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
  24. // CHECK:STDERR: fail_init_as_inplace.carbon:[[@LINE+4]]:18: note: type `Class` does not implement interface `Core.Copy` [MissingImplInMemberAccessNote]
  25. // CHECK:STDERR: var c: Class = {.a = 1, .b = 2} as Class;
  26. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
  27. // CHECK:STDERR:
  28. var c: Class = {.a = 1, .b = 2} as Class;
  29. G(&c);
  30. }