convert_condition.carbon 622 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. // 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. return if LazyEq.Make(2, 1 + 1) then 1 else 2;
  24. }