fail_base_repeated.carbon 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 B1 {}
  7. base class B2 {}
  8. class C {
  9. extend base: B1;
  10. // CHECK:STDERR: fail_base_repeated.carbon:[[@LINE+7]]:3: ERROR: Multiple `base` declarations in class. Multiple inheritance is not permitted.
  11. // CHECK:STDERR: extend base: B2;
  12. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  13. // CHECK:STDERR: fail_base_repeated.carbon:[[@LINE-4]]:3: Previous `base` declaration is here.
  14. // CHECK:STDERR: extend base: B1;
  15. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  16. // CHECK:STDERR:
  17. extend base: B2;
  18. }
  19. class D {
  20. // TODO: Consider adding a custom diagnostic for this case.
  21. extend base: B1;
  22. // CHECK:STDERR: fail_base_repeated.carbon:[[@LINE+6]]:3: ERROR: Multiple `base` declarations in class. Multiple inheritance is not permitted.
  23. // CHECK:STDERR: extend base: B1;
  24. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  25. // CHECK:STDERR: fail_base_repeated.carbon:[[@LINE-4]]:3: Previous `base` declaration is here.
  26. // CHECK:STDERR: extend base: B1;
  27. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  28. extend base: B1;
  29. }
  30. // CHECK:STDOUT: --- fail_base_repeated.carbon
  31. // CHECK:STDOUT:
  32. // CHECK:STDOUT: constants {
  33. // CHECK:STDOUT: %B1: type = class_type @B1 [template]
  34. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  35. // CHECK:STDOUT: %B2: type = class_type @B2 [template]
  36. // CHECK:STDOUT: %C: type = class_type @C [template]
  37. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  38. // CHECK:STDOUT: %.3: type = ptr_type {} [template]
  39. // CHECK:STDOUT: %.4: type = unbound_element_type C, B1 [template]
  40. // CHECK:STDOUT: %.5: type = struct_type {.base: B1} [template]
  41. // CHECK:STDOUT: %D: type = class_type @D [template]
  42. // CHECK:STDOUT: %.6: type = unbound_element_type D, B1 [template]
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: file {
  46. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  47. // CHECK:STDOUT: .Core = %Core
  48. // CHECK:STDOUT: .B1 = %B1.decl
  49. // CHECK:STDOUT: .B2 = %B2.decl
  50. // CHECK:STDOUT: .C = %C.decl
  51. // CHECK:STDOUT: .D = %D.decl
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  54. // CHECK:STDOUT: %B1.decl: type = class_decl @B1 [template = constants.%B1] {}
  55. // CHECK:STDOUT: %B2.decl: type = class_decl @B2 [template = constants.%B2] {}
  56. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  57. // CHECK:STDOUT: %D.decl: type = class_decl @D [template = constants.%D] {}
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: class @B1 {
  61. // CHECK:STDOUT: !members:
  62. // CHECK:STDOUT: .Self = constants.%B1
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: class @B2 {
  66. // CHECK:STDOUT: !members:
  67. // CHECK:STDOUT: .Self = constants.%B2
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: class @C {
  71. // CHECK:STDOUT: %B1.ref: type = name_ref B1, file.%B1.decl [template = constants.%B1]
  72. // CHECK:STDOUT: %.loc11: <unbound element of class C> = base_decl B1, element0 [template]
  73. // CHECK:STDOUT: %B2.ref: type = name_ref B2, file.%B2.decl [template = constants.%B2]
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: !members:
  76. // CHECK:STDOUT: .Self = constants.%C
  77. // CHECK:STDOUT: .base = %.loc11
  78. // CHECK:STDOUT: extend name_scope2
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: class @D {
  82. // CHECK:STDOUT: %B1.ref.loc24: type = name_ref B1, file.%B1.decl [template = constants.%B1]
  83. // CHECK:STDOUT: %.loc24: <unbound element of class D> = base_decl B1, element0 [template]
  84. // CHECK:STDOUT: %B1.ref.loc31: type = name_ref B1, file.%B1.decl [template = constants.%B1]
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: !members:
  87. // CHECK:STDOUT: .Self = constants.%D
  88. // CHECK:STDOUT: .base = %.loc24
  89. // CHECK:STDOUT: extend name_scope2
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT: