fail_modifiers.carbon 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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 = symbolic_binding 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 = symbolic_binding Self, 0 [symbolic = constants.%Self]
  78. // CHECK:STDOUT: %Abstract.WithSelf.decl = interface_with_self_decl @Abstract [concrete]
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: !members:
  81. // CHECK:STDOUT: .Self = %Self
  82. // CHECK:STDOUT: witness = ()
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: !requires:
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: specific @Abstract.WithSelf(constants.%Self) {}
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: --- fail_default.carbon
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: constants {
  92. // CHECK:STDOUT: %Default.type: type = facet_type <@Default> [concrete]
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: file {
  96. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  97. // CHECK:STDOUT: .Default = %Default.decl
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT: %Default.decl: type = interface_decl @Default [concrete = constants.%Default.type] {} {}
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT:
  102. // CHECK:STDOUT: interface @Default;
  103. // CHECK:STDOUT:
  104. // CHECK:STDOUT: --- fail_virtual.carbon
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: constants {
  107. // CHECK:STDOUT: %Virtual.type: type = facet_type <@Virtual> [concrete]
  108. // CHECK:STDOUT: %Self: %Virtual.type = symbolic_binding Self, 0 [symbolic]
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT:
  111. // CHECK:STDOUT: file {
  112. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  113. // CHECK:STDOUT: .Virtual = %Virtual.decl
  114. // CHECK:STDOUT: }
  115. // CHECK:STDOUT: %Virtual.decl: type = interface_decl @Virtual [concrete = constants.%Virtual.type] {} {}
  116. // CHECK:STDOUT: }
  117. // CHECK:STDOUT:
  118. // CHECK:STDOUT: interface @Virtual {
  119. // CHECK:STDOUT: %Self: %Virtual.type = symbolic_binding Self, 0 [symbolic = constants.%Self]
  120. // CHECK:STDOUT: %Virtual.WithSelf.decl = interface_with_self_decl @Virtual [concrete]
  121. // CHECK:STDOUT:
  122. // CHECK:STDOUT: !members:
  123. // CHECK:STDOUT: .Self = %Self
  124. // CHECK:STDOUT: witness = ()
  125. // CHECK:STDOUT:
  126. // CHECK:STDOUT: !requires:
  127. // CHECK:STDOUT: }
  128. // CHECK:STDOUT:
  129. // CHECK:STDOUT: specific @Virtual.WithSelf(constants.%Self) {}
  130. // CHECK:STDOUT:
  131. // CHECK:STDOUT: --- fail_protected.carbon
  132. // CHECK:STDOUT:
  133. // CHECK:STDOUT: constants {
  134. // CHECK:STDOUT: %Protected.type: type = facet_type <@Protected> [concrete]
  135. // CHECK:STDOUT: }
  136. // CHECK:STDOUT:
  137. // CHECK:STDOUT: file {
  138. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  139. // CHECK:STDOUT: .Protected = %Protected.decl
  140. // CHECK:STDOUT: }
  141. // CHECK:STDOUT: %Protected.decl: type = interface_decl @Protected [concrete = constants.%Protected.type] {} {}
  142. // CHECK:STDOUT: }
  143. // CHECK:STDOUT:
  144. // CHECK:STDOUT: interface @Protected;
  145. // CHECK:STDOUT:
  146. // CHECK:STDOUT: --- fail_private_member.carbon
  147. // CHECK:STDOUT:
  148. // CHECK:STDOUT: constants {
  149. // CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
  150. // CHECK:STDOUT: %Self: %I.type = symbolic_binding Self, 0 [symbolic]
  151. // CHECK:STDOUT: %Self.binding.as_type: type = symbolic_binding_type Self, 0, %Self [symbolic]
  152. // CHECK:STDOUT: %pattern_type: type = pattern_type %Self.binding.as_type [symbolic]
  153. // CHECK:STDOUT: %I.WithSelf.F.type: type = fn_type @I.WithSelf.F, @I.WithSelf(%Self) [symbolic]
  154. // CHECK:STDOUT: %I.WithSelf.F: %I.WithSelf.F.type = struct_value () [symbolic]
  155. // CHECK:STDOUT: %I.assoc_type: type = assoc_entity_type @I [concrete]
  156. // CHECK:STDOUT: %assoc0: %I.assoc_type = assoc_entity element0, @I.WithSelf.%I.WithSelf.F.decl [concrete]
  157. // CHECK:STDOUT: }
  158. // CHECK:STDOUT:
  159. // CHECK:STDOUT: file {
  160. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  161. // CHECK:STDOUT: .I = %I.decl
  162. // CHECK:STDOUT: }
  163. // CHECK:STDOUT: %I.decl: type = interface_decl @I [concrete = constants.%I.type] {} {}
  164. // CHECK:STDOUT: }
  165. // CHECK:STDOUT:
  166. // CHECK:STDOUT: interface @I {
  167. // CHECK:STDOUT: %Self: %I.type = symbolic_binding Self, 0 [symbolic = constants.%Self]
  168. // CHECK:STDOUT: %I.WithSelf.decl = interface_with_self_decl @I [concrete]
  169. // CHECK:STDOUT:
  170. // CHECK:STDOUT: !with Self:
  171. // CHECK:STDOUT: %I.WithSelf.F.decl: @I.WithSelf.%I.WithSelf.F.type (%I.WithSelf.F.type) = fn_decl @I.WithSelf.F [symbolic = @I.WithSelf.%I.WithSelf.F (constants.%I.WithSelf.F)] {
  172. // CHECK:STDOUT: %self.param_patt: @I.WithSelf.F.%pattern_type (%pattern_type) = value_param_pattern [concrete]
  173. // CHECK:STDOUT: %self.patt: @I.WithSelf.F.%pattern_type (%pattern_type) = at_binding_pattern self, %self.param_patt [concrete]
  174. // CHECK:STDOUT: } {
  175. // CHECK:STDOUT: %self.param: @I.WithSelf.F.%Self.binding.as_type (%Self.binding.as_type) = value_param call_param0
  176. // CHECK:STDOUT: %.loc9_22.1: type = splice_block %.loc9_22.2 [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)] {
  177. // CHECK:STDOUT: %Self.ref: %I.type = name_ref Self, @I.%Self [symbolic = %Self (constants.%Self)]
  178. // CHECK:STDOUT: %Self.as_type: type = facet_access_type %Self.ref [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)]
  179. // CHECK:STDOUT: %.loc9_22.2: type = converted %Self.ref, %Self.as_type [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)]
  180. // CHECK:STDOUT: }
  181. // CHECK:STDOUT: %self: @I.WithSelf.F.%Self.binding.as_type (%Self.binding.as_type) = value_binding self, %self.param
  182. // CHECK:STDOUT: }
  183. // CHECK:STDOUT: %assoc0: %I.assoc_type = assoc_entity element0, %I.WithSelf.F.decl [concrete = constants.%assoc0]
  184. // CHECK:STDOUT:
  185. // CHECK:STDOUT: !members:
  186. // CHECK:STDOUT: .Self = %Self
  187. // CHECK:STDOUT: .F = @I.WithSelf.%assoc0
  188. // CHECK:STDOUT: witness = (@I.WithSelf.%I.WithSelf.F.decl)
  189. // CHECK:STDOUT:
  190. // CHECK:STDOUT: !requires:
  191. // CHECK:STDOUT: }
  192. // CHECK:STDOUT:
  193. // CHECK:STDOUT: generic fn @I.WithSelf.F(@I.%Self: %I.type) {
  194. // CHECK:STDOUT: %Self: %I.type = symbolic_binding Self, 0 [symbolic = %Self (constants.%Self)]
  195. // CHECK:STDOUT: %Self.binding.as_type: type = symbolic_binding_type Self, 0, %Self [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)]
  196. // CHECK:STDOUT: %pattern_type: type = pattern_type %Self.binding.as_type [symbolic = %pattern_type (constants.%pattern_type)]
  197. // CHECK:STDOUT:
  198. // CHECK:STDOUT: fn(%self.param: @I.WithSelf.F.%Self.binding.as_type (%Self.binding.as_type));
  199. // CHECK:STDOUT: }
  200. // CHECK:STDOUT:
  201. // CHECK:STDOUT: specific @I.WithSelf(constants.%Self) {}
  202. // CHECK:STDOUT:
  203. // CHECK:STDOUT: specific @I.WithSelf.F(constants.%Self) {
  204. // CHECK:STDOUT: %Self => constants.%Self
  205. // CHECK:STDOUT: %Self.binding.as_type => constants.%Self.binding.as_type
  206. // CHECK:STDOUT: %pattern_type => constants.%pattern_type
  207. // CHECK:STDOUT: }
  208. // CHECK:STDOUT:
  209. // CHECK:STDOUT: --- fail_protected_member.carbon
  210. // CHECK:STDOUT:
  211. // CHECK:STDOUT: constants {
  212. // CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
  213. // CHECK:STDOUT: %Self: %I.type = symbolic_binding Self, 0 [symbolic]
  214. // CHECK:STDOUT: %Self.binding.as_type: type = symbolic_binding_type Self, 0, %Self [symbolic]
  215. // CHECK:STDOUT: %pattern_type: type = pattern_type %Self.binding.as_type [symbolic]
  216. // CHECK:STDOUT: %I.WithSelf.F.type: type = fn_type @I.WithSelf.F, @I.WithSelf(%Self) [symbolic]
  217. // CHECK:STDOUT: %I.WithSelf.F: %I.WithSelf.F.type = struct_value () [symbolic]
  218. // CHECK:STDOUT: %I.assoc_type: type = assoc_entity_type @I [concrete]
  219. // CHECK:STDOUT: %assoc0: %I.assoc_type = assoc_entity element0, @I.WithSelf.%I.WithSelf.F.decl [concrete]
  220. // CHECK:STDOUT: }
  221. // CHECK:STDOUT:
  222. // CHECK:STDOUT: file {
  223. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  224. // CHECK:STDOUT: .I = %I.decl
  225. // CHECK:STDOUT: }
  226. // CHECK:STDOUT: %I.decl: type = interface_decl @I [concrete = constants.%I.type] {} {}
  227. // CHECK:STDOUT: }
  228. // CHECK:STDOUT:
  229. // CHECK:STDOUT: interface @I {
  230. // CHECK:STDOUT: %Self: %I.type = symbolic_binding Self, 0 [symbolic = constants.%Self]
  231. // CHECK:STDOUT: %I.WithSelf.decl = interface_with_self_decl @I [concrete]
  232. // CHECK:STDOUT:
  233. // CHECK:STDOUT: !with Self:
  234. // CHECK:STDOUT: %I.WithSelf.F.decl: @I.WithSelf.%I.WithSelf.F.type (%I.WithSelf.F.type) = fn_decl @I.WithSelf.F [symbolic = @I.WithSelf.%I.WithSelf.F (constants.%I.WithSelf.F)] {
  235. // CHECK:STDOUT: %self.param_patt: @I.WithSelf.F.%pattern_type (%pattern_type) = value_param_pattern [concrete]
  236. // CHECK:STDOUT: %self.patt: @I.WithSelf.F.%pattern_type (%pattern_type) = at_binding_pattern self, %self.param_patt [concrete]
  237. // CHECK:STDOUT: } {
  238. // CHECK:STDOUT: %self.param: @I.WithSelf.F.%Self.binding.as_type (%Self.binding.as_type) = value_param call_param0
  239. // CHECK:STDOUT: %.loc9_24.1: type = splice_block %.loc9_24.2 [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)] {
  240. // CHECK:STDOUT: %Self.ref: %I.type = name_ref Self, @I.%Self [symbolic = %Self (constants.%Self)]
  241. // CHECK:STDOUT: %Self.as_type: type = facet_access_type %Self.ref [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)]
  242. // CHECK:STDOUT: %.loc9_24.2: type = converted %Self.ref, %Self.as_type [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)]
  243. // CHECK:STDOUT: }
  244. // CHECK:STDOUT: %self: @I.WithSelf.F.%Self.binding.as_type (%Self.binding.as_type) = value_binding self, %self.param
  245. // CHECK:STDOUT: }
  246. // CHECK:STDOUT: %assoc0: %I.assoc_type = assoc_entity element0, %I.WithSelf.F.decl [concrete = constants.%assoc0]
  247. // CHECK:STDOUT:
  248. // CHECK:STDOUT: !members:
  249. // CHECK:STDOUT: .Self = %Self
  250. // CHECK:STDOUT: .F = @I.WithSelf.%assoc0
  251. // CHECK:STDOUT: witness = (@I.WithSelf.%I.WithSelf.F.decl)
  252. // CHECK:STDOUT:
  253. // CHECK:STDOUT: !requires:
  254. // CHECK:STDOUT: }
  255. // CHECK:STDOUT:
  256. // CHECK:STDOUT: generic fn @I.WithSelf.F(@I.%Self: %I.type) {
  257. // CHECK:STDOUT: %Self: %I.type = symbolic_binding Self, 0 [symbolic = %Self (constants.%Self)]
  258. // CHECK:STDOUT: %Self.binding.as_type: type = symbolic_binding_type Self, 0, %Self [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)]
  259. // CHECK:STDOUT: %pattern_type: type = pattern_type %Self.binding.as_type [symbolic = %pattern_type (constants.%pattern_type)]
  260. // CHECK:STDOUT:
  261. // CHECK:STDOUT: fn(%self.param: @I.WithSelf.F.%Self.binding.as_type (%Self.binding.as_type));
  262. // CHECK:STDOUT: }
  263. // CHECK:STDOUT:
  264. // CHECK:STDOUT: specific @I.WithSelf(constants.%Self) {}
  265. // CHECK:STDOUT:
  266. // CHECK:STDOUT: specific @I.WithSelf.F(constants.%Self) {
  267. // CHECK:STDOUT: %Self => constants.%Self
  268. // CHECK:STDOUT: %Self.binding.as_type => constants.%Self.binding.as_type
  269. // CHECK:STDOUT: %pattern_type => constants.%pattern_type
  270. // CHECK:STDOUT: }
  271. // CHECK:STDOUT: