fail_import_misuses.carbon 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  6. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  7. //
  8. // AUTOUPDATE
  9. // TIP: To test this file alone, run:
  10. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/fail_import_misuses.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/fail_import_misuses.carbon
  13. // --- a.carbon
  14. library "[[@TEST_NAME]]";
  15. class Empty {
  16. }
  17. class Incomplete;
  18. // --- fail_b.carbon
  19. library "[[@TEST_NAME]]";
  20. import library "a";
  21. // CHECK:STDERR: fail_b.carbon:[[@LINE+8]]:1: error: redeclaration of `class Empty` is redundant [RedeclRedundant]
  22. // CHECK:STDERR: class Empty {
  23. // CHECK:STDERR: ^~~~~~~~~~~~~
  24. // CHECK:STDERR: fail_b.carbon:[[@LINE-5]]:1: in import [InImport]
  25. // CHECK:STDERR: a.carbon:4:1: note: previously declared here [RedeclPrevDecl]
  26. // CHECK:STDERR: class Empty {
  27. // CHECK:STDERR: ^~~~~~~~~~~~~
  28. // CHECK:STDERR:
  29. class Empty {
  30. }
  31. // CHECK:STDERR: fail_b.carbon:[[@LINE+8]]:8: error: binding pattern has incomplete type `Incomplete` in name binding declaration [IncompleteTypeInBindingDecl]
  32. // CHECK:STDERR: var a: Incomplete;
  33. // CHECK:STDERR: ^~~~~~~~~~
  34. // CHECK:STDERR: fail_b.carbon:[[@LINE-16]]:1: in import [InImport]
  35. // CHECK:STDERR: a.carbon:7:1: note: class was forward declared here [ClassForwardDeclaredHere]
  36. // CHECK:STDERR: class Incomplete;
  37. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  38. // CHECK:STDERR:
  39. var a: Incomplete;
  40. // CHECK:STDOUT: --- a.carbon
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: constants {
  43. // CHECK:STDOUT: %Empty: type = class_type @Empty [concrete]
  44. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  45. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  46. // CHECK:STDOUT: %Incomplete: type = class_type @Incomplete [concrete]
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: imports {
  50. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  51. // CHECK:STDOUT: import Core//prelude
  52. // CHECK:STDOUT: import Core//prelude/...
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: file {
  57. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  58. // CHECK:STDOUT: .Core = imports.%Core
  59. // CHECK:STDOUT: .Empty = %Empty.decl
  60. // CHECK:STDOUT: .Incomplete = %Incomplete.decl
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT: %Core.import = import Core
  63. // CHECK:STDOUT: %Empty.decl: type = class_decl @Empty [concrete = constants.%Empty] {} {}
  64. // CHECK:STDOUT: %Incomplete.decl: type = class_decl @Incomplete [concrete = constants.%Incomplete] {} {}
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: class @Empty {
  68. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  69. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
  70. // CHECK:STDOUT: complete_type_witness = %complete_type
  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.f48899.1: type = class_type @Empty.1 [concrete]
  82. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  83. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  84. // CHECK:STDOUT: %Empty.f48899.2: type = class_type @Empty.2 [concrete]
  85. // CHECK:STDOUT: %Incomplete: type = class_type @Incomplete [concrete]
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT:
  88. // CHECK:STDOUT: imports {
  89. // CHECK:STDOUT: %Main.Empty: type = import_ref Main//a, Empty, loaded [concrete = constants.%Empty.f48899.1]
  90. // CHECK:STDOUT: %Main.Incomplete: type = import_ref Main//a, Incomplete, loaded [concrete = constants.%Incomplete]
  91. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  92. // CHECK:STDOUT: import Core//prelude
  93. // CHECK:STDOUT: import Core//prelude/...
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT: %Main.import_ref.8f2: <witness> = import_ref Main//a, loc5_1, loaded [concrete = constants.%complete_type]
  96. // CHECK:STDOUT: %Main.import_ref.fd7 = import_ref Main//a, inst18 [no loc], unloaded
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: file {
  100. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  101. // CHECK:STDOUT: .Empty = imports.%Main.Empty
  102. // CHECK:STDOUT: .Incomplete = imports.%Main.Incomplete
  103. // CHECK:STDOUT: .Core = imports.%Core
  104. // CHECK:STDOUT: .a = %a
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT: %Core.import = import Core
  107. // CHECK:STDOUT: %default.import = import <none>
  108. // CHECK:STDOUT: %Empty.decl: type = class_decl @Empty.2 [concrete = constants.%Empty.f48899.2] {} {}
  109. // CHECK:STDOUT: name_binding_decl {
  110. // CHECK:STDOUT: %a.patt: <error> = binding_pattern a [concrete]
  111. // CHECK:STDOUT: %a.var_patt: <error> = var_pattern %a.patt [concrete]
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT: %a.var: ref <error> = var %a.var_patt [concrete = <error>]
  114. // CHECK:STDOUT: %Incomplete.ref: type = name_ref Incomplete, imports.%Main.Incomplete [concrete = constants.%Incomplete]
  115. // CHECK:STDOUT: %a: <error> = bind_name a, <error>
  116. // CHECK:STDOUT: }
  117. // CHECK:STDOUT:
  118. // CHECK:STDOUT: class @Empty.1 [from "a.carbon"] {
  119. // CHECK:STDOUT: complete_type_witness = imports.%Main.import_ref.8f2
  120. // CHECK:STDOUT:
  121. // CHECK:STDOUT: !members:
  122. // CHECK:STDOUT: .Self = imports.%Main.import_ref.fd7
  123. // CHECK:STDOUT: }
  124. // CHECK:STDOUT:
  125. // CHECK:STDOUT: class @Empty.2 {
  126. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  127. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
  128. // CHECK:STDOUT: complete_type_witness = %complete_type
  129. // CHECK:STDOUT:
  130. // CHECK:STDOUT: !members:
  131. // CHECK:STDOUT: .Self = constants.%Empty.f48899.2
  132. // CHECK:STDOUT: }
  133. // CHECK:STDOUT:
  134. // CHECK:STDOUT: class @Incomplete [from "a.carbon"];
  135. // CHECK:STDOUT: