fail_import_misuses.carbon 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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_import_misuses.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/fail_import_misuses.carbon
  10. // --- a.carbon
  11. library "[[@TEST_NAME]]";
  12. class Empty {
  13. }
  14. class Incomplete;
  15. // --- fail_b.carbon
  16. library "[[@TEST_NAME]]";
  17. import library "a";
  18. // CHECK:STDERR: fail_b.carbon:[[@LINE+8]]:1: error: redeclaration of `class Empty` is redundant
  19. // CHECK:STDERR: class Empty {
  20. // CHECK:STDERR: ^~~~~~~~~~~~~
  21. // CHECK:STDERR: fail_b.carbon:[[@LINE-5]]:1: in import
  22. // CHECK:STDERR: a.carbon:4:1: note: previously declared here
  23. // CHECK:STDERR: class Empty {
  24. // CHECK:STDERR: ^~~~~~~~~~~~~
  25. // CHECK:STDERR:
  26. class Empty {
  27. }
  28. // CHECK:STDERR: fail_b.carbon:[[@LINE+7]]:8: error: Variable has incomplete type `Incomplete`
  29. // CHECK:STDERR: var a: Incomplete;
  30. // CHECK:STDERR: ^~~~~~~~~~
  31. // CHECK:STDERR: fail_b.carbon:[[@LINE-16]]:1: in import
  32. // CHECK:STDERR: a.carbon:7:1: note: class was forward declared here
  33. // CHECK:STDERR: class Incomplete;
  34. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  35. var a: Incomplete;
  36. // CHECK:STDOUT: --- a.carbon
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: constants {
  39. // CHECK:STDOUT: %Empty: type = class_type @Empty [template]
  40. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  41. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  42. // CHECK:STDOUT: %Incomplete: type = class_type @Incomplete [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/operators
  49. // CHECK:STDOUT: import Core//prelude/types
  50. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  51. // CHECK:STDOUT: import Core//prelude/operators/as
  52. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  53. // CHECK:STDOUT: import Core//prelude/operators/comparison
  54. // CHECK:STDOUT: import Core//prelude/types/bool
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: file {
  59. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  60. // CHECK:STDOUT: .Core = imports.%Core
  61. // CHECK:STDOUT: .Empty = %Empty.decl
  62. // CHECK:STDOUT: .Incomplete = %Incomplete.decl
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT: %Core.import = import Core
  65. // CHECK:STDOUT: %Empty.decl: type = class_decl @Empty [template = constants.%Empty] {} {}
  66. // CHECK:STDOUT: %Incomplete.decl: type = class_decl @Incomplete [template = constants.%Incomplete] {} {}
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: class @Empty {
  70. // CHECK:STDOUT: %.loc5: <witness> = complete_type_witness %.1 [template = constants.%.2]
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: !members:
  73. // CHECK:STDOUT: .Self = constants.%Empty
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: class @Incomplete;
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: --- fail_b.carbon
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: constants {
  81. // CHECK:STDOUT: %Empty: type = class_type @Empty [template]
  82. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  83. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  84. // CHECK:STDOUT: %.3: type = class_type @.1 [template]
  85. // CHECK:STDOUT: %Incomplete: type = class_type @Incomplete [template]
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT:
  88. // CHECK:STDOUT: imports {
  89. // CHECK:STDOUT: %import_ref.1: type = import_ref Main//a, inst+3, loaded [template = constants.%Empty]
  90. // CHECK:STDOUT: %import_ref.2: type = import_ref Main//a, inst+8, loaded [template = constants.%Incomplete]
  91. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  92. // CHECK:STDOUT: import Core//prelude
  93. // CHECK:STDOUT: import Core//prelude/operators
  94. // CHECK:STDOUT: import Core//prelude/types
  95. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  96. // CHECK:STDOUT: import Core//prelude/operators/as
  97. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  98. // CHECK:STDOUT: import Core//prelude/operators/comparison
  99. // CHECK:STDOUT: import Core//prelude/types/bool
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT: %import_ref.3 = import_ref Main//a, inst+4, unloaded
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT:
  104. // CHECK:STDOUT: file {
  105. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  106. // CHECK:STDOUT: .Empty = imports.%import_ref.1
  107. // CHECK:STDOUT: .Incomplete = imports.%import_ref.2
  108. // CHECK:STDOUT: .Core = imports.%Core
  109. // CHECK:STDOUT: .a = %a
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT: %Core.import = import Core
  112. // CHECK:STDOUT: %default.import = import <invalid>
  113. // CHECK:STDOUT: %.decl: type = class_decl @.1 [template = constants.%.3] {} {}
  114. // CHECK:STDOUT: %Incomplete.ref: type = name_ref Incomplete, imports.%import_ref.2 [template = constants.%Incomplete]
  115. // CHECK:STDOUT: %a.var: ref <error> = var a
  116. // CHECK:STDOUT: %a: ref <error> = bind_name a, %a.var
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: class @Empty {
  120. // CHECK:STDOUT: !members:
  121. // CHECK:STDOUT: .Self = imports.%import_ref.3
  122. // CHECK:STDOUT: }
  123. // CHECK:STDOUT:
  124. // CHECK:STDOUT: class @.1 {
  125. // CHECK:STDOUT: %.loc15: <witness> = complete_type_witness %.1 [template = constants.%.2]
  126. // CHECK:STDOUT:
  127. // CHECK:STDOUT: !members:
  128. // CHECK:STDOUT: .Self = constants.%.3
  129. // CHECK:STDOUT: }
  130. // CHECK:STDOUT:
  131. // CHECK:STDOUT: class @Incomplete;
  132. // CHECK:STDOUT: