use_mixin_method_in_class_method.carbon 895 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. __mixin Operations {
  9. fn Square[self: Self](x:i32) -> i32{
  10. return x * x;
  11. }
  12. }
  13. class Point {
  14. var x: i32;
  15. var y: i32;
  16. fn DistanceSquare[self: Self](other:Self) -> i32 {
  17. return self.Square(self.x - other.x) + self.Square(self.y - other.y);
  18. }
  19. __mix Operations;
  20. }
  21. class Complex {
  22. var r: i32;
  23. var i: i32;
  24. __mix Operations;
  25. fn AbsSquare[self: Self]() -> i32 {
  26. return self.Square(self.r) + self.Square(self.i);
  27. }
  28. }
  29. fn Main() -> i32 {
  30. var p1: Point = {.x = 1, .y = 2 };
  31. var p2: Point = {.x = 4, .y = 3 };
  32. var c: Complex = {.r = 5, .i = 6 };
  33. return c.AbsSquare() - p1.DistanceSquare(p2) - 51;
  34. }