bit_or.carbon 614 B

12345678910111213141516171819202122232425262728
  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. // NOAUTOUPDATE
  6. package ExplorerTest api;
  7. class A { var n: i32; }
  8. impl A as BitOrWith(i32) where .Result = A {
  9. fn Op[self: Self](rhs: i32) -> A { return {.n = self.n | rhs}; }
  10. }
  11. fn Main() -> i32 {
  12. var a: A = {.n = 1};
  13. a = a | 2;
  14. Print("{0}", a.n);
  15. a |= 5;
  16. Print("{0}", a.n);
  17. Print("{0}", (a | 12).n);
  18. return 0;
  19. }
  20. // CHECK:STDOUT: 3
  21. // CHECK:STDOUT: 7
  22. // CHECK:STDOUT: 15
  23. // CHECK:STDOUT: result: 0