fail_unambiguous_impl_generic.carbon 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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(T:! Type) {
  12. fn Add[me: Self](b: Self) -> Self;
  13. fn Scale[me: Self](v: T) -> Self;
  14. }
  15. class Point(T:! Type) {
  16. var x: T;
  17. var y: T;
  18. }
  19. external impl Point(i32) as Vector(i32) {
  20. fn Add[me: Self](b: Self) -> Self {
  21. return {.x = me.x + b.x, .y = me.y + b.y};
  22. }
  23. fn Scale[me: Self](v: i32) -> Self {
  24. return {.x = me.x * v, .y = me.y * v};
  25. }
  26. }
  27. external impl forall [T:! Type] Point(T) as Vector(T) {
  28. fn Add[me: Self](b: Self) -> Self {
  29. return me;
  30. }
  31. fn Scale[me: Self](v: T) -> Self {
  32. return me;
  33. }
  34. }
  35. fn AddAndScaleGeneric[T:! Vector(i32)](a: T, b: T, s: i32) -> T {
  36. return a.Add(b).Scale(s);
  37. }
  38. fn Main() -> i32 {
  39. var a: Point(i32) = {.x = 1, .y = 1};
  40. var b: Point(i32) = {.x = 2, .y = 3};
  41. // TODO: This shouldn't be considered ambiguous.
  42. // CHECK: COMPILATION ERROR: {{.*}}/explorer/testdata/impl/fail_unambiguous_impl_generic.carbon:[[@LINE+1]]: ambiguous implementations of interface Vector(T = i32) for class Point(T = i32)
  43. var p: Point(i32) = AddAndScaleGeneric(a, b, 5);
  44. return p.x - 15;
  45. }