fail_impl_bad_member.carbon 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. // RUN: %{not} %{explorer} %s 2>&1 | \
  6. // RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes=false %s
  7. // RUN: %{not} %{explorer} --parser_debug --trace_file=- %s 2>&1 | \
  8. // RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s
  9. // AUTOUPDATE: %{explorer} %s
  10. package ExplorerTest api;
  11. interface Vector {
  12. fn Add[me: Self](b: Self) -> Self;
  13. fn Scale[me: Self](v: i32) -> Self;
  14. }
  15. class Point {
  16. var x: i32;
  17. var y: i32;
  18. impl Point as Vector {
  19. fn Add[me: Point](b: Point) -> Point {
  20. return {.x = me.x + b.x, .y = me.y + b.y};
  21. }
  22. fn Scale[me: Point](v: i32) -> i32 {
  23. return 0;
  24. // CHECK: COMPILATION ERROR: {{.*}}/explorer/testdata/interface/fail_impl_bad_member.carbon:[[@LINE+3]]: type error in member of implementation
  25. // CHECK: expected: fn (i32) -> class Point
  26. // CHECK: actual: fn (i32) -> i32
  27. }
  28. }
  29. }
  30. fn AddAndScaleGeneric[T:! Vector](a: T, b: T, s: i32) -> T {
  31. var m: auto = a.Add;
  32. var n: auto = m(b).Scale;
  33. return n(s);
  34. }
  35. fn Main() -> i32 {
  36. var a: Point = {.x = 0, .y = 0};
  37. var b: Point = {.x = 2, .y = 3};
  38. var p: Point = AddAndScaleGeneric(a, b, 3);
  39. return p.x - 6;
  40. }