fail_base_repeated.carbon 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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: 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: 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: %B2: type = class_type @B2 [template]
  40. // CHECK:STDOUT: %C: type = class_type @C [template]
  41. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  42. // CHECK:STDOUT: %.3: type = ptr_type %.1 [template]
  43. // CHECK:STDOUT: %.4: type = unbound_element_type %C, %B1 [template]
  44. // CHECK:STDOUT: %.5: type = struct_type {.base: %B1} [template]
  45. // CHECK:STDOUT: %D: type = class_type @D [template]
  46. // CHECK:STDOUT: %.6: type = unbound_element_type %D, %B1 [template]
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: file {
  50. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  51. // CHECK:STDOUT: .Core = %Core
  52. // CHECK:STDOUT: .B1 = %B1.decl
  53. // CHECK:STDOUT: .B2 = %B2.decl
  54. // CHECK:STDOUT: .C = %C.decl
  55. // CHECK:STDOUT: .D = %D.decl
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  58. // CHECK:STDOUT: %B1.decl: type = class_decl @B1 [template = constants.%B1] {}
  59. // CHECK:STDOUT: %B2.decl: type = class_decl @B2 [template = constants.%B2] {}
  60. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  61. // CHECK:STDOUT: %D.decl: type = class_decl @D [template = constants.%D] {}
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: class @B1 {
  65. // CHECK:STDOUT: !members:
  66. // CHECK:STDOUT: .Self = constants.%B1
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: class @B2 {
  70. // CHECK:STDOUT: !members:
  71. // CHECK:STDOUT: .Self = constants.%B2
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: class @C {
  75. // CHECK:STDOUT: %B1.ref: type = name_ref B1, file.%B1.decl [template = constants.%B1]
  76. // CHECK:STDOUT: %.loc15: %.4 = base_decl %B1, element0 [template]
  77. // CHECK:STDOUT: %B2.ref: type = name_ref B2, file.%B2.decl [template = constants.%B2]
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: !members:
  80. // CHECK:STDOUT: .Self = constants.%C
  81. // CHECK:STDOUT: .base = %.loc15
  82. // CHECK:STDOUT: extend name_scope2
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: class @D {
  86. // CHECK:STDOUT: %B1.ref.loc28: type = name_ref B1, file.%B1.decl [template = constants.%B1]
  87. // CHECK:STDOUT: %.loc28: %.6 = base_decl %B1, element0 [template]
  88. // CHECK:STDOUT: %B1.ref.loc35: type = name_ref B1, file.%B1.decl [template = constants.%B1]
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: !members:
  91. // CHECK:STDOUT: .Self = constants.%D
  92. // CHECK:STDOUT: .base = %.loc28
  93. // CHECK:STDOUT: extend name_scope2
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT: