mul.carbon 620 B

123456789101112131415161718192021222324252627
  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: 10
  7. // CHECK:STDOUT: 30
  8. // CHECK:STDOUT: 210
  9. // CHECK:STDOUT: result: 0
  10. package ExplorerTest api;
  11. class A { var n: i32; }
  12. external impl A as MulWith(i32) where .Result = A {
  13. fn Op[self: Self](rhs: i32) -> A { return {.n = self.n * rhs}; }
  14. }
  15. fn Main() -> i32 {
  16. var a: A = {.n = 5};
  17. a = a * 2;
  18. Print("{0}", a.n);
  19. a *= 3;
  20. Print("{0}", a.n);
  21. Print("{0}", (a * 7).n);
  22. return 0;
  23. }