fail_base_modifiers.carbon 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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_base_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_base_modifiers.carbon
  10. base class B {}
  11. class C1 {
  12. // CHECK:STDERR: fail_base_modifiers.carbon:[[@LINE+4]]:3: error: `private` not allowed on `base` declaration [ModifierNotAllowedOnDeclaration]
  13. // CHECK:STDERR: private extend base: B;
  14. // CHECK:STDERR: ^~~~~~~
  15. // CHECK:STDERR:
  16. private extend base: B;
  17. }
  18. class C2 {
  19. // CHECK:STDERR: fail_base_modifiers.carbon:[[@LINE+8]]:3: error: `abstract` not allowed on `base` declaration [ModifierNotAllowedOnDeclaration]
  20. // CHECK:STDERR: abstract base: B;
  21. // CHECK:STDERR: ^~~~~~~~
  22. // CHECK:STDERR:
  23. // CHECK:STDERR: fail_base_modifiers.carbon:[[@LINE+4]]:3: error: missing `extend` before `base` declaration [BaseMissingExtend]
  24. // CHECK:STDERR: abstract base: B;
  25. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  26. // CHECK:STDERR:
  27. abstract base: B;
  28. }
  29. class C3 {
  30. // CHECK:STDERR: fail_base_modifiers.carbon:[[@LINE+7]]:10: error: `default` not allowed on declaration with `extend` [ModifierNotAllowedWith]
  31. // CHECK:STDERR: extend default base: B;
  32. // CHECK:STDERR: ^~~~~~~
  33. // CHECK:STDERR: fail_base_modifiers.carbon:[[@LINE+4]]:3: note: `extend` previously appeared here [ModifierPrevious]
  34. // CHECK:STDERR: extend default base: B;
  35. // CHECK:STDERR: ^~~~~~
  36. // CHECK:STDERR:
  37. extend default base: B;
  38. }
  39. class C4 {
  40. // CHECK:STDERR: fail_base_modifiers.carbon:[[@LINE+7]]:10: error: `extend` repeated on declaration [ModifierRepeated]
  41. // CHECK:STDERR: extend extend base: B;
  42. // CHECK:STDERR: ^~~~~~
  43. // CHECK:STDERR: fail_base_modifiers.carbon:[[@LINE+4]]:3: note: `extend` previously appeared here [ModifierPrevious]
  44. // CHECK:STDERR: extend extend base: B;
  45. // CHECK:STDERR: ^~~~~~
  46. // CHECK:STDERR:
  47. extend extend base: B;
  48. }
  49. // CHECK:STDOUT: --- fail_base_modifiers.carbon
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: constants {
  52. // CHECK:STDOUT: %B: type = class_type @B [concrete]
  53. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  54. // CHECK:STDOUT: %complete_type.357: <witness> = complete_type_witness %empty_struct_type [concrete]
  55. // CHECK:STDOUT: %C1: type = class_type @C1 [concrete]
  56. // CHECK:STDOUT: %C1.elem: type = unbound_element_type %C1, %B [concrete]
  57. // CHECK:STDOUT: %struct_type.base: type = struct_type {.base: %B} [concrete]
  58. // CHECK:STDOUT: %complete_type.98e: <witness> = complete_type_witness %struct_type.base [concrete]
  59. // CHECK:STDOUT: %C2: type = class_type @C2 [concrete]
  60. // CHECK:STDOUT: %C2.elem: type = unbound_element_type %C2, %B [concrete]
  61. // CHECK:STDOUT: %C3: type = class_type @C3 [concrete]
  62. // CHECK:STDOUT: %C3.elem: type = unbound_element_type %C3, %B [concrete]
  63. // CHECK:STDOUT: %C4: type = class_type @C4 [concrete]
  64. // CHECK:STDOUT: %C4.elem: type = unbound_element_type %C4, %B [concrete]
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: imports {
  68. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  69. // CHECK:STDOUT: import Core//prelude
  70. // CHECK:STDOUT: import Core//prelude/...
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: file {
  75. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  76. // CHECK:STDOUT: .Core = imports.%Core
  77. // CHECK:STDOUT: .B = %B.decl
  78. // CHECK:STDOUT: .C1 = %C1.decl
  79. // CHECK:STDOUT: .C2 = %C2.decl
  80. // CHECK:STDOUT: .C3 = %C3.decl
  81. // CHECK:STDOUT: .C4 = %C4.decl
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT: %Core.import = import Core
  84. // CHECK:STDOUT: %B.decl: type = class_decl @B [concrete = constants.%B] {} {}
  85. // CHECK:STDOUT: %C1.decl: type = class_decl @C1 [concrete = constants.%C1] {} {}
  86. // CHECK:STDOUT: %C2.decl: type = class_decl @C2 [concrete = constants.%C2] {} {}
  87. // CHECK:STDOUT: %C3.decl: type = class_decl @C3 [concrete = constants.%C3] {} {}
  88. // CHECK:STDOUT: %C4.decl: type = class_decl @C4 [concrete = constants.%C4] {} {}
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: class @B {
  92. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  93. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type.357]
  94. // CHECK:STDOUT: complete_type_witness = %complete_type
  95. // CHECK:STDOUT:
  96. // CHECK:STDOUT: !members:
  97. // CHECK:STDOUT: .Self = constants.%B
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT:
  100. // CHECK:STDOUT: class @C1 {
  101. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [concrete = constants.%B]
  102. // CHECK:STDOUT: %.loc18: %C1.elem = base_decl %B.ref, element0 [concrete]
  103. // CHECK:STDOUT: %struct_type.base: type = struct_type {.base: %B} [concrete = constants.%struct_type.base]
  104. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.base [concrete = constants.%complete_type.98e]
  105. // CHECK:STDOUT: complete_type_witness = %complete_type
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: !members:
  108. // CHECK:STDOUT: .Self = constants.%C1
  109. // CHECK:STDOUT: .B = <poisoned>
  110. // CHECK:STDOUT: .base = %.loc18
  111. // CHECK:STDOUT: extend %B.ref
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT:
  114. // CHECK:STDOUT: class @C2 {
  115. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [concrete = constants.%B]
  116. // CHECK:STDOUT: %.loc30: %C2.elem = base_decl %B.ref, element0 [concrete]
  117. // CHECK:STDOUT: %struct_type.base: type = struct_type {.base: %B} [concrete = constants.%struct_type.base]
  118. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.base [concrete = constants.%complete_type.98e]
  119. // CHECK:STDOUT: complete_type_witness = %complete_type
  120. // CHECK:STDOUT:
  121. // CHECK:STDOUT: !members:
  122. // CHECK:STDOUT: .Self = constants.%C2
  123. // CHECK:STDOUT: .B = <poisoned>
  124. // CHECK:STDOUT: .base = %.loc30
  125. // CHECK:STDOUT: }
  126. // CHECK:STDOUT:
  127. // CHECK:STDOUT: class @C3 {
  128. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [concrete = constants.%B]
  129. // CHECK:STDOUT: %.loc41: %C3.elem = base_decl %B.ref, element0 [concrete]
  130. // CHECK:STDOUT: %struct_type.base: type = struct_type {.base: %B} [concrete = constants.%struct_type.base]
  131. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.base [concrete = constants.%complete_type.98e]
  132. // CHECK:STDOUT: complete_type_witness = %complete_type
  133. // CHECK:STDOUT:
  134. // CHECK:STDOUT: !members:
  135. // CHECK:STDOUT: .Self = constants.%C3
  136. // CHECK:STDOUT: .B = <poisoned>
  137. // CHECK:STDOUT: .base = %.loc41
  138. // CHECK:STDOUT: extend %B.ref
  139. // CHECK:STDOUT: }
  140. // CHECK:STDOUT:
  141. // CHECK:STDOUT: class @C4 {
  142. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [concrete = constants.%B]
  143. // CHECK:STDOUT: %.loc52: %C4.elem = base_decl %B.ref, element0 [concrete]
  144. // CHECK:STDOUT: %struct_type.base: type = struct_type {.base: %B} [concrete = constants.%struct_type.base]
  145. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.base [concrete = constants.%complete_type.98e]
  146. // CHECK:STDOUT: complete_type_witness = %complete_type
  147. // CHECK:STDOUT:
  148. // CHECK:STDOUT: !members:
  149. // CHECK:STDOUT: .Self = constants.%C4
  150. // CHECK:STDOUT: .B = <poisoned>
  151. // CHECK:STDOUT: .base = %.loc52
  152. // CHECK:STDOUT: extend %B.ref
  153. // CHECK:STDOUT: }
  154. // CHECK:STDOUT: