fail_extend_cycle.carbon 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  6. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  7. //
  8. // AUTOUPDATE
  9. // TIP: To test this file alone, run:
  10. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/fail_extend_cycle.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/fail_extend_cycle.carbon
  13. base class A {
  14. }
  15. base class B {
  16. // This ensures that the compiler treats A as complete.
  17. extend base: A;
  18. }
  19. // CHECK:STDERR: fail_extend_cycle.carbon:[[@LINE+7]]:1: error: redefinition of `class A` [RedeclRedef]
  20. // CHECK:STDERR: base class A {
  21. // CHECK:STDERR: ^~~~~~~~~~~~~~
  22. // CHECK:STDERR: fail_extend_cycle.carbon:[[@LINE-11]]:1: note: previously defined here [RedeclPrevDef]
  23. // CHECK:STDERR: base class A {
  24. // CHECK:STDERR: ^~~~~~~~~~~~~~
  25. // CHECK:STDERR:
  26. base class A {
  27. extend base: A;
  28. // CHECK:STDERR: fail_extend_cycle.carbon:[[@LINE+4]]:10: error: name `C` not found [NameNotFound]
  29. // CHECK:STDERR: var c: C;
  30. // CHECK:STDERR: ^
  31. // CHECK:STDERR:
  32. var c: C;
  33. }
  34. // CHECK:STDOUT: --- fail_extend_cycle.carbon
  35. // CHECK:STDOUT:
  36. // CHECK:STDOUT: constants {
  37. // CHECK:STDOUT: %A.466950.1: type = class_type @A.1 [concrete]
  38. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  39. // CHECK:STDOUT: %complete_type.357: <witness> = complete_type_witness %empty_struct_type [concrete]
  40. // CHECK:STDOUT: %B: type = class_type @B [concrete]
  41. // CHECK:STDOUT: %B.elem: type = unbound_element_type %B, %A.466950.1 [concrete]
  42. // CHECK:STDOUT: %struct_type.base: type = struct_type {.base: %A.466950.1} [concrete]
  43. // CHECK:STDOUT: %complete_type.020: <witness> = complete_type_witness %struct_type.base [concrete]
  44. // CHECK:STDOUT: %A.466950.2: type = class_type @A.2 [concrete]
  45. // CHECK:STDOUT: %A.elem: type = unbound_element_type %A.466950.2, %A.466950.1 [concrete]
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT:
  48. // CHECK:STDOUT: imports {
  49. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  50. // CHECK:STDOUT: import Core//prelude
  51. // CHECK:STDOUT: import Core//prelude/...
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: file {
  56. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  57. // CHECK:STDOUT: .Core = imports.%Core
  58. // CHECK:STDOUT: .A = %A.decl.loc14
  59. // CHECK:STDOUT: .B = %B.decl
  60. // CHECK:STDOUT: .C = <poisoned>
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT: %Core.import = import Core
  63. // CHECK:STDOUT: %A.decl.loc14: type = class_decl @A.1 [concrete = constants.%A.466950.1] {} {}
  64. // CHECK:STDOUT: %B.decl: type = class_decl @B [concrete = constants.%B] {} {}
  65. // CHECK:STDOUT: %A.decl.loc29: type = class_decl @A.2 [concrete = constants.%A.466950.2] {} {}
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: class @A.1 {
  69. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  70. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type.357]
  71. // CHECK:STDOUT: complete_type_witness = %complete_type
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: !members:
  74. // CHECK:STDOUT: .Self = constants.%A.466950.1
  75. // CHECK:STDOUT: .C = <poisoned>
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: class @B {
  79. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl.loc14 [concrete = constants.%A.466950.1]
  80. // CHECK:STDOUT: %.loc19: %B.elem = base_decl %A.ref, element0 [concrete]
  81. // CHECK:STDOUT: %struct_type.base: type = struct_type {.base: %A.466950.1} [concrete = constants.%struct_type.base]
  82. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.base [concrete = constants.%complete_type.020]
  83. // CHECK:STDOUT: complete_type_witness = %complete_type
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: !members:
  86. // CHECK:STDOUT: .Self = constants.%B
  87. // CHECK:STDOUT: .A = <poisoned>
  88. // CHECK:STDOUT: .base = %.loc19
  89. // CHECK:STDOUT: extend %A.ref
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: class @A.2 {
  93. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl.loc14 [concrete = constants.%A.466950.1]
  94. // CHECK:STDOUT: %.loc30: %A.elem = base_decl %A.ref, element0 [concrete]
  95. // CHECK:STDOUT: %C.ref: <error> = name_ref C, <error> [concrete = <error>]
  96. // CHECK:STDOUT: %.loc35: <error> = field_decl c, element1 [concrete]
  97. // CHECK:STDOUT: %struct_type.base.c: type = struct_type {.base: %A.466950.1, .c: <error>} [concrete = <error>]
  98. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.base.c [concrete = <error>]
  99. // CHECK:STDOUT: complete_type_witness = %complete_type
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: !members:
  102. // CHECK:STDOUT: .Self = constants.%A.466950.2
  103. // CHECK:STDOUT: .A = <poisoned>
  104. // CHECK:STDOUT: .base = %.loc30
  105. // CHECK:STDOUT: .C = <poisoned>
  106. // CHECK:STDOUT: .c = %.loc35
  107. // CHECK:STDOUT: extend %A.ref
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT: