symbolic_facets.carbon 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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/convert.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/deduce/symbolic_facets.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/deduce/symbolic_facets.carbon
  12. // By placing each interface inside a generic class, a facet type refering to
  13. // the interface becomes symbolic. Normally they would be concrete. This can
  14. // affect decisions in deduce which unwraps symbolic values, but still needs to
  15. // ensure they convert correctly.
  16. // --- fail_missing_interface.carbon
  17. library "[[@TEST_NAME]]";
  18. class C(CC:! type) {
  19. interface A {}
  20. fn F(T:! A) {}
  21. }
  22. class D(DD:! type) {
  23. interface B {}
  24. fn G(T:! B) {
  25. // T only implements D(DD).B, so should not convert to a facet value
  26. // implementing C(()).A.
  27. //
  28. // CHECK:STDERR: fail_missing_interface.carbon:[[@LINE+7]]:5: error: cannot convert type `T` that implements `B` into type implementing `A` [ConversionFailureFacetToFacet]
  29. // CHECK:STDERR: C(()).F(T);
  30. // CHECK:STDERR: ^~~~~~~~~~
  31. // CHECK:STDERR: fail_missing_interface.carbon:[[@LINE-12]]:3: note: while deducing parameters of generic declared here [DeductionGenericHere]
  32. // CHECK:STDERR: fn F(T:! A) {}
  33. // CHECK:STDERR: ^~~~~~~~~~~~~
  34. // CHECK:STDERR:
  35. C(()).F(T);
  36. }
  37. }
  38. // --- fail_interface_wrong_generic_param.carbon
  39. library "[[@TEST_NAME]]";
  40. class C(CC:! type) {
  41. interface A {}
  42. fn F(T:! A) {}
  43. }
  44. class D(DD:! type) {
  45. interface B {}
  46. fn G(T:! B & C({}).A) {
  47. // T implements C({}).A and D(DD).B, so should not convert to a facet value
  48. // implementing C(()).A.
  49. //
  50. // CHECK:STDERR: fail_interface_wrong_generic_param.carbon:[[@LINE+7]]:5: error: cannot convert type `T` that implements `A & B` into type implementing `A` [ConversionFailureFacetToFacet]
  51. // CHECK:STDERR: C(()).F(T);
  52. // CHECK:STDERR: ^~~~~~~~~~
  53. // CHECK:STDERR: fail_interface_wrong_generic_param.carbon:[[@LINE-12]]:3: note: while deducing parameters of generic declared here [DeductionGenericHere]
  54. // CHECK:STDERR: fn F(T:! A) {}
  55. // CHECK:STDERR: ^~~~~~~~~~~~~
  56. // CHECK:STDERR:
  57. C(()).F(T);
  58. }
  59. }
  60. // --- compatible_deduce.carbon
  61. library "[[@TEST_NAME]]";
  62. class C(CC:! type) {
  63. interface A {}
  64. fn F(T:! A) {}
  65. }
  66. class D(DD:! type) {
  67. interface B {}
  68. fn G(T:! B & C(()).A) {
  69. C(()).F(T);
  70. }
  71. }