fail_extend_cycle.carbon 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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`.
  17. // CHECK:STDERR: base class A {
  18. // CHECK:STDERR: ^~~~~~~~~~~~~~
  19. // CHECK:STDERR: fail_extend_cycle.carbon:[[@LINE-11]]:1: Previously defined here.
  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.
  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: %B: type = class_type @B [template]
  36. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  37. // CHECK:STDOUT: %.3: type = ptr_type %.1 [template]
  38. // CHECK:STDOUT: %.4: type = unbound_element_type %B, %A [template]
  39. // CHECK:STDOUT: %.5: type = struct_type {.base: %A} [template]
  40. // CHECK:STDOUT: %.6: type = class_type @.1 [template]
  41. // CHECK:STDOUT: %.7: type = unbound_element_type %.6, %A [template]
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: file {
  45. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  46. // CHECK:STDOUT: .Core = %Core
  47. // CHECK:STDOUT: .A = %A.decl
  48. // CHECK:STDOUT: .B = %B.decl
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  51. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {}
  52. // CHECK:STDOUT: %B.decl: type = class_decl @B [template = constants.%B] {}
  53. // CHECK:STDOUT: %.decl: type = class_decl @.1 [template = constants.%.6] {}
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: class @A {
  57. // CHECK:STDOUT: !members:
  58. // CHECK:STDOUT: .Self = constants.%A
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT:
  61. // CHECK:STDOUT: class @B {
  62. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  63. // CHECK:STDOUT: %.loc16: %.4 = base_decl %A, element0 [template]
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: !members:
  66. // CHECK:STDOUT: .Self = constants.%B
  67. // CHECK:STDOUT: .base = %.loc16
  68. // CHECK:STDOUT: extend name_scope2
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: class @.1 {
  72. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  73. // CHECK:STDOUT: %.loc27: %.7 = base_decl %A, element0 [template]
  74. // CHECK:STDOUT: %C.ref: <error> = name_ref C, <error> [template = <error>]
  75. // CHECK:STDOUT: %.loc31: <error> = field_decl c, element1 [template]
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: !members:
  78. // CHECK:STDOUT: .Self = constants.%.6
  79. // CHECK:STDOUT: .base = %.loc27
  80. // CHECK:STDOUT: .c = %.loc31
  81. // CHECK:STDOUT: extend name_scope2
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT: