fail_base_repeated.carbon 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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+6]]: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. extend base: B1;
  33. }
  34. // CHECK:STDOUT: --- fail_base_repeated.carbon
  35. // CHECK:STDOUT:
  36. // CHECK:STDOUT: constants {
  37. // CHECK:STDOUT: %B1: type = class_type @B1 [template]
  38. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
  39. // CHECK:STDOUT: %complete_type.357: <witness> = complete_type_witness %empty_struct_type [template]
  40. // CHECK:STDOUT: %B2: type = class_type @B2 [template]
  41. // CHECK:STDOUT: %C: type = class_type @C [template]
  42. // CHECK:STDOUT: %C.elem: type = unbound_element_type %C, %B1 [template]
  43. // CHECK:STDOUT: %struct_type.base: type = struct_type {.base: %B1} [template]
  44. // CHECK:STDOUT: %complete_type.5ac: <witness> = complete_type_witness %struct_type.base [template]
  45. // CHECK:STDOUT: %D: type = class_type @D [template]
  46. // CHECK:STDOUT: %D.elem: type = unbound_element_type %D, %B1 [template]
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: imports {
  50. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  51. // CHECK:STDOUT: import Core//prelude
  52. // CHECK:STDOUT: import Core//prelude/...
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: file {
  57. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  58. // CHECK:STDOUT: .Core = imports.%Core
  59. // CHECK:STDOUT: .B1 = %B1.decl
  60. // CHECK:STDOUT: .B2 = %B2.decl
  61. // CHECK:STDOUT: .C = %C.decl
  62. // CHECK:STDOUT: .D = %D.decl
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT: %Core.import = import Core
  65. // CHECK:STDOUT: %B1.decl: type = class_decl @B1 [template = constants.%B1] {} {}
  66. // CHECK:STDOUT: %B2.decl: type = class_decl @B2 [template = constants.%B2] {} {}
  67. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  68. // CHECK:STDOUT: %D.decl: type = class_decl @D [template = constants.%D] {} {}
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: class @B1 {
  72. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type.357]
  73. // CHECK:STDOUT: complete_type_witness = %complete_type
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: !members:
  76. // CHECK:STDOUT: .Self = constants.%B1
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: class @B2 {
  80. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type.357]
  81. // CHECK:STDOUT: complete_type_witness = %complete_type
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: !members:
  84. // CHECK:STDOUT: .Self = constants.%B2
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: class @C {
  88. // CHECK:STDOUT: %B1.ref: type = name_ref B1, file.%B1.decl [template = constants.%B1]
  89. // CHECK:STDOUT: %.loc15: %C.elem = base_decl %B1.ref, element0 [template]
  90. // CHECK:STDOUT: %B2.ref: type = name_ref B2, file.%B2.decl [template = constants.%B2]
  91. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.base [template = constants.%complete_type.5ac]
  92. // CHECK:STDOUT: complete_type_witness = %complete_type
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: !members:
  95. // CHECK:STDOUT: .Self = constants.%C
  96. // CHECK:STDOUT: .base = %.loc15
  97. // CHECK:STDOUT: extend %B1.ref
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT:
  100. // CHECK:STDOUT: class @D {
  101. // CHECK:STDOUT: %B1.ref.loc28: type = name_ref B1, file.%B1.decl [template = constants.%B1]
  102. // CHECK:STDOUT: %.loc28: %D.elem = base_decl %B1.ref.loc28, element0 [template]
  103. // CHECK:STDOUT: %B1.ref.loc35: type = name_ref B1, file.%B1.decl [template = constants.%B1]
  104. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.base [template = constants.%complete_type.5ac]
  105. // CHECK:STDOUT: complete_type_witness = %complete_type
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: !members:
  108. // CHECK:STDOUT: .Self = constants.%D
  109. // CHECK:STDOUT: .base = %.loc28
  110. // CHECK:STDOUT: extend %B1.ref.loc28
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT: