fail_interface_method_as_class_member.carbon 980 B

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