bit_and.carbon 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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/full.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/operators/builtin/bit_and.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/operators/builtin/bit_and.carbon
  12. // --- bit_and_facet_types.carbon
  13. library "[[@TEST_NAME]]";
  14. interface I {}
  15. interface J {}
  16. fn F1[T:! I & J](t: T) {}
  17. fn F2[T:! I & I](t: T) {}
  18. // --- fail_bit_and_non_facet_types.carbon
  19. library "[[@TEST_NAME]]";
  20. interface I {}
  21. class J {}
  22. class K {}
  23. // CHECK:STDERR: fail_bit_and_non_facet_types.carbon:[[@LINE+4]]:11: error: non-facet type `J` combined with `&` operator [FacetTypeRequiredForTypeAndOperator]
  24. // CHECK:STDERR: fn F1[T:! I & J](t: T) {}
  25. // CHECK:STDERR: ^~~~~
  26. // CHECK:STDERR:
  27. fn F1[T:! I & J](t: T) {}
  28. // CHECK:STDERR: fail_bit_and_non_facet_types.carbon:[[@LINE+4]]:11: error: non-facet type `J` combined with `&` operator [FacetTypeRequiredForTypeAndOperator]
  29. // CHECK:STDERR: fn F2[T:! J & I](t: T) {}
  30. // CHECK:STDERR: ^~~~~
  31. // CHECK:STDERR:
  32. fn F2[T:! J & I](t: T) {}
  33. // CHECK:STDERR: fail_bit_and_non_facet_types.carbon:[[@LINE+8]]:11: error: non-facet type `J` combined with `&` operator [FacetTypeRequiredForTypeAndOperator]
  34. // CHECK:STDERR: fn F3[T:! J & K](t: T) {}
  35. // CHECK:STDERR: ^~~~~
  36. // CHECK:STDERR:
  37. // CHECK:STDERR: fail_bit_and_non_facet_types.carbon:[[@LINE+4]]:11: error: non-facet type `K` combined with `&` operator [FacetTypeRequiredForTypeAndOperator]
  38. // CHECK:STDERR: fn F3[T:! J & K](t: T) {}
  39. // CHECK:STDERR: ^~~~~
  40. // CHECK:STDERR:
  41. fn F3[T:! J & K](t: T) {}
  42. // --- bit_and_values_with_impl.carbon
  43. library "[[@TEST_NAME]]";
  44. class J { adapt {}; }
  45. impl J as Core.BitAndWith(J) where .Result = J {
  46. fn Op[self: Self](other: Self) -> Self { return {} as J; }
  47. }
  48. fn F() {
  49. let a: J = {} as J;
  50. let b: J = {} as J;
  51. a & b;
  52. }
  53. // --- fail_bit_and_values_no_impl.carbon
  54. library "[[@TEST_NAME]]";
  55. class J { adapt {}; }
  56. fn F() {
  57. let a: J = {} as J;
  58. let b: J = {} as J;
  59. // CHECK:STDERR: fail_bit_and_values_no_impl.carbon:[[@LINE+4]]:3: error: cannot access member of interface `Core.BitAndWith(J)` in type `J` that does not implement that interface [MissingImplInMemberAccess]
  60. // CHECK:STDERR: a & b;
  61. // CHECK:STDERR: ^~~~~
  62. // CHECK:STDERR:
  63. a & b;
  64. }