10d1744fbabedd2d7b67aeeba5ccfad33dde54eb 935 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. package ExplorerTest api;
  7. // TODO: Implement this with some kind of reflection?
  8. impl {.x: i32, .y: i32} as EqWith(Self) {
  9. fn Equal[self: Self](other: Self) -> bool {
  10. return self.x == other.x and self.y == other.y;
  11. }
  12. fn NotEqual[self: Self](other: Self) -> bool {
  13. return self.x != other.x or self.y != other.y;
  14. }
  15. }
  16. fn Main() -> i32 {
  17. var t1: {.x: i32, .y: i32} = {.x = 5, .y = 2};
  18. var t2: {.x: i32,} = {.x = 5,};
  19. // CHECK:STDERR: COMPILATION ERROR: fail_equality_type.carbon:[[@LINE+1]]: {.x: i32, .y: i32} is not equality comparable with {.x: i32} (could not find implementation of interface EqWith(U = {.x: i32}) for {.x: i32, .y: i32})
  20. if (t1 == t2) {
  21. return 1;
  22. } else {
  23. return 0;
  24. }
  25. }