fail_extend_cycle.carbon 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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+3]]:10: error: name `C` not found [NameNotFound]
  26. // CHECK:STDERR: var c: C;
  27. // CHECK:STDERR: ^
  28. var c: C;
  29. }
  30. // CHECK:STDOUT: --- fail_extend_cycle.carbon
  31. // CHECK:STDOUT:
  32. // CHECK:STDOUT: constants {
  33. // CHECK:STDOUT: %A: type = class_type @A [template]
  34. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  35. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  36. // CHECK:STDOUT: %B: type = class_type @B [template]
  37. // CHECK:STDOUT: %.4: type = unbound_element_type %B, %A [template]
  38. // CHECK:STDOUT: %.5: type = struct_type {.base: %A} [template]
  39. // CHECK:STDOUT: %.6: <witness> = complete_type_witness %.5 [template]
  40. // CHECK:STDOUT: %.7: type = class_type @.1 [template]
  41. // CHECK:STDOUT: %.8: type = unbound_element_type %.7, %A [template]
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: imports {
  45. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  46. // CHECK:STDOUT: import Core//prelude
  47. // CHECK:STDOUT: import Core//prelude/...
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: file {
  52. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  53. // CHECK:STDOUT: .Core = imports.%Core
  54. // CHECK:STDOUT: .A = %A.decl
  55. // CHECK:STDOUT: .B = %B.decl
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT: %Core.import = import Core
  58. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {} {}
  59. // CHECK:STDOUT: %B.decl: type = class_decl @B [template = constants.%B] {} {}
  60. // CHECK:STDOUT: %.decl: type = class_decl @.1 [template = constants.%.7] {} {}
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: class @A {
  64. // CHECK:STDOUT: %.loc12: <witness> = complete_type_witness %.1 [template = constants.%.2]
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: !members:
  67. // CHECK:STDOUT: .Self = constants.%A
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: class @B {
  71. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  72. // CHECK:STDOUT: %.loc16: %.4 = base_decl %A, element0 [template]
  73. // CHECK:STDOUT: %.loc17: <witness> = complete_type_witness %.5 [template = constants.%.6]
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: !members:
  76. // CHECK:STDOUT: .Self = constants.%B
  77. // CHECK:STDOUT: .base = %.loc16
  78. // CHECK:STDOUT: extend %A.ref
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: class @.1 {
  82. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  83. // CHECK:STDOUT: %.loc27: %.8 = base_decl %A, element0 [template]
  84. // CHECK:STDOUT: %C.ref: <error> = name_ref C, <error> [template = <error>]
  85. // CHECK:STDOUT: %.loc31: <error> = field_decl c, element1 [template]
  86. // CHECK:STDOUT: %.loc32: <witness> = complete_type_witness <error> [template = <error>]
  87. // CHECK:STDOUT:
  88. // CHECK:STDOUT: !members:
  89. // CHECK:STDOUT: .Self = constants.%.7
  90. // CHECK:STDOUT: .base = %.loc27
  91. // CHECK:STDOUT: .c = %.loc31
  92. // CHECK:STDOUT: extend %A.ref
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT: