fail_method_let.carbon 761 B

123456789101112131415161718192021222324252627282930313233
  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 api;
  7. class Point {
  8. fn Origin() -> Point {
  9. return {.x = 0, .y = 0};
  10. }
  11. fn GetSetX[addr self: Point*](x: i32) -> i32 {
  12. var old: auto = (*self).x;
  13. (*self).x = x;
  14. return old;
  15. }
  16. var x: i32;
  17. var y: i32;
  18. }
  19. fn Main() -> i32 {
  20. let p: Point = Point.Origin();
  21. // CHECK:STDERR: COMPILATION ERROR: explorer/testdata/addr/fail_method_let.carbon:[[@LINE+1]]: method p.GetSetX requires its receiver to be a reference expression
  22. var x: auto = p.GetSetX(42);
  23. if (p.x == 42) {
  24. return x;
  25. }
  26. return 1;
  27. }