fail_name_lookup.carbon 1.1 KB

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