fail_interface_missing_member.carbon 924 B

12345678910111213141516171819202122232425262728293031323334
  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 Vector {
  10. fn Add[self: Self](b: Self) -> Self;
  11. }
  12. fn ScaleGeneric[T:! Vector](a: T, s: i32) -> T {
  13. // CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/interface/fail_interface_missing_member.carbon:[[@LINE+1]]: member access, Scale not in interface Vector where T is interface Vector
  14. return a.Scale(s);
  15. }
  16. class Point {
  17. var x: i32;
  18. var y: i32;
  19. impl Point as Vector {
  20. fn Add[self: Point](b: Point) -> Point {
  21. return {.x = self.x + b.x, .y = self.y + b.y};
  22. }
  23. }
  24. }
  25. fn Main() -> i32 {
  26. var a: Point = {.x = 3, .y = 1};
  27. var b: Point = ScaleGeneric(a, 2);
  28. return b.x - 6;
  29. }