fail_modifiers.carbon 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. // AUTOUPDATE
  6. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/fail_modifiers.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/fail_modifiers.carbon
  10. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+7]]:18: error: `private` repeated on declaration
  11. // CHECK:STDERR: private abstract private class DuplicatePrivate;
  12. // CHECK:STDERR: ^~~~~~~
  13. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+4]]:1: note: `private` previously appeared here
  14. // CHECK:STDERR: private abstract private class DuplicatePrivate;
  15. // CHECK:STDERR: ^~~~~~~
  16. // CHECK:STDERR:
  17. private abstract private class DuplicatePrivate;
  18. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+7]]:14: error: `protected` not allowed on declaration with `private`
  19. // CHECK:STDERR: private base protected class TwoAccess {}
  20. // CHECK:STDERR: ^~~~~~~~~
  21. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+4]]:1: note: `private` previously appeared here
  22. // CHECK:STDERR: private base protected class TwoAccess {}
  23. // CHECK:STDERR: ^~~~~~~
  24. // CHECK:STDERR:
  25. private base protected class TwoAccess {}
  26. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+7]]:10: error: `abstract` repeated on declaration
  27. // CHECK:STDERR: abstract abstract class TwoAbstract;
  28. // CHECK:STDERR: ^~~~~~~~
  29. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+4]]:1: note: `abstract` previously appeared here
  30. // CHECK:STDERR: abstract abstract class TwoAbstract;
  31. // CHECK:STDERR: ^~~~~~~~
  32. // CHECK:STDERR:
  33. abstract abstract class TwoAbstract;
  34. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+15]]:1: error: `protected` not allowed on `class` declaration at file scope, `protected` is only allowed on class members
  35. // CHECK:STDERR: protected virtual base class Virtual {}
  36. // CHECK:STDERR: ^~~~~~~~~
  37. // CHECK:STDERR:
  38. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+11]]:11: error: `virtual` not allowed on `class` declaration
  39. // CHECK:STDERR: protected virtual base class Virtual {}
  40. // CHECK:STDERR: ^~~~~~~
  41. // CHECK:STDERR:
  42. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+7]]:19: error: `base` not allowed on declaration with `virtual`
  43. // CHECK:STDERR: protected virtual base class Virtual {}
  44. // CHECK:STDERR: ^~~~
  45. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+4]]:11: note: `virtual` previously appeared here
  46. // CHECK:STDERR: protected virtual base class Virtual {}
  47. // CHECK:STDERR: ^~~~~~~
  48. // CHECK:STDERR:
  49. protected virtual base class Virtual {}
  50. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+7]]:10: error: `protected` must appear before `abstract`
  51. // CHECK:STDERR: abstract protected class WrongOrder;
  52. // CHECK:STDERR: ^~~~~~~~~
  53. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+4]]:1: note: `abstract` previously appeared here
  54. // CHECK:STDERR: abstract protected class WrongOrder;
  55. // CHECK:STDERR: ^~~~~~~~
  56. // CHECK:STDERR:
  57. abstract protected class WrongOrder;
  58. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+7]]:10: error: `base` not allowed on declaration with `abstract`
  59. // CHECK:STDERR: abstract base class AbstractAndBase {}
  60. // CHECK:STDERR: ^~~~
  61. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+4]]:1: note: `abstract` previously appeared here
  62. // CHECK:STDERR: abstract base class AbstractAndBase {}
  63. // CHECK:STDERR: ^~~~~~~~
  64. // CHECK:STDERR:
  65. abstract base class AbstractAndBase {}
  66. abstract class AbstractWithDefinition {
  67. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+4]]:19: error: definition of `abstract` function
  68. // CHECK:STDERR: abstract fn F() {}
  69. // CHECK:STDERR: ^
  70. // CHECK:STDERR:
  71. abstract fn F() {}
  72. abstract fn G();
  73. }
  74. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+3]]:31: error: definition of `abstract` function
  75. // CHECK:STDERR: fn AbstractWithDefinition.G() {
  76. // CHECK:STDERR: ^
  77. fn AbstractWithDefinition.G() {
  78. }
  79. // CHECK:STDOUT: --- fail_modifiers.carbon
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: constants {
  82. // CHECK:STDOUT: %DuplicatePrivate: type = class_type @DuplicatePrivate [template]
  83. // CHECK:STDOUT: %TwoAccess: type = class_type @TwoAccess [template]
  84. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  85. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  86. // CHECK:STDOUT: %TwoAbstract: type = class_type @TwoAbstract [template]
  87. // CHECK:STDOUT: %Virtual: type = class_type @Virtual [template]
  88. // CHECK:STDOUT: %WrongOrder: type = class_type @WrongOrder [template]
  89. // CHECK:STDOUT: %AbstractAndBase: type = class_type @AbstractAndBase [template]
  90. // CHECK:STDOUT: %AbstractWithDefinition: type = class_type @AbstractWithDefinition [template]
  91. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  92. // CHECK:STDOUT: %.3: type = tuple_type () [template]
  93. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  94. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  95. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: imports {
  99. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  100. // CHECK:STDOUT: import Core//prelude
  101. // CHECK:STDOUT: import Core//prelude/operators
  102. // CHECK:STDOUT: import Core//prelude/types
  103. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  104. // CHECK:STDOUT: import Core//prelude/operators/as
  105. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  106. // CHECK:STDOUT: import Core//prelude/operators/comparison
  107. // CHECK:STDOUT: import Core//prelude/types/bool
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT:
  111. // CHECK:STDOUT: file {
  112. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  113. // CHECK:STDOUT: .Core = imports.%Core
  114. // CHECK:STDOUT: .DuplicatePrivate [private] = %DuplicatePrivate.decl
  115. // CHECK:STDOUT: .TwoAccess [private] = %TwoAccess.decl
  116. // CHECK:STDOUT: .TwoAbstract = %TwoAbstract.decl
  117. // CHECK:STDOUT: .Virtual = %Virtual.decl
  118. // CHECK:STDOUT: .WrongOrder = %WrongOrder.decl
  119. // CHECK:STDOUT: .AbstractAndBase = %AbstractAndBase.decl
  120. // CHECK:STDOUT: .AbstractWithDefinition = %AbstractWithDefinition.decl
  121. // CHECK:STDOUT: }
  122. // CHECK:STDOUT: %Core.import = import Core
  123. // CHECK:STDOUT: %DuplicatePrivate.decl: type = class_decl @DuplicatePrivate [template = constants.%DuplicatePrivate] {} {}
  124. // CHECK:STDOUT: %TwoAccess.decl: type = class_decl @TwoAccess [template = constants.%TwoAccess] {} {}
  125. // CHECK:STDOUT: %TwoAbstract.decl: type = class_decl @TwoAbstract [template = constants.%TwoAbstract] {} {}
  126. // CHECK:STDOUT: %Virtual.decl: type = class_decl @Virtual [template = constants.%Virtual] {} {}
  127. // CHECK:STDOUT: %WrongOrder.decl: type = class_decl @WrongOrder [template = constants.%WrongOrder] {} {}
  128. // CHECK:STDOUT: %AbstractAndBase.decl: type = class_decl @AbstractAndBase [template = constants.%AbstractAndBase] {} {}
  129. // CHECK:STDOUT: %AbstractWithDefinition.decl: type = class_decl @AbstractWithDefinition [template = constants.%AbstractWithDefinition] {} {}
  130. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {} {}
  131. // CHECK:STDOUT: }
  132. // CHECK:STDOUT:
  133. // CHECK:STDOUT: class @DuplicatePrivate;
  134. // CHECK:STDOUT:
  135. // CHECK:STDOUT: class @TwoAccess {
  136. // CHECK:STDOUT: %.loc27: <witness> = complete_type_witness %.1 [template = constants.%.2]
  137. // CHECK:STDOUT:
  138. // CHECK:STDOUT: !members:
  139. // CHECK:STDOUT: .Self = constants.%TwoAccess
  140. // CHECK:STDOUT: }
  141. // CHECK:STDOUT:
  142. // CHECK:STDOUT: class @TwoAbstract;
  143. // CHECK:STDOUT:
  144. // CHECK:STDOUT: class @Virtual {
  145. // CHECK:STDOUT: %.loc53: <witness> = complete_type_witness %.1 [template = constants.%.2]
  146. // CHECK:STDOUT:
  147. // CHECK:STDOUT: !members:
  148. // CHECK:STDOUT: .Self = constants.%Virtual
  149. // CHECK:STDOUT: }
  150. // CHECK:STDOUT:
  151. // CHECK:STDOUT: class @WrongOrder;
  152. // CHECK:STDOUT:
  153. // CHECK:STDOUT: class @AbstractAndBase {
  154. // CHECK:STDOUT: %.loc71: <witness> = complete_type_witness %.1 [template = constants.%.2]
  155. // CHECK:STDOUT:
  156. // CHECK:STDOUT: !members:
  157. // CHECK:STDOUT: .Self = constants.%AbstractAndBase
  158. // CHECK:STDOUT: }
  159. // CHECK:STDOUT:
  160. // CHECK:STDOUT: class @AbstractWithDefinition {
  161. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
  162. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {} {}
  163. // CHECK:STDOUT: %.loc80: <witness> = complete_type_witness %.1 [template = constants.%.2]
  164. // CHECK:STDOUT:
  165. // CHECK:STDOUT: !members:
  166. // CHECK:STDOUT: .Self = constants.%AbstractWithDefinition
  167. // CHECK:STDOUT: .F = %F.decl
  168. // CHECK:STDOUT: .G = %G.decl
  169. // CHECK:STDOUT: }
  170. // CHECK:STDOUT:
  171. // CHECK:STDOUT: abstract fn @F() {
  172. // CHECK:STDOUT: !entry:
  173. // CHECK:STDOUT: return
  174. // CHECK:STDOUT: }
  175. // CHECK:STDOUT:
  176. // CHECK:STDOUT: abstract fn @G() {
  177. // CHECK:STDOUT: !entry:
  178. // CHECK:STDOUT: return
  179. // CHECK:STDOUT: }
  180. // CHECK:STDOUT: