convert_condition.carbon 601 B

123456789101112131415161718192021222324252627282930
  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. if (LazyEq.Make(2, 1 + 1)) {
  21. return 1;
  22. } else {
  23. return 2;
  24. }
  25. }
  26. // CHECK:STDOUT: result: 1