fail_extend_cycle.carbon 5.0 KB

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