fail_base_repeated.carbon 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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
  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
  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
  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
  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: %.1: type = struct_type {} [template]
  39. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  40. // CHECK:STDOUT: %B2: type = class_type @B2 [template]
  41. // CHECK:STDOUT: %C: type = class_type @C [template]
  42. // CHECK:STDOUT: %.3: type = tuple_type () [template]
  43. // CHECK:STDOUT: %.4: type = ptr_type %.1 [template]
  44. // CHECK:STDOUT: %.5: type = unbound_element_type %C, %B1 [template]
  45. // CHECK:STDOUT: %.6: type = struct_type {.base: %B1} [template]
  46. // CHECK:STDOUT: %.7: <witness> = complete_type_witness %.6 [template]
  47. // CHECK:STDOUT: %D: type = class_type @D [template]
  48. // CHECK:STDOUT: %.8: type = unbound_element_type %D, %B1 [template]
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: imports {
  52. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  53. // CHECK:STDOUT: import Core//prelude
  54. // CHECK:STDOUT: import Core//prelude/operators
  55. // CHECK:STDOUT: import Core//prelude/types
  56. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  57. // CHECK:STDOUT: import Core//prelude/operators/as
  58. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  59. // CHECK:STDOUT: import Core//prelude/operators/comparison
  60. // CHECK:STDOUT: import Core//prelude/types/bool
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: file {
  65. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  66. // CHECK:STDOUT: .Core = imports.%Core
  67. // CHECK:STDOUT: .B1 = %B1.decl
  68. // CHECK:STDOUT: .B2 = %B2.decl
  69. // CHECK:STDOUT: .C = %C.decl
  70. // CHECK:STDOUT: .D = %D.decl
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT: %Core.import = import Core
  73. // CHECK:STDOUT: %B1.decl: type = class_decl @B1 [template = constants.%B1] {} {}
  74. // CHECK:STDOUT: %B2.decl: type = class_decl @B2 [template = constants.%B2] {} {}
  75. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  76. // CHECK:STDOUT: %D.decl: type = class_decl @D [template = constants.%D] {} {}
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: class @B1 {
  80. // CHECK:STDOUT: %.loc11: <witness> = complete_type_witness %.1 [template = constants.%.2]
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: !members:
  83. // CHECK:STDOUT: .Self = constants.%B1
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: class @B2 {
  87. // CHECK:STDOUT: %.loc12: <witness> = complete_type_witness %.1 [template = constants.%.2]
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: !members:
  90. // CHECK:STDOUT: .Self = constants.%B2
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: class @C {
  94. // CHECK:STDOUT: %B1.ref: type = name_ref B1, file.%B1.decl [template = constants.%B1]
  95. // CHECK:STDOUT: %.loc15: %.5 = base_decl %B1, element0 [template]
  96. // CHECK:STDOUT: %B2.ref: type = name_ref B2, file.%B2.decl [template = constants.%B2]
  97. // CHECK:STDOUT: %.loc24: <witness> = complete_type_witness %.6 [template = constants.%.7]
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: !members:
  100. // CHECK:STDOUT: .Self = constants.%C
  101. // CHECK:STDOUT: .base = %.loc15
  102. // CHECK:STDOUT: extend name_scope2
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT:
  105. // CHECK:STDOUT: class @D {
  106. // CHECK:STDOUT: %B1.ref.loc28: type = name_ref B1, file.%B1.decl [template = constants.%B1]
  107. // CHECK:STDOUT: %.loc28: %.8 = base_decl %B1, element0 [template]
  108. // CHECK:STDOUT: %B1.ref.loc35: type = name_ref B1, file.%B1.decl [template = constants.%B1]
  109. // CHECK:STDOUT: %.loc36: <witness> = complete_type_witness %.6 [template = constants.%.7]
  110. // CHECK:STDOUT:
  111. // CHECK:STDOUT: !members:
  112. // CHECK:STDOUT: .Self = constants.%D
  113. // CHECK:STDOUT: .base = %.loc28
  114. // CHECK:STDOUT: extend name_scope2
  115. // CHECK:STDOUT: }
  116. // CHECK:STDOUT: