function.carbon 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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/function/export/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/function/export/function.carbon
  12. // --- other.carbon
  13. package Other;
  14. fn F1() {}
  15. fn F2() -> i32 { return 0; }
  16. fn F3(_: i32) {}
  17. fn HasGenericArg(T:! type, a: T) { a; }
  18. fn HasDeducedArg[T:! type](a: T) { a; }
  19. class C {
  20. fn Method[self: Self]() { self; }
  21. }
  22. // --- function.carbon
  23. library "[[@TEST_NAME]]";
  24. import Other;
  25. import Cpp inline '''
  26. void G() {
  27. Carbon::Other::F1();
  28. }
  29. ''';
  30. // --- return_int.carbon
  31. library "[[@TEST_NAME]]";
  32. import Other;
  33. import Cpp inline '''
  34. int G() {
  35. return Carbon::Other::F2();
  36. }
  37. ''';
  38. // --- args.carbon
  39. library "[[@TEST_NAME]]";
  40. import Other;
  41. import Cpp inline '''
  42. void G() {
  43. Carbon::Other::F3(123);
  44. }
  45. ''';
  46. // --- fail_todo_generic.carbon
  47. library "[[@TEST_NAME]]";
  48. // CHECK:STDERR: fail_todo_generic.carbon:[[@LINE+5]]:1: in import [InImport]
  49. // CHECK:STDERR: other.carbon:7:1: error: semantics TODO: `unsupported: C++ calling a Carbon function with generic parameters` [SemanticsTodo]
  50. // CHECK:STDERR: fn HasGenericArg(T:! type, a: T) { a; }
  51. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  52. // CHECK:STDERR:
  53. import Other;
  54. import Cpp inline '''
  55. void G() {
  56. // CHECK:STDERR: fail_todo_generic.carbon:[[@LINE+8]]:18: error: no member named 'HasGenericArg' in namespace 'Carbon::Other' [CppInteropParseError]
  57. // CHECK:STDERR: 20 | Carbon::Other::HasGenericArg<int>(123);
  58. // CHECK:STDERR: | ^~~~~~~~~~~~~
  59. // CHECK:STDERR:
  60. // CHECK:STDERR: fail_todo_generic.carbon:[[@LINE+4]]:35: error: expected '(' for function-style cast or type construction [CppInteropParseError]
  61. // CHECK:STDERR: 20 | Carbon::Other::HasGenericArg<int>(123);
  62. // CHECK:STDERR: | ~~~^
  63. // CHECK:STDERR:
  64. Carbon::Other::HasGenericArg<int>(123);
  65. }
  66. ''';
  67. // --- fail_todo_deduced.carbon
  68. library "[[@TEST_NAME]]";
  69. // CHECK:STDERR: fail_todo_deduced.carbon:[[@LINE+5]]:1: in import [InImport]
  70. // CHECK:STDERR: other.carbon:8:1: error: semantics TODO: `unsupported: C++ calling a Carbon function with generic parameters` [SemanticsTodo]
  71. // CHECK:STDERR: fn HasDeducedArg[T:! type](a: T) { a; }
  72. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  73. // CHECK:STDERR:
  74. import Other;
  75. import Cpp inline '''
  76. void G() {
  77. // CHECK:STDERR: fail_todo_deduced.carbon:[[@LINE+4]]:18: error: no member named 'HasDeducedArg' in namespace 'Carbon::Other' [CppInteropParseError]
  78. // CHECK:STDERR: 16 | Carbon::Other::HasDeducedArg(123);
  79. // CHECK:STDERR: | ^~~~~~~~~~~~~
  80. // CHECK:STDERR:
  81. Carbon::Other::HasDeducedArg(123);
  82. }
  83. ''';
  84. // --- method.carbon
  85. library "[[@TEST_NAME]]";
  86. import Other;
  87. import Cpp inline '''
  88. void G() {
  89. Carbon::Other::C().Method();
  90. }
  91. ''';