fail_base_repeated.carbon 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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_repeated.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_repeated.carbon
  10. base class B1 {}
  11. base class B2 {}
  12. class C {
  13. extend base: B1;
  14. // CHECK:STDERR: fail_base_repeated.carbon:[[@LINE+7]]:3: error: multiple `base` declarations in class; multiple inheritance is not permitted [BaseDeclRepeated]
  15. // CHECK:STDERR: extend base: B2;
  16. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  17. // CHECK:STDERR: fail_base_repeated.carbon:[[@LINE-4]]:3: note: previous `base` declaration is here [ClassSpecificDeclPrevious]
  18. // CHECK:STDERR: extend base: B1;
  19. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  20. // CHECK:STDERR:
  21. extend base: B2;
  22. }
  23. class D {
  24. // TODO: Consider adding a custom diagnostic for this case.
  25. extend base: B1;
  26. // CHECK:STDERR: fail_base_repeated.carbon:[[@LINE+7]]:3: error: multiple `base` declarations in class; multiple inheritance is not permitted [BaseDeclRepeated]
  27. // CHECK:STDERR: extend base: B1;
  28. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  29. // CHECK:STDERR: fail_base_repeated.carbon:[[@LINE-4]]:3: note: previous `base` declaration is here [ClassSpecificDeclPrevious]
  30. // CHECK:STDERR: extend base: B1;
  31. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  32. // CHECK:STDERR:
  33. extend base: B1;
  34. }
  35. // CHECK:STDOUT: --- fail_base_repeated.carbon
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: constants {
  38. // CHECK:STDOUT: %B1: type = class_type @B1 [concrete]
  39. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  40. // CHECK:STDOUT: %complete_type.357: <witness> = complete_type_witness %empty_struct_type [concrete]
  41. // CHECK:STDOUT: %B2: type = class_type @B2 [concrete]
  42. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  43. // CHECK:STDOUT: %C.elem: type = unbound_element_type %C, %B1 [concrete]
  44. // CHECK:STDOUT: %struct_type.base: type = struct_type {.base: %B1} [concrete]
  45. // CHECK:STDOUT: %complete_type.5ac: <witness> = complete_type_witness %struct_type.base [concrete]
  46. // CHECK:STDOUT: %D: type = class_type @D [concrete]
  47. // CHECK:STDOUT: %D.elem: type = unbound_element_type %D, %B1 [concrete]
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT:
  50. // CHECK:STDOUT: imports {
  51. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  52. // CHECK:STDOUT: import Core//prelude
  53. // CHECK:STDOUT: import Core//prelude/...
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: file {
  58. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  59. // CHECK:STDOUT: .Core = imports.%Core
  60. // CHECK:STDOUT: .B1 = %B1.decl
  61. // CHECK:STDOUT: .B2 = %B2.decl
  62. // CHECK:STDOUT: .C = %C.decl
  63. // CHECK:STDOUT: .D = %D.decl
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT: %Core.import = import Core
  66. // CHECK:STDOUT: %B1.decl: type = class_decl @B1 [concrete = constants.%B1] {} {}
  67. // CHECK:STDOUT: %B2.decl: type = class_decl @B2 [concrete = constants.%B2] {} {}
  68. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  69. // CHECK:STDOUT: %D.decl: type = class_decl @D [concrete = constants.%D] {} {}
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: class @B1 {
  73. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type.357]
  74. // CHECK:STDOUT: complete_type_witness = %complete_type
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: !members:
  77. // CHECK:STDOUT: .Self = constants.%B1
  78. // CHECK:STDOUT: .B2 = <poisoned>
  79. // CHECK:STDOUT: .B1 = <poisoned>
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: class @B2 {
  83. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type.357]
  84. // CHECK:STDOUT: complete_type_witness = %complete_type
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: !members:
  87. // CHECK:STDOUT: .Self = constants.%B2
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: class @C {
  91. // CHECK:STDOUT: %B1.ref: type = name_ref B1, file.%B1.decl [concrete = constants.%B1]
  92. // CHECK:STDOUT: %.loc15: %C.elem = base_decl %B1.ref, element0 [concrete]
  93. // CHECK:STDOUT: %B2.ref: type = name_ref B2, file.%B2.decl [concrete = constants.%B2]
  94. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.base [concrete = constants.%complete_type.5ac]
  95. // CHECK:STDOUT: complete_type_witness = %complete_type
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: !members:
  98. // CHECK:STDOUT: .Self = constants.%C
  99. // CHECK:STDOUT: .B1 = <poisoned>
  100. // CHECK:STDOUT: .base = %.loc15
  101. // CHECK:STDOUT: .B2 = <poisoned>
  102. // CHECK:STDOUT: extend %B1.ref
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT:
  105. // CHECK:STDOUT: class @D {
  106. // CHECK:STDOUT: %B1.ref.loc28: type = name_ref B1, file.%B1.decl [concrete = constants.%B1]
  107. // CHECK:STDOUT: %.loc28: %D.elem = base_decl %B1.ref.loc28, element0 [concrete]
  108. // CHECK:STDOUT: %B1.ref.loc36: type = name_ref B1, file.%B1.decl [concrete = constants.%B1]
  109. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.base [concrete = constants.%complete_type.5ac]
  110. // CHECK:STDOUT: complete_type_witness = %complete_type
  111. // CHECK:STDOUT:
  112. // CHECK:STDOUT: !members:
  113. // CHECK:STDOUT: .Self = constants.%D
  114. // CHECK:STDOUT: .B1 = <poisoned>
  115. // CHECK:STDOUT: .base = %.loc28
  116. // CHECK:STDOUT: extend %B1.ref.loc28
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT: