convert_condition.carbon 576 B

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