fail_memaccess_category.carbon 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/convert.carbon
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/fail_memaccess_category.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/fail_memaccess_category.carbon
  12. class A {
  13. fn F[addr self: A*]();
  14. }
  15. class B {
  16. var a: A;
  17. }
  18. fn F(s: {.a: A}, b: B) {
  19. // `s` has only a value representation, so this must be invalid.
  20. // CHECK:STDERR: fail_memaccess_category.carbon:[[@LINE+7]]:3: error: `addr self` method cannot be invoked on a value [AddrSelfIsNonRef]
  21. // CHECK:STDERR: s.a.F();
  22. // CHECK:STDERR: ^~~
  23. // CHECK:STDERR: fail_memaccess_category.carbon:[[@LINE-12]]:8: note: initializing function parameter [InCallToFunctionParam]
  24. // CHECK:STDERR: fn F[addr self: A*]();
  25. // CHECK:STDERR: ^~~~~~~~~~~~~
  26. // CHECK:STDERR:
  27. s.a.F();
  28. // `b` has an object representation for `A`, but this is still invalid for
  29. // consistency.
  30. // CHECK:STDERR: fail_memaccess_category.carbon:[[@LINE+7]]:3: error: `addr self` method cannot be invoked on a value [AddrSelfIsNonRef]
  31. // CHECK:STDERR: b.a.F();
  32. // CHECK:STDERR: ^~~
  33. // CHECK:STDERR: fail_memaccess_category.carbon:[[@LINE-23]]:8: note: initializing function parameter [InCallToFunctionParam]
  34. // CHECK:STDERR: fn F[addr self: A*]();
  35. // CHECK:STDERR: ^~~~~~~~~~~~~
  36. // CHECK:STDERR:
  37. b.a.F();
  38. }