unsafe_as.carbon 1.2 KB

1234567891011121314151617181920212223242526272829
  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/unformed.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/as/unsafe_as.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/as/unsafe_as.carbon
  12. // --- fail_no_conversion.carbon
  13. library "[[@TEST_NAME]]";
  14. class A {};
  15. class B {};
  16. fn Convert(a: A) -> B {
  17. // CHECK:STDERR: fail_no_conversion.carbon:[[@LINE+7]]:10: error: cannot convert expression of type `A` to `B` with `unsafe as` [ConversionFailure]
  18. // CHECK:STDERR: return a unsafe as B;
  19. // CHECK:STDERR: ^~~~~~~~~~~~~
  20. // CHECK:STDERR: fail_no_conversion.carbon:[[@LINE+4]]:10: note: type `A` does not implement interface `Core.UnsafeAs(B)` [MissingImplInMemberAccessNote]
  21. // CHECK:STDERR: return a unsafe as B;
  22. // CHECK:STDERR: ^~~~~~~~~~~~~
  23. // CHECK:STDERR:
  24. return a unsafe as B;
  25. }