fail_unbound_field.carbon 1.2 KB

123456789101112131415161718192021222324252627282930
  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/int.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_unbound_field.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/fail_unbound_field.carbon
  12. class Class {
  13. var field: i32;
  14. fn F() -> i32 {
  15. // CHECK:STDERR: fail_unbound_field.carbon:[[@LINE+4]]:12: error: expression cannot be used as a value [UseOfNonExprAsValue]
  16. // CHECK:STDERR: return field;
  17. // CHECK:STDERR: ^~~~~
  18. // CHECK:STDERR:
  19. return field;
  20. }
  21. }
  22. fn G() -> i32 {
  23. // CHECK:STDERR: fail_unbound_field.carbon:[[@LINE+4]]:10: error: expression cannot be used as a value [UseOfNonExprAsValue]
  24. // CHECK:STDERR: return Class.field;
  25. // CHECK:STDERR: ^~~~~~~~~~~
  26. // CHECK:STDERR:
  27. return Class.field;
  28. }