fail_external_impl_self.carbon 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. }
  17. // CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/interface/fail_external_impl_self.carbon:[[@LINE+1]]: could not resolve 'Self'
  18. external impl Self 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) -> Point {
  23. return {.x = me.x * v, .y = me.y * v};
  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 = 1, .y = 4};
  33. var b: Point = {.x = 2, .y = 3};
  34. var p: Point = AddAndScaleGeneric(a, b, 5);
  35. return p.x - 15;
  36. }