fail_base_modifiers.carbon 4.6 KB

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