convert_run.carbon 643 B

12345678910111213141516171819202122232425262728293031
  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: 3
  9. package ExplorerTest api;
  10. class Wrap(T:! Type) {
  11. var v: T;
  12. }
  13. fn MakeWrap[T:! Type](x: T) -> Wrap(T) { return {.v = x}; }
  14. impl forall [T:! Type] Wrap(T) as ImplicitAs(T) {
  15. fn Convert[me: Self]() -> T {
  16. return me.v;
  17. }
  18. }
  19. fn Main() -> i32 {
  20. var n: i32 = 1;
  21. __continuation k {
  22. n = n + 1;
  23. }
  24. n = 2;
  25. __run MakeWrap(k);
  26. return n;
  27. }