fail_interface_method_as_class_member.carbon 881 B

123456789101112131415161718192021222324252627282930313233343536373839
  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 Printable {
  8. fn PrintIt[self: Self]();
  9. }
  10. impl String as Printable {
  11. fn PrintIt[self: String]() {
  12. Print(self);
  13. }
  14. }
  15. class Vector(T:! type) {
  16. var x: T;
  17. alias PrintIt = Printable.PrintIt;
  18. }
  19. // Conditionally implement the API for certain `T`s.
  20. impl forall [U:! Printable] Vector(U) as Printable {
  21. fn PrintIt[self: Self]() {
  22. Print("{ ");
  23. self.x.PrintIt();
  24. Print(" }");
  25. }
  26. }
  27. fn Main() -> i32 {
  28. var v: Vector(String) = {.x = "test"};
  29. // CHECK:STDERR: COMPILATION ERROR: fail_interface_method_as_class_member.carbon:[[@LINE+1]]: Member access to aliases is not yet supported.
  30. v.PrintIt();
  31. return 42;
  32. }