fail_modifiers.carbon 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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/none.carbon
  6. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  7. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  8. //
  9. // AUTOUPDATE
  10. // TIP: To test this file alone, run:
  11. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interface/fail_modifiers.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interface/fail_modifiers.carbon
  14. // --- fail_abstract.carbon
  15. library "[[@TEST_NAME]]";
  16. // CHECK:STDERR: fail_abstract.carbon:[[@LINE+4]]:1: error: `abstract` not allowed on `interface` declaration [ModifierNotAllowedOnDeclaration]
  17. // CHECK:STDERR: abstract interface Abstract {
  18. // CHECK:STDERR: ^~~~~~~~
  19. // CHECK:STDERR:
  20. abstract interface Abstract {
  21. }
  22. // --- fail_default.carbon
  23. library "[[@TEST_NAME]]";
  24. // CHECK:STDERR: fail_default.carbon:[[@LINE+4]]:1: error: `default` not allowed on `interface` declaration [ModifierNotAllowedOnDeclaration]
  25. // CHECK:STDERR: default interface Default;
  26. // CHECK:STDERR: ^~~~~~~
  27. // CHECK:STDERR:
  28. default interface Default;
  29. // --- fail_virtual.carbon
  30. library "[[@TEST_NAME]]";
  31. // CHECK:STDERR: fail_virtual.carbon:[[@LINE+4]]:1: error: `virtual` not allowed on `interface` declaration [ModifierNotAllowedOnDeclaration]
  32. // CHECK:STDERR: virtual interface Virtual {
  33. // CHECK:STDERR: ^~~~~~~
  34. // CHECK:STDERR:
  35. virtual interface Virtual {
  36. }
  37. // --- fail_protected.carbon
  38. library "[[@TEST_NAME]]";
  39. // CHECK:STDERR: fail_protected.carbon:[[@LINE+4]]:1: error: `protected` not allowed; requires class scope [ModifierProtectedNotAllowed]
  40. // CHECK:STDERR: protected interface Protected;
  41. // CHECK:STDERR: ^~~~~~~~~
  42. // CHECK:STDERR:
  43. protected interface Protected;
  44. // --- fail_private_member.carbon
  45. library "[[@TEST_NAME]]";
  46. interface I {
  47. // CHECK:STDERR: fail_private_member.carbon:[[@LINE+4]]:3: error: `private` not allowed; requires class or file scope [ModifierPrivateNotAllowed]
  48. // CHECK:STDERR: private fn F[self: Self]();
  49. // CHECK:STDERR: ^~~~~~~
  50. // CHECK:STDERR:
  51. private fn F[self: Self]();
  52. }
  53. // --- fail_protected_member.carbon
  54. library "[[@TEST_NAME]]";
  55. interface I {
  56. // CHECK:STDERR: fail_protected_member.carbon:[[@LINE+4]]:3: error: `protected` not allowed; requires class scope [ModifierProtectedNotAllowed]
  57. // CHECK:STDERR: protected fn F[self: Self]();
  58. // CHECK:STDERR: ^~~~~~~~~
  59. // CHECK:STDERR:
  60. protected fn F[self: Self]();
  61. }
  62. // CHECK:STDOUT: --- fail_abstract.carbon
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: constants {
  65. // CHECK:STDOUT: %Abstract.type: type = facet_type <@Abstract> [concrete]
  66. // CHECK:STDOUT: %Self: %Abstract.type = bind_symbolic_name Self, 0 [symbolic]
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: file {
  70. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  71. // CHECK:STDOUT: .Abstract = %Abstract.decl
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT: %Abstract.decl: type = interface_decl @Abstract [concrete = constants.%Abstract.type] {} {}
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: interface @Abstract {
  77. // CHECK:STDOUT: %Self: %Abstract.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: !members:
  80. // CHECK:STDOUT: .Self = %Self
  81. // CHECK:STDOUT: witness = ()
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: --- fail_default.carbon
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: constants {
  87. // CHECK:STDOUT: %Default.type: type = facet_type <@Default> [concrete]
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: file {
  91. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  92. // CHECK:STDOUT: .Default = %Default.decl
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT: %Default.decl: type = interface_decl @Default [concrete = constants.%Default.type] {} {}
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: interface @Default;
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: --- fail_virtual.carbon
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: constants {
  102. // CHECK:STDOUT: %Virtual.type: type = facet_type <@Virtual> [concrete]
  103. // CHECK:STDOUT: %Self: %Virtual.type = bind_symbolic_name Self, 0 [symbolic]
  104. // CHECK:STDOUT: }
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: file {
  107. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  108. // CHECK:STDOUT: .Virtual = %Virtual.decl
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT: %Virtual.decl: type = interface_decl @Virtual [concrete = constants.%Virtual.type] {} {}
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT:
  113. // CHECK:STDOUT: interface @Virtual {
  114. // CHECK:STDOUT: %Self: %Virtual.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
  115. // CHECK:STDOUT:
  116. // CHECK:STDOUT: !members:
  117. // CHECK:STDOUT: .Self = %Self
  118. // CHECK:STDOUT: witness = ()
  119. // CHECK:STDOUT: }
  120. // CHECK:STDOUT:
  121. // CHECK:STDOUT: --- fail_protected.carbon
  122. // CHECK:STDOUT:
  123. // CHECK:STDOUT: constants {
  124. // CHECK:STDOUT: %Protected.type: type = facet_type <@Protected> [concrete]
  125. // CHECK:STDOUT: }
  126. // CHECK:STDOUT:
  127. // CHECK:STDOUT: file {
  128. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  129. // CHECK:STDOUT: .Protected = %Protected.decl
  130. // CHECK:STDOUT: }
  131. // CHECK:STDOUT: %Protected.decl: type = interface_decl @Protected [concrete = constants.%Protected.type] {} {}
  132. // CHECK:STDOUT: }
  133. // CHECK:STDOUT:
  134. // CHECK:STDOUT: interface @Protected;
  135. // CHECK:STDOUT:
  136. // CHECK:STDOUT: --- fail_private_member.carbon
  137. // CHECK:STDOUT:
  138. // CHECK:STDOUT: constants {
  139. // CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
  140. // CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic]
  141. // CHECK:STDOUT: %Self.as_type: type = facet_access_type %Self [symbolic]
  142. // CHECK:STDOUT: %pattern_type: type = pattern_type %Self.as_type [symbolic]
  143. // CHECK:STDOUT: %I.F.type: type = fn_type @I.F [concrete]
  144. // CHECK:STDOUT: %I.F: %I.F.type = struct_value () [concrete]
  145. // CHECK:STDOUT: %I.assoc_type: type = assoc_entity_type @I [concrete]
  146. // CHECK:STDOUT: %assoc0: %I.assoc_type = assoc_entity element0, @I.%I.F.decl [concrete]
  147. // CHECK:STDOUT: }
  148. // CHECK:STDOUT:
  149. // CHECK:STDOUT: file {
  150. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  151. // CHECK:STDOUT: .I = %I.decl
  152. // CHECK:STDOUT: }
  153. // CHECK:STDOUT: %I.decl: type = interface_decl @I [concrete = constants.%I.type] {} {}
  154. // CHECK:STDOUT: }
  155. // CHECK:STDOUT:
  156. // CHECK:STDOUT: interface @I {
  157. // CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
  158. // CHECK:STDOUT: %I.F.decl: %I.F.type = fn_decl @I.F [concrete = constants.%I.F] {
  159. // CHECK:STDOUT: %self.patt: @I.F.%pattern_type (%pattern_type) = binding_pattern self [concrete]
  160. // CHECK:STDOUT: %self.param_patt: @I.F.%pattern_type (%pattern_type) = value_param_pattern %self.patt, call_param0 [concrete]
  161. // CHECK:STDOUT: } {
  162. // CHECK:STDOUT: %self.param: @I.F.%Self.as_type.loc9_22.1 (%Self.as_type) = value_param call_param0
  163. // CHECK:STDOUT: %.loc9_22.1: type = splice_block %.loc9_22.2 [symbolic = %Self.as_type.loc9_22.1 (constants.%Self.as_type)] {
  164. // CHECK:STDOUT: %Self.ref: %I.type = name_ref Self, @I.%Self [symbolic = %Self (constants.%Self)]
  165. // CHECK:STDOUT: %Self.as_type.loc9_22.2: type = facet_access_type %Self.ref [symbolic = %Self.as_type.loc9_22.1 (constants.%Self.as_type)]
  166. // CHECK:STDOUT: %.loc9_22.2: type = converted %Self.ref, %Self.as_type.loc9_22.2 [symbolic = %Self.as_type.loc9_22.1 (constants.%Self.as_type)]
  167. // CHECK:STDOUT: }
  168. // CHECK:STDOUT: %self: @I.F.%Self.as_type.loc9_22.1 (%Self.as_type) = bind_name self, %self.param
  169. // CHECK:STDOUT: }
  170. // CHECK:STDOUT: %assoc0: %I.assoc_type = assoc_entity element0, %I.F.decl [concrete = constants.%assoc0]
  171. // CHECK:STDOUT:
  172. // CHECK:STDOUT: !members:
  173. // CHECK:STDOUT: .Self = %Self
  174. // CHECK:STDOUT: .F = %assoc0
  175. // CHECK:STDOUT: witness = (%I.F.decl)
  176. // CHECK:STDOUT: }
  177. // CHECK:STDOUT:
  178. // CHECK:STDOUT: generic fn @I.F(@I.%Self: %I.type) {
  179. // CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic = %Self (constants.%Self)]
  180. // CHECK:STDOUT: %Self.as_type.loc9_22.1: type = facet_access_type %Self [symbolic = %Self.as_type.loc9_22.1 (constants.%Self.as_type)]
  181. // CHECK:STDOUT: %pattern_type: type = pattern_type %Self.as_type.loc9_22.1 [symbolic = %pattern_type (constants.%pattern_type)]
  182. // CHECK:STDOUT:
  183. // CHECK:STDOUT: fn(%self.param: @I.F.%Self.as_type.loc9_22.1 (%Self.as_type));
  184. // CHECK:STDOUT: }
  185. // CHECK:STDOUT:
  186. // CHECK:STDOUT: specific @I.F(constants.%Self) {
  187. // CHECK:STDOUT: %Self => constants.%Self
  188. // CHECK:STDOUT: %Self.as_type.loc9_22.1 => constants.%Self.as_type
  189. // CHECK:STDOUT: %pattern_type => constants.%pattern_type
  190. // CHECK:STDOUT: }
  191. // CHECK:STDOUT:
  192. // CHECK:STDOUT: --- fail_protected_member.carbon
  193. // CHECK:STDOUT:
  194. // CHECK:STDOUT: constants {
  195. // CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
  196. // CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic]
  197. // CHECK:STDOUT: %Self.as_type: type = facet_access_type %Self [symbolic]
  198. // CHECK:STDOUT: %pattern_type: type = pattern_type %Self.as_type [symbolic]
  199. // CHECK:STDOUT: %I.F.type: type = fn_type @I.F [concrete]
  200. // CHECK:STDOUT: %I.F: %I.F.type = struct_value () [concrete]
  201. // CHECK:STDOUT: %I.assoc_type: type = assoc_entity_type @I [concrete]
  202. // CHECK:STDOUT: %assoc0: %I.assoc_type = assoc_entity element0, @I.%I.F.decl [concrete]
  203. // CHECK:STDOUT: }
  204. // CHECK:STDOUT:
  205. // CHECK:STDOUT: file {
  206. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  207. // CHECK:STDOUT: .I = %I.decl
  208. // CHECK:STDOUT: }
  209. // CHECK:STDOUT: %I.decl: type = interface_decl @I [concrete = constants.%I.type] {} {}
  210. // CHECK:STDOUT: }
  211. // CHECK:STDOUT:
  212. // CHECK:STDOUT: interface @I {
  213. // CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
  214. // CHECK:STDOUT: %I.F.decl: %I.F.type = fn_decl @I.F [concrete = constants.%I.F] {
  215. // CHECK:STDOUT: %self.patt: @I.F.%pattern_type (%pattern_type) = binding_pattern self [concrete]
  216. // CHECK:STDOUT: %self.param_patt: @I.F.%pattern_type (%pattern_type) = value_param_pattern %self.patt, call_param0 [concrete]
  217. // CHECK:STDOUT: } {
  218. // CHECK:STDOUT: %self.param: @I.F.%Self.as_type.loc9_24.1 (%Self.as_type) = value_param call_param0
  219. // CHECK:STDOUT: %.loc9_24.1: type = splice_block %.loc9_24.2 [symbolic = %Self.as_type.loc9_24.1 (constants.%Self.as_type)] {
  220. // CHECK:STDOUT: %Self.ref: %I.type = name_ref Self, @I.%Self [symbolic = %Self (constants.%Self)]
  221. // CHECK:STDOUT: %Self.as_type.loc9_24.2: type = facet_access_type %Self.ref [symbolic = %Self.as_type.loc9_24.1 (constants.%Self.as_type)]
  222. // CHECK:STDOUT: %.loc9_24.2: type = converted %Self.ref, %Self.as_type.loc9_24.2 [symbolic = %Self.as_type.loc9_24.1 (constants.%Self.as_type)]
  223. // CHECK:STDOUT: }
  224. // CHECK:STDOUT: %self: @I.F.%Self.as_type.loc9_24.1 (%Self.as_type) = bind_name self, %self.param
  225. // CHECK:STDOUT: }
  226. // CHECK:STDOUT: %assoc0: %I.assoc_type = assoc_entity element0, %I.F.decl [concrete = constants.%assoc0]
  227. // CHECK:STDOUT:
  228. // CHECK:STDOUT: !members:
  229. // CHECK:STDOUT: .Self = %Self
  230. // CHECK:STDOUT: .F = %assoc0
  231. // CHECK:STDOUT: witness = (%I.F.decl)
  232. // CHECK:STDOUT: }
  233. // CHECK:STDOUT:
  234. // CHECK:STDOUT: generic fn @I.F(@I.%Self: %I.type) {
  235. // CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic = %Self (constants.%Self)]
  236. // CHECK:STDOUT: %Self.as_type.loc9_24.1: type = facet_access_type %Self [symbolic = %Self.as_type.loc9_24.1 (constants.%Self.as_type)]
  237. // CHECK:STDOUT: %pattern_type: type = pattern_type %Self.as_type.loc9_24.1 [symbolic = %pattern_type (constants.%pattern_type)]
  238. // CHECK:STDOUT:
  239. // CHECK:STDOUT: fn(%self.param: @I.F.%Self.as_type.loc9_24.1 (%Self.as_type));
  240. // CHECK:STDOUT: }
  241. // CHECK:STDOUT:
  242. // CHECK:STDOUT: specific @I.F(constants.%Self) {
  243. // CHECK:STDOUT: %Self => constants.%Self
  244. // CHECK:STDOUT: %Self.as_type.loc9_24.1 => constants.%Self.as_type
  245. // CHECK:STDOUT: %pattern_type => constants.%pattern_type
  246. // CHECK:STDOUT: }
  247. // CHECK:STDOUT: