convert_condition.carbon 593 B

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