bit_and.carbon 2.5 KB

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