fail_name_lookup.carbon 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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: %{not} %{explorer-run}
  7. // RUN: %{not} %{explorer-run-trace}
  8. package ExplorerTest api;
  9. interface CallF {
  10. fn DoIt[self: Self]();
  11. }
  12. interface HasF {
  13. fn F[self: Self]();
  14. }
  15. impl forall [template T:! HasF] T as CallF {
  16. // TODO: This case should be accepted, using `ClassWithExternalF.(HasF.F)`.
  17. // TODO: The other case should be rejected due to ambiguity.
  18. // CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/template/fail_name_lookup.carbon:[[@LINE+1]]: class ClassWithExternalF does not have a field named F
  19. fn DoIt[self: Self]() { self.F(); }
  20. }
  21. class ClassWithInternalF {
  22. fn F[self: Self]() { Print("ClassWithInternalF.F"); }
  23. }
  24. external impl ClassWithInternalF as HasF {
  25. fn F[self: Self]() { Print("ClassWithInternalF.(HasF.F)"); }
  26. }
  27. class ClassWithExternalF {}
  28. external impl ClassWithExternalF as HasF {
  29. fn F[self: Self]() { Print("ClassWithExternalF.(HasF.F)"); }
  30. }
  31. fn Main() -> i32 {
  32. var a: ClassWithInternalF = {};
  33. var b: ClassWithExternalF = {};
  34. a.(CallF.DoIt)();
  35. b.(CallF.DoIt)();
  36. return 0;
  37. }