function.carbon 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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/interop/cpp/reverse/function.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/reverse/function.carbon
  12. // --- other.carbon
  13. package Other;
  14. fn F1() {}
  15. fn F2() -> i32 { return 0; }
  16. fn F3(_: i32) {}
  17. // --- function.carbon
  18. library "[[@TEST_NAME]]";
  19. import Other;
  20. import Cpp inline '''
  21. void G() {
  22. Carbon::Other::F1();
  23. }
  24. ''';
  25. // --- fail_todo_non_void.carbon
  26. library "[[@TEST_NAME]]";
  27. // CHECK:STDERR: fail_todo_non_void.carbon:[[@LINE+5]]:1: in import [InImport]
  28. // CHECK:STDERR: other.carbon:4:1: error: semantics TODO: `unsupported: C++ calling a Carbon function with return type other than `()`` [SemanticsTodo]
  29. // CHECK:STDERR: fn F2() -> i32 { return 0; }
  30. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  31. // CHECK:STDERR:
  32. import Other;
  33. import Cpp inline '''
  34. void G() {
  35. // CHECK:STDERR: fail_todo_non_void.carbon:[[@LINE+4]]:18: error: no member named 'F2' in namespace 'Carbon::Other' [CppInteropParseError]
  36. // CHECK:STDERR: 16 | Carbon::Other::F2();
  37. // CHECK:STDERR: | ^~
  38. // CHECK:STDERR:
  39. Carbon::Other::F2();
  40. }
  41. ''';
  42. // --- fail_todo_args.carbon
  43. library "[[@TEST_NAME]]";
  44. // CHECK:STDERR: fail_todo_args.carbon:[[@LINE+5]]:1: in import [InImport]
  45. // CHECK:STDERR: other.carbon:5:1: error: semantics TODO: `unsupported: C++ calling a Carbon function with parameters` [SemanticsTodo]
  46. // CHECK:STDERR: fn F3(_: i32) {}
  47. // CHECK:STDERR: ^~~~~~~~~~~~~~~
  48. // CHECK:STDERR:
  49. import Other;
  50. import Cpp inline '''
  51. void G() {
  52. // CHECK:STDERR: fail_todo_args.carbon:[[@LINE+4]]:18: error: no member named 'F3' in namespace 'Carbon::Other' [CppInteropParseError]
  53. // CHECK:STDERR: 16 | Carbon::Other::F3();
  54. // CHECK:STDERR: | ^~
  55. // CHECK:STDERR:
  56. Carbon::Other::F3();
  57. }
  58. ''';