use-mixin-method-in-class-method.carbon 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. // RUN: %{explorer} %s 2>&1 | \
  6. // RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes=false %s
  7. // RUN: %{explorer} --parser_debug --trace_file=- %s 2>&1 | \
  8. // RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s
  9. // AUTOUPDATE: %{explorer} %s
  10. // CHECK: result: 0
  11. package ExplorerTest api;
  12. __mixin Operations {
  13. fn Square[me: Self](x:i32) -> i32{
  14. return x * x;
  15. }
  16. }
  17. class Point {
  18. var x: i32;
  19. var y: i32;
  20. fn DistanceSquare[me:Self](other:Self) -> i32 {
  21. return me.Square(me.x - other.x) + me.Square(me.y - other.y);
  22. }
  23. __mix Operations;
  24. }
  25. class Complex {
  26. var r: i32;
  27. var i: i32;
  28. __mix Operations;
  29. fn AbsSquare[me:Self]() -> i32 {
  30. return me.Square(me.r) + me.Square(me.i);
  31. }
  32. }
  33. fn Main() -> i32 {
  34. var p1: Point = {.x = 1, .y = 2 };
  35. var p2: Point = {.x = 4, .y = 3 };
  36. var c: Complex = {.r = 5, .i = 6 };
  37. return c.AbsSquare() - p1.DistanceSquare(p2) - 51;
  38. }