fail_impl_missing_member.carbon 914 B

123456789101112131415161718192021222324252627282930313233343536
  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 Vector {
  8. fn Add[self: Self](b: Self) -> Self;
  9. fn Scale[self: Self](v: i32) -> Self;
  10. }
  11. class Point {
  12. var x: i32;
  13. var y: i32;
  14. extend impl as Vector {
  15. fn Add[self: Point](b: Point) -> Point {
  16. return {.x = self.x + b.x, .y = self.y + b.y};
  17. }
  18. // CHECK:STDERR: COMPILATION ERROR: fail_impl_missing_member.carbon:[[@LINE+1]]: implementation missing Scale
  19. }
  20. }
  21. fn AddAndScaleGeneric[T:! Vector](a: T, b: T, s: i32) -> T {
  22. var m: auto = a.Add;
  23. var n: auto = m(b).Scale;
  24. return n(s);
  25. }
  26. fn Main() -> i32 {
  27. var a: Point = {.x = 0, .y = 0};
  28. var b: Point = {.x = 2, .y = 3};
  29. var p: Point = AddAndScaleGeneric(a, b, 3);
  30. return p.x - 6;
  31. }