fail_import_misuses.carbon 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 "a";
  12. class Empty {
  13. }
  14. class Incomplete;
  15. // --- fail_b.carbon
  16. library "b";
  17. import library "a";
  18. // CHECK:STDERR: fail_b.carbon:[[@LINE+10]]:1: ERROR: Only one library can declare `class Empty` without `extern`.
  19. // CHECK:STDERR: class Empty {
  20. // CHECK:STDERR: ^~~~~~~~~~~~~
  21. // CHECK:STDERR: fail_b.carbon:[[@LINE-5]]:1: In import.
  22. // CHECK:STDERR: import library "a";
  23. // CHECK:STDERR: ^~~~~~
  24. // CHECK:STDERR: a.carbon:4:1: Previously declared here.
  25. // CHECK:STDERR: class Empty {
  26. // CHECK:STDERR: ^~~~~~~~~~~~~
  27. // CHECK:STDERR:
  28. class Empty {
  29. }
  30. // CHECK:STDERR: fail_b.carbon:[[@LINE+9]]:8: ERROR: Variable has incomplete type `Incomplete`.
  31. // CHECK:STDERR: var a: Incomplete;
  32. // CHECK:STDERR: ^~~~~~~~~~
  33. // CHECK:STDERR: fail_b.carbon:[[@LINE-18]]:1: In import.
  34. // CHECK:STDERR: import library "a";
  35. // CHECK:STDERR: ^~~~~~
  36. // CHECK:STDERR: a.carbon:7:1: Class was forward declared here.
  37. // CHECK:STDERR: class Incomplete;
  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 [template]
  44. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  45. // CHECK:STDOUT: %Incomplete: type = class_type @Incomplete [template]
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT:
  48. // CHECK:STDOUT: file {
  49. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  50. // CHECK:STDOUT: .Core = %Core
  51. // CHECK:STDOUT: .Empty = %Empty.decl
  52. // CHECK:STDOUT: .Incomplete = %Incomplete.decl
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: %Core.import = import Core
  55. // CHECK:STDOUT: %Core: <namespace> = namespace %Core.import, [template] {
  56. // CHECK:STDOUT: import Core//prelude
  57. // CHECK:STDOUT: import Core//prelude/operators
  58. // CHECK:STDOUT: import Core//prelude/types
  59. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  60. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  61. // CHECK:STDOUT: import Core//prelude/operators/comparison
  62. // CHECK:STDOUT: import Core//prelude/types/bool
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT: %Empty.decl: type = class_decl @Empty [template = constants.%Empty] {}
  65. // CHECK:STDOUT: %Incomplete.decl: type = class_decl @Incomplete [template = constants.%Incomplete] {}
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: class @Empty {
  69. // CHECK:STDOUT: !members:
  70. // CHECK:STDOUT: .Self = constants.%Empty
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: class @Incomplete;
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: --- fail_b.carbon
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: constants {
  78. // CHECK:STDOUT: %Empty: type = class_type @Empty [template]
  79. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  80. // CHECK:STDOUT: %.2: 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: %import_ref.1: type = import_ref Main//a, inst+3, loaded [template = constants.%Empty]
  86. // CHECK:STDOUT: %import_ref.2: type = import_ref Main//a, inst+6, loaded [template = constants.%Incomplete]
  87. // CHECK:STDOUT: %import_ref.3 = import_ref Main//a, inst+4, unloaded
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: file {
  91. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  92. // CHECK:STDOUT: .Empty = imports.%import_ref.1
  93. // CHECK:STDOUT: .Incomplete = imports.%import_ref.2
  94. // CHECK:STDOUT: .Core = %Core
  95. // CHECK:STDOUT: .a = %a
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT: %Core.import = import Core
  98. // CHECK:STDOUT: %default.import = import <invalid>
  99. // CHECK:STDOUT: %Core: <namespace> = namespace %Core.import, [template] {
  100. // CHECK:STDOUT: import Core//prelude
  101. // CHECK:STDOUT: import Core//prelude/operators
  102. // CHECK:STDOUT: import Core//prelude/types
  103. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  104. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  105. // CHECK:STDOUT: import Core//prelude/operators/comparison
  106. // CHECK:STDOUT: import Core//prelude/types/bool
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT: %.decl: type = class_decl @.1 [template = constants.%.2] {}
  109. // CHECK:STDOUT: %Incomplete.ref: type = name_ref Incomplete, imports.%import_ref.2 [template = constants.%Incomplete]
  110. // CHECK:STDOUT: %a.var: ref <error> = var a
  111. // CHECK:STDOUT: %a: ref <error> = bind_name a, %a.var
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT:
  114. // CHECK:STDOUT: class @Empty {
  115. // CHECK:STDOUT: !members:
  116. // CHECK:STDOUT: .Self = imports.%import_ref.3
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: class @.1 {
  120. // CHECK:STDOUT: !members:
  121. // CHECK:STDOUT: .Self = constants.%.2
  122. // CHECK:STDOUT: }
  123. // CHECK:STDOUT:
  124. // CHECK:STDOUT: class @Incomplete;
  125. // CHECK:STDOUT: