destroy_decl.carbon 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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/destroy.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/destroy_decl.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/destroy_decl.carbon
  12. // --- self.carbon
  13. library "[[@TEST_NAME]]";
  14. class C {
  15. fn destroy[self: Self]();
  16. }
  17. // --- addr_self.carbon
  18. library "[[@TEST_NAME]]";
  19. class C {
  20. fn destroy[addr self: Self*]();
  21. }
  22. // --- explicit_return.carbon
  23. library "[[@TEST_NAME]]";
  24. class C {
  25. fn destroy[self: Self]() -> ();
  26. }
  27. // --- fail_class_function.carbon
  28. library "[[@TEST_NAME]]";
  29. class C {
  30. // CHECK:STDERR: fail_class_function.carbon:[[@LINE+4]]:3: error: missing implicit `self` parameter [DestroyFunctionMissingSelf]
  31. // CHECK:STDERR: fn destroy();
  32. // CHECK:STDERR: ^~~~~~~~~~~~~
  33. // CHECK:STDERR:
  34. fn destroy();
  35. }
  36. // --- fail_extra_implicit_params_second.carbon
  37. library "[[@TEST_NAME]]";
  38. class C {
  39. // CHECK:STDERR: fail_extra_implicit_params_second.carbon:[[@LINE+4]]:26: error: unexpected implicit parameter [DestroyFunctionUnexpectedImplicitParam]
  40. // CHECK:STDERR: fn destroy[self: Self, T:! type]();
  41. // CHECK:STDERR: ^
  42. // CHECK:STDERR:
  43. fn destroy[self: Self, T:! type]();
  44. }
  45. // --- fail_extra_implicit_params_first.carbon
  46. library "[[@TEST_NAME]]";
  47. class C {
  48. // CHECK:STDERR: fail_extra_implicit_params_first.carbon:[[@LINE+4]]:14: error: unexpected implicit parameter [DestroyFunctionUnexpectedImplicitParam]
  49. // CHECK:STDERR: fn destroy[T:! type, self: Self]();
  50. // CHECK:STDERR: ^
  51. // CHECK:STDERR:
  52. fn destroy[T:! type, self: Self]();
  53. }
  54. // --- fail_positional_params.carbon
  55. library "[[@TEST_NAME]]";
  56. class C {
  57. // CHECK:STDERR: fail_positional_params.carbon:[[@LINE+4]]:3: error: missing empty explicit parameter list [DestroyFunctionPositionalParams]
  58. // CHECK:STDERR: fn destroy[self: Self];
  59. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~
  60. // CHECK:STDERR:
  61. fn destroy[self: Self];
  62. }
  63. // --- fail_explicit_params.carbon
  64. library "[[@TEST_NAME]]";
  65. class C {
  66. // CHECK:STDERR: fail_explicit_params.carbon:[[@LINE+4]]:26: error: unexpected parameter [DestroyFunctionNonEmptyExplicitParams]
  67. // CHECK:STDERR: fn destroy[self: Self](x: ());
  68. // CHECK:STDERR: ^~~~~
  69. // CHECK:STDERR:
  70. fn destroy[self: Self](x: ());
  71. }
  72. // --- fail_return_type.carbon
  73. library "[[@TEST_NAME]]";
  74. class C {
  75. // CHECK:STDERR: fail_return_type.carbon:[[@LINE+4]]:28: error: incorrect return type; must be unspecified or `()` [DestroyFunctionIncorrectReturnType]
  76. // CHECK:STDERR: fn destroy[self: Self]() -> {};
  77. // CHECK:STDERR: ^~~~~
  78. // CHECK:STDERR:
  79. fn destroy[self: Self]() -> {};
  80. }
  81. // --- fail_out_of_line_missing_params.carbon
  82. library "[[@TEST_NAME]]";
  83. class C {
  84. fn destroy[self: Self]();
  85. }
  86. // CHECK:STDERR: fail_out_of_line_missing_params.carbon:[[@LINE+7]]:1: error: redeclaration differs because of missing implicit parameter list [RedeclParamListDiffers]
  87. // CHECK:STDERR: fn C.destroy {}
  88. // CHECK:STDERR: ^~~~~~~~~~~~~~
  89. // CHECK:STDERR: fail_out_of_line_missing_params.carbon:[[@LINE-6]]:3: note: previously declared with implicit parameter list [RedeclParamListPrevious]
  90. // CHECK:STDERR: fn destroy[self: Self]();
  91. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
  92. // CHECK:STDERR:
  93. fn C.destroy {}
  94. // --- fail_destroy_in_file_scope.carbon
  95. library "[[@TEST_NAME]]";
  96. // CHECK:STDERR: fail_destroy_in_file_scope.carbon:[[@LINE+4]]:1: error: declaring `fn destroy` in non-class scope [DestroyFunctionOutsideClass]
  97. // CHECK:STDERR: fn destroy[self: ()]();
  98. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~
  99. // CHECK:STDERR:
  100. fn destroy[self: ()]();
  101. // --- fail_destroy_in_namespace_scope.carbon
  102. library "[[@TEST_NAME]]";
  103. namespace NS;
  104. // CHECK:STDERR: fail_destroy_in_namespace_scope.carbon:[[@LINE+4]]:1: error: declaring `fn destroy` in non-class scope [DestroyFunctionOutsideClass]
  105. // CHECK:STDERR: fn NS.destroy();
  106. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  107. // CHECK:STDERR:
  108. fn NS.destroy();
  109. // --- fail_invalid_qualifier_with_params.carbon
  110. library "[[@TEST_NAME]]";
  111. class C {
  112. fn destroy[self: Self]();
  113. }
  114. // CHECK:STDERR: fail_invalid_qualifier_with_params.carbon:[[@LINE+7]]:6: error: name qualifiers are only allowed for entities that provide a scope [QualifiedNameInNonScope]
  115. // CHECK:STDERR: fn C.destroy[self: Self]().Foo() {}
  116. // CHECK:STDERR: ^~~~~~~
  117. // CHECK:STDERR: fail_invalid_qualifier_with_params.carbon:[[@LINE-6]]:3: note: referenced non-scope entity declared here [QualifiedNameNonScopeEntity]
  118. // CHECK:STDERR: fn destroy[self: Self]();
  119. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
  120. // CHECK:STDERR:
  121. fn C.destroy[self: Self]().Foo() {}
  122. // --- fail_invalid_qualifier_no_params.carbon
  123. library "[[@TEST_NAME]]";
  124. class C {
  125. fn destroy[self: Self]();
  126. }
  127. // CHECK:STDERR: fail_invalid_qualifier_no_params.carbon:[[@LINE+7]]:6: error: name qualifiers are only allowed for entities that provide a scope [QualifiedNameInNonScope]
  128. // CHECK:STDERR: fn C.destroy.Foo() {}
  129. // CHECK:STDERR: ^~~~~~~
  130. // CHECK:STDERR: fail_invalid_qualifier_no_params.carbon:[[@LINE-6]]:3: note: referenced non-scope entity declared here [QualifiedNameNonScopeEntity]
  131. // CHECK:STDERR: fn destroy[self: Self]();
  132. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
  133. // CHECK:STDERR:
  134. fn C.destroy.Foo() {}
  135. // --- fail_return_type_after_no_params.carbon
  136. library "[[@TEST_NAME]]";
  137. // Return type handling special-cases the "no params" case.
  138. class C {
  139. // CHECK:STDERR: fail_return_type_after_no_params.carbon:[[@LINE+4]]:3: error: missing implicit `self` parameter [DestroyFunctionMissingSelf]
  140. // CHECK:STDERR: fn destroy -> ();
  141. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  142. // CHECK:STDERR:
  143. fn destroy -> ();
  144. }