fail_method_let.carbon 888 B

1234567891011121314151617181920212223242526272829303132333435
  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 | %{FileCheck-strict} %s
  6. // RUN: %{not} %{explorer-trace} %s | %{FileCheck-allow-unmatched} %s
  7. // AUTOUPDATE: %{explorer} %s
  8. package ExplorerTest api;
  9. class Point {
  10. fn Origin() -> Point {
  11. return {.x = 0, .y = 0};
  12. }
  13. fn GetSetX[addr me: Point*](x: i32) -> i32 {
  14. var old: auto = (*me).x;
  15. (*me).x = x;
  16. return old;
  17. }
  18. var x: i32;
  19. var y: i32;
  20. }
  21. fn Main() -> i32 {
  22. let p: Point = Point.Origin();
  23. // CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/addr/fail_method_let.carbon:[[@LINE+1]]: method GetSetX requires its receiver to be an lvalue
  24. var x: auto = p.GetSetX(42);
  25. if (p.x == 42) {
  26. return x;
  27. }
  28. return 1;
  29. }