impl_lookup.carbon 862 B

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