fail_no_impl.carbon 767 B

1234567891011121314151617181920212223242526272829
  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. }
  15. fn AddAndScaleGeneric[T:! Vector](a: T, b: T, s: i32) -> T {
  16. return a.Add(b).Scale(s);
  17. }
  18. fn Main() -> i32 {
  19. var a: Point = {.x = 0, .y = 0};
  20. var b: Point = {.x = 2, .y = 3};
  21. // CHECK:STDERR: COMPILATION ERROR: fail_no_impl.carbon:[[@LINE+1]]: could not find implementation of interface Vector for class Point
  22. var p: Point = AddAndScaleGeneric(a, b, 3);
  23. return p.x - 6;
  24. }