implicit_conversion_choice.carbon 444 B

123456789101112131415161718192021
  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: 3
  7. package ExplorerTest api;
  8. choice A {
  9. Value(i32)
  10. }
  11. impl i32 as ImplicitAs(A) {
  12. fn Convert[self: Self]() -> A { return A.Value(self + 1); }
  13. }
  14. fn Main() -> i32 {
  15. let A.Value(n: i32) = 2;
  16. return n;
  17. }