fail_interface_missing_member.carbon 827 B

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