impl_lookup.carbon 808 B

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