equality_false.carbon 758 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. // AUTOUPDATE
  6. // CHECK:STDOUT: result: 0
  7. package ExplorerTest api;
  8. // TODO: Implement this with some kind of reflection?
  9. external impl {.x: i32, .y: i32} as EqWith(Self) {
  10. fn Equal[self: Self](other: Self) -> bool {
  11. return self.x == other.x and self.y == other.y;
  12. }
  13. fn NotEqual[self: Self](other: Self) -> bool {
  14. return self.x != other.x or self.y != other.y;
  15. }
  16. }
  17. fn Main() -> i32 {
  18. var t1: {.x: i32, .y: i32} = {.x = 5, .y = 2};
  19. var t2: {.x: i32, .y: i32} = {.x = 5, .y = 4};
  20. if (t1 == t2) {
  21. return 1;
  22. } else {
  23. return 0;
  24. }
  25. }