fail_impl_bad_member.carbon 1.1 KB

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