2e05abea6fd46fc2b5315dca60d3b56e5b407fd4 826 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. package ExplorerTest;
  7. class Shape {
  8. var x: i32;
  9. }
  10. class Point {
  11. fn Origin() -> Point {
  12. return {.x = 0, .y = 0};
  13. }
  14. fn GetSetX[addr self: Shape*](x: i32) -> i32 {
  15. var old: auto = (*self).x;
  16. (*self).x = x;
  17. return old;
  18. }
  19. var x: i32;
  20. var y: i32;
  21. }
  22. fn Main() -> i32 {
  23. var p: Point = Point.Origin();
  24. // CHECK:STDERR: COMPILATION ERROR: fail_method_self_type.carbon:[[@LINE+3]]: type error in method access, receiver type
  25. // CHECK:STDERR: expected: class Shape
  26. // CHECK:STDERR: actual: class Point
  27. var x: auto = p.GetSetX(42);
  28. if (p.x == 42) {
  29. return x;
  30. }
  31. return 1;
  32. }