convert_condition.carbon 647 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: 1
  9. package ExplorerTest api;
  10. class LazyEq {
  11. var v1: i32;
  12. var v2: i32;
  13. impl as ImplicitAs(bool) {
  14. fn Convert[self: Self]() -> bool {
  15. return self.v1 == self.v2;
  16. }
  17. }
  18. fn Make(v1: i32, v2: i32) -> Self {
  19. return {.v1 = v1, .v2 = v2};
  20. }
  21. }
  22. fn Main() -> i32 {
  23. if (LazyEq.Make(2, 1 + 1)) {
  24. return 1;
  25. } else {
  26. return 2;
  27. }
  28. }