fail_self_substitution.carbon 863 B

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