convert_incomplete.carbon 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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/adapter/convert_incomplete.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/adapter/convert_incomplete.carbon
  12. // --- already_complete.carbon
  13. library "[[@TEST_NAME]]";
  14. class Adapter(T:! type) {
  15. extend adapt T*;
  16. }
  17. class X {}
  18. // Trigger completion of Adapter(X) here.
  19. var x: Adapter(X);
  20. fn F(p: Adapter(X)*) {
  21. let x: X* = *p as X*;
  22. }
  23. // --- can_be_completed.carbon
  24. library "[[@TEST_NAME]]";
  25. class Adapter(T:! type) {
  26. extend adapt T*;
  27. }
  28. class X {}
  29. fn F(p: Adapter(X)*) {
  30. // The conversion here triggers completion of Adapter(X)
  31. // so we can determine what it adapts.
  32. let x: X* = *p as X*;
  33. }
  34. // --- fail_incomplete.carbon
  35. library "[[@TEST_NAME]]";
  36. class Adapter(T:! type);
  37. class X {}
  38. fn F(p: Adapter(X)*) {
  39. // CHECK:STDERR: fail_incomplete.carbon:[[@LINE+7]]:15: error: cannot convert expression of type `Adapter(X)` to `X*` with `as` [ConversionFailure]
  40. // CHECK:STDERR: let x: X* = *p as X*;
  41. // CHECK:STDERR: ^~~~~~~~
  42. // CHECK:STDERR: fail_incomplete.carbon:[[@LINE+4]]:15: note: type `Adapter(X)` does not implement interface `Core.As(X*)` [MissingImplInMemberAccessNote]
  43. // CHECK:STDERR: let x: X* = *p as X*;
  44. // CHECK:STDERR: ^~~~~~~~
  45. // CHECK:STDERR:
  46. let x: X* = *p as X*;
  47. }