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