fail_base_modifiers.carbon 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. base class B {}
  7. class C1 {
  8. // CHECK:STDERR: fail_base_modifiers.carbon:[[@LINE+4]]:3: ERROR: `private` not allowed on `base` declaration.
  9. // CHECK:STDERR: private extend base: B;
  10. // CHECK:STDERR: ^~~~~~~
  11. // CHECK:STDERR:
  12. private extend base: B;
  13. }
  14. class C2 {
  15. // CHECK:STDERR: fail_base_modifiers.carbon:[[@LINE+8]]:3: ERROR: `abstract` not allowed on `base` declaration.
  16. // CHECK:STDERR: abstract base: B;
  17. // CHECK:STDERR: ^~~~~~~~
  18. // CHECK:STDERR:
  19. // CHECK:STDERR: fail_base_modifiers.carbon:[[@LINE+4]]:3: ERROR: Missing `extend` before `base` declaration in class.
  20. // CHECK:STDERR: abstract base: B;
  21. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  22. // CHECK:STDERR:
  23. abstract base: B;
  24. }
  25. class C3 {
  26. // CHECK:STDERR: fail_base_modifiers.carbon:[[@LINE+7]]:10: ERROR: `default` not allowed on declaration with `extend`.
  27. // CHECK:STDERR: extend default base: B;
  28. // CHECK:STDERR: ^~~~~~~
  29. // CHECK:STDERR: fail_base_modifiers.carbon:[[@LINE+4]]:3: `extend` previously appeared here.
  30. // CHECK:STDERR: extend default base: B;
  31. // CHECK:STDERR: ^~~~~~
  32. // CHECK:STDERR:
  33. extend default base: B;
  34. }
  35. class C4 {
  36. // CHECK:STDERR: fail_base_modifiers.carbon:[[@LINE+6]]:10: ERROR: `extend` repeated on declaration.
  37. // CHECK:STDERR: extend extend base: B;
  38. // CHECK:STDERR: ^~~~~~
  39. // CHECK:STDERR: fail_base_modifiers.carbon:[[@LINE+3]]:3: `extend` previously appeared here.
  40. // CHECK:STDERR: extend extend base: B;
  41. // CHECK:STDERR: ^~~~~~
  42. extend extend base: B;
  43. }
  44. // CHECK:STDOUT: --- fail_base_modifiers.carbon
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: constants {
  47. // CHECK:STDOUT: %B: type = class_type @B [template]
  48. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  49. // CHECK:STDOUT: %C1: type = class_type @C1 [template]
  50. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  51. // CHECK:STDOUT: %.3: type = ptr_type {} [template]
  52. // CHECK:STDOUT: %.4: type = unbound_element_type C1, B [template]
  53. // CHECK:STDOUT: %.5: type = struct_type {.base: B} [template]
  54. // CHECK:STDOUT: %C2: type = class_type @C2 [template]
  55. // CHECK:STDOUT: %.6: type = unbound_element_type C2, B [template]
  56. // CHECK:STDOUT: %C3: type = class_type @C3 [template]
  57. // CHECK:STDOUT: %.7: type = unbound_element_type C3, B [template]
  58. // CHECK:STDOUT: %C4: type = class_type @C4 [template]
  59. // CHECK:STDOUT: %.8: type = unbound_element_type C4, B [template]
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: file {
  63. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  64. // CHECK:STDOUT: .Core = %Core
  65. // CHECK:STDOUT: .B = %B.decl
  66. // CHECK:STDOUT: .C1 = %C1.decl
  67. // CHECK:STDOUT: .C2 = %C2.decl
  68. // CHECK:STDOUT: .C3 = %C3.decl
  69. // CHECK:STDOUT: .C4 = %C4.decl
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  72. // CHECK:STDOUT: %B.decl: type = class_decl @B [template = constants.%B] {}
  73. // CHECK:STDOUT: %C1.decl: type = class_decl @C1 [template = constants.%C1] {}
  74. // CHECK:STDOUT: %C2.decl: type = class_decl @C2 [template = constants.%C2] {}
  75. // CHECK:STDOUT: %C3.decl: type = class_decl @C3 [template = constants.%C3] {}
  76. // CHECK:STDOUT: %C4.decl: type = class_decl @C4 [template = constants.%C4] {}
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: class @B {
  80. // CHECK:STDOUT: !members:
  81. // CHECK:STDOUT: .Self = constants.%B
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: class @C1 {
  85. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [template = constants.%B]
  86. // CHECK:STDOUT: %.loc14: <unbound element of class C1> = base_decl B, element0 [template]
  87. // CHECK:STDOUT:
  88. // CHECK:STDOUT: !members:
  89. // CHECK:STDOUT: .Self = constants.%C1
  90. // CHECK:STDOUT: .base = %.loc14
  91. // CHECK:STDOUT: extend name_scope2
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: class @C2 {
  95. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [template = constants.%B]
  96. // CHECK:STDOUT: %.loc26: <unbound element of class C2> = base_decl B, element0 [template]
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: !members:
  99. // CHECK:STDOUT: .Self = constants.%C2
  100. // CHECK:STDOUT: .base = %.loc26
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: class @C3 {
  104. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [template = constants.%B]
  105. // CHECK:STDOUT: %.loc37: <unbound element of class C3> = base_decl B, element0 [template]
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: !members:
  108. // CHECK:STDOUT: .Self = constants.%C3
  109. // CHECK:STDOUT: .base = %.loc37
  110. // CHECK:STDOUT: extend name_scope2
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT:
  113. // CHECK:STDOUT: class @C4 {
  114. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [template = constants.%B]
  115. // CHECK:STDOUT: %.loc47: <unbound element of class C4> = base_decl B, element0 [template]
  116. // CHECK:STDOUT:
  117. // CHECK:STDOUT: !members:
  118. // CHECK:STDOUT: .Self = constants.%C4
  119. // CHECK:STDOUT: .base = %.loc47
  120. // CHECK:STDOUT: extend name_scope2
  121. // CHECK:STDOUT: }
  122. // CHECK:STDOUT: