simple_mix_in_mixin.carbon 594 B

1234567891011121314151617181920212223242526272829303132
  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. // RUN: %{explorer-run}
  7. // RUN: %{explorer-run-trace}
  8. // CHECK:STDOUT: result: 0
  9. package ExplorerTest api;
  10. __mixin M1 {
  11. fn Scale10[self: Self](x:i32) -> i32{
  12. return x * 10;
  13. }
  14. }
  15. __mixin M2 {
  16. __mix M1;
  17. fn Square[self: Self](x:i32) -> i32{
  18. return x * x;
  19. }
  20. }
  21. class C {
  22. __mix M2;
  23. }
  24. fn Main() -> i32 {
  25. var c: C = {};
  26. return c.Square(11) - c.Scale10(10) - 21;
  27. }