fail_extend_cycle.carbon 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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: type = class_type @A [template]
  35. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
  36. // CHECK:STDOUT: %complete_type.357: <witness> = complete_type_witness %empty_struct_type [template]
  37. // CHECK:STDOUT: %B: type = class_type @B [template]
  38. // CHECK:STDOUT: %B.elem: type = unbound_element_type %B, %A [template]
  39. // CHECK:STDOUT: %struct_type.base: type = struct_type {.base: %A} [template]
  40. // CHECK:STDOUT: %complete_type.020: <witness> = complete_type_witness %struct_type.base [template]
  41. // CHECK:STDOUT: %.a95: type = class_type @.1 [template]
  42. // CHECK:STDOUT: %.elem: type = unbound_element_type %.a95, %A [template]
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: imports {
  46. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  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 [template] {
  54. // CHECK:STDOUT: .Core = imports.%Core
  55. // CHECK:STDOUT: .A = %A.decl
  56. // CHECK:STDOUT: .B = %B.decl
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT: %Core.import = import Core
  59. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {} {}
  60. // CHECK:STDOUT: %B.decl: type = class_decl @B [template = constants.%B] {} {}
  61. // CHECK:STDOUT: %.decl: type = class_decl @.1 [template = constants.%.a95] {} {}
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: class @A {
  65. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type.357]
  66. // CHECK:STDOUT: complete_type_witness = %complete_type
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: !members:
  69. // CHECK:STDOUT: .Self = constants.%A
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: class @B {
  73. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  74. // CHECK:STDOUT: %.loc16: %B.elem = base_decl %A.ref, element0 [template]
  75. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.base [template = constants.%complete_type.020]
  76. // CHECK:STDOUT: complete_type_witness = %complete_type
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: !members:
  79. // CHECK:STDOUT: .Self = constants.%B
  80. // CHECK:STDOUT: .base = %.loc16
  81. // CHECK:STDOUT: extend %A.ref
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: class @.1 {
  85. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  86. // CHECK:STDOUT: %.loc27: %.elem = base_decl %A.ref, element0 [template]
  87. // CHECK:STDOUT: %.loc32_8: <error> = field_decl c, element1 [template]
  88. // CHECK:STDOUT: name_binding_decl {
  89. // CHECK:STDOUT: %.loc32_3: <error> = var_pattern %.loc32_8
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT: %.var: ref <error> = var <none>
  92. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness <error> [template = <error>]
  93. // CHECK:STDOUT: complete_type_witness = %complete_type
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: !members:
  96. // CHECK:STDOUT: .Self = constants.%.a95
  97. // CHECK:STDOUT: .base = %.loc27
  98. // CHECK:STDOUT: .c = %.loc32_8
  99. // CHECK:STDOUT: extend %A.ref
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT: