fail_import_misuses.carbon 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 [RedeclRedundant]
  19. // CHECK:STDERR: class Empty {
  20. // CHECK:STDERR: ^~~~~~~~~~~~~
  21. // CHECK:STDERR: fail_b.carbon:[[@LINE-5]]:1: in import [InImport]
  22. // CHECK:STDERR: a.carbon:4:1: note: previously declared here [RedeclPrevDecl]
  23. // CHECK:STDERR: class Empty {
  24. // CHECK:STDERR: ^~~~~~~~~~~~~
  25. // CHECK:STDERR:
  26. class Empty {
  27. }
  28. // CHECK:STDERR: fail_b.carbon:[[@LINE+8]]:8: error: binding pattern has incomplete type `Incomplete` in name binding declaration [IncompleteTypeInBindingDecl]
  29. // CHECK:STDERR: var a: Incomplete;
  30. // CHECK:STDERR: ^~~~~~~~~~
  31. // CHECK:STDERR: fail_b.carbon:[[@LINE-16]]:1: in import [InImport]
  32. // CHECK:STDERR: a.carbon:7:1: note: class was forward declared here [ClassForwardDeclaredHere]
  33. // CHECK:STDERR: class Incomplete;
  34. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  35. // CHECK:STDERR:
  36. var a: Incomplete;
  37. // CHECK:STDOUT: --- a.carbon
  38. // CHECK:STDOUT:
  39. // CHECK:STDOUT: constants {
  40. // CHECK:STDOUT: %Empty: type = class_type @Empty [template]
  41. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
  42. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template]
  43. // CHECK:STDOUT: %Incomplete: type = class_type @Incomplete [template]
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: imports {
  47. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  48. // CHECK:STDOUT: import Core//prelude
  49. // CHECK:STDOUT: import Core//prelude/...
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: file {
  54. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  55. // CHECK:STDOUT: .Core = imports.%Core
  56. // CHECK:STDOUT: .Empty = %Empty.decl
  57. // CHECK:STDOUT: .Incomplete = %Incomplete.decl
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: %Core.import = import Core
  60. // CHECK:STDOUT: %Empty.decl: type = class_decl @Empty [template = constants.%Empty] {} {}
  61. // CHECK:STDOUT: %Incomplete.decl: type = class_decl @Incomplete [template = constants.%Incomplete] {} {}
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: class @Empty {
  65. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type]
  66. // CHECK:STDOUT: complete_type_witness = %complete_type
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: !members:
  69. // CHECK:STDOUT: .Self = constants.%Empty
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: class @Incomplete;
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: --- fail_b.carbon
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: constants {
  77. // CHECK:STDOUT: %Empty: type = class_type @Empty [template]
  78. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
  79. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template]
  80. // CHECK:STDOUT: %.a95: type = class_type @.1 [template]
  81. // CHECK:STDOUT: %Incomplete: type = class_type @Incomplete [template]
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: imports {
  85. // CHECK:STDOUT: %Main.Empty: type = import_ref Main//a, Empty, loaded [template = constants.%Empty]
  86. // CHECK:STDOUT: %Main.Incomplete: type = import_ref Main//a, Incomplete, loaded [template = constants.%Incomplete]
  87. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  88. // CHECK:STDOUT: import Core//prelude
  89. // CHECK:STDOUT: import Core//prelude/...
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT: %Main.import_ref.8f2: <witness> = import_ref Main//a, loc5_1, loaded [template = constants.%complete_type]
  92. // CHECK:STDOUT: %Main.import_ref.fd7 = import_ref Main//a, inst16 [no loc], unloaded
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: file {
  96. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  97. // CHECK:STDOUT: .Empty = imports.%Main.Empty
  98. // CHECK:STDOUT: .Incomplete = imports.%Main.Incomplete
  99. // CHECK:STDOUT: .Core = imports.%Core
  100. // CHECK:STDOUT: .a = %a
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT: %Core.import = import Core
  103. // CHECK:STDOUT: %default.import = import <none>
  104. // CHECK:STDOUT: %.decl: type = class_decl @.1 [template = constants.%.a95] {} {}
  105. // CHECK:STDOUT: name_binding_decl {
  106. // CHECK:STDOUT: %a.patt: <error> = binding_pattern a
  107. // CHECK:STDOUT: %.loc25: <error> = var_pattern %a.patt
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT: %a.var: ref <error> = var a
  110. // CHECK:STDOUT: %Incomplete.ref: type = name_ref Incomplete, imports.%Main.Incomplete [template = constants.%Incomplete]
  111. // CHECK:STDOUT: %a: <error> = bind_name a, <error>
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT:
  114. // CHECK:STDOUT: class @Empty [from "a.carbon"] {
  115. // CHECK:STDOUT: complete_type_witness = imports.%Main.import_ref.8f2
  116. // CHECK:STDOUT:
  117. // CHECK:STDOUT: !members:
  118. // CHECK:STDOUT: .Self = imports.%Main.import_ref.fd7
  119. // CHECK:STDOUT: }
  120. // CHECK:STDOUT:
  121. // CHECK:STDOUT: class @.1 {
  122. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type]
  123. // CHECK:STDOUT: complete_type_witness = %complete_type
  124. // CHECK:STDOUT:
  125. // CHECK:STDOUT: !members:
  126. // CHECK:STDOUT: .Self = constants.%.a95
  127. // CHECK:STDOUT: }
  128. // CHECK:STDOUT:
  129. // CHECK:STDOUT: class @Incomplete [from "a.carbon"];
  130. // CHECK:STDOUT: