fail_impl_bad_member.carbon 1.1 KB

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. 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. impl Point as Vector {
  15. fn Add[self: Point](b: Point) -> Point {
  16. return {.x = self.x + b.x, .y = self.y + b.y};
  17. }
  18. fn Scale[self: Point](v: i32) -> i32 {
  19. return 0;
  20. // CHECK:STDERR: COMPILATION ERROR: explorer/testdata/interface/fail_impl_bad_member.carbon:[[@LINE+3]]: type error in member of implementation
  21. // CHECK:STDERR: expected: fn (i32,) -> class Point
  22. // CHECK:STDERR: actual: fn (i32,) -> i32
  23. }
  24. }
  25. }
  26. fn AddAndScaleGeneric[T:! Vector](a: T, b: T, s: i32) -> T {
  27. var m: auto = a.Add;
  28. var n: auto = m(b).Scale;
  29. return n(s);
  30. }
  31. fn Main() -> i32 {
  32. var a: Point = {.x = 0, .y = 0};
  33. var b: Point = {.x = 2, .y = 3};
  34. var p: Point = AddAndScaleGeneric(a, b, 3);
  35. return p.x - 6;
  36. }