impl_as_not_self.carbon 646 B

12345678910111213141516171819202122232425262728
  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: 5
  7. package ExplorerTest api;
  8. interface ConvertsFromInt {
  9. impl i32 as ImplicitAs(Self);
  10. }
  11. fn ConvertIntTo(T:! ConvertsFromInt, n: i32) -> T {
  12. return n;
  13. }
  14. class IntHolder {
  15. var n: i32;
  16. }
  17. external impl i32 as ImplicitAs(IntHolder) {
  18. fn Convert[self: Self]() -> IntHolder { return {.n = self}; }
  19. }
  20. external impl IntHolder as ConvertsFromInt {}
  21. fn Main() -> i32 {
  22. return ConvertIntTo(IntHolder, 5).n;
  23. }