fail_self_substitution.carbon 960 B

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. __mixin Operations {
  10. fn F[self: Self](x: Self) -> Self{
  11. return x;
  12. }
  13. }
  14. class Point {
  15. fn Origin() -> Point {
  16. return {.x = 0, .y = 0};
  17. }
  18. var x: i32;
  19. var y: i32;
  20. __mix Operations;
  21. }
  22. class Complex {
  23. fn Zero() -> Complex {
  24. return {.r = 0, .i = 0};
  25. }
  26. var r: i32;
  27. var i: i32;
  28. }
  29. fn Main() -> i32 {
  30. var p: Point = Point.Origin();
  31. var c: Complex = {.r = 42, .i = 1};
  32. // CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/mixin/fail_self_substitution.carbon:[[@LINE+1]]: mismatch in non-deduced types, `class Complex` is not implicitly convertible to `class Point`
  33. var p1: Point = p.F(c);
  34. return p1.x - 42;
  35. }