impl_lookup.carbon 816 B

12345678910111213141516171819202122232425262728293031323334353637
  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 Frob {
  8. let Result:! type;
  9. fn F[self: Self]() -> Result;
  10. }
  11. fn Use[T:! Frob](x: T) -> T.Result {
  12. var v: T.Result = x.F();
  13. return v;
  14. }
  15. class AlmostI32 {
  16. var val: i32;
  17. extend impl as ImplicitAs(i32) {
  18. fn Convert[self: Self]() -> i32 { return self.val; }
  19. }
  20. }
  21. impl i32 as Frob where .Result = AlmostI32 {
  22. fn F[self: Self]() -> AlmostI32 { return {.val = self}; }
  23. }
  24. fn Main() -> i32 {
  25. // Ensure that lookup for
  26. // i32.(Frob.Result) as ImplicitAs(i32)
  27. // finds `impl AlmostI32 as ImplicitAs(i32)`.
  28. return Use(1);
  29. }
  30. // CHECK:STDOUT: result: 1