fail_import_misuses.carbon 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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: <namespace> = namespace [template] {}
  55. // CHECK:STDOUT: %Empty.decl: type = class_decl @Empty [template = constants.%Empty] {}
  56. // CHECK:STDOUT: %Incomplete.decl: type = class_decl @Incomplete [template = constants.%Incomplete] {}
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: class @Empty {
  60. // CHECK:STDOUT: !members:
  61. // CHECK:STDOUT: .Self = constants.%Empty
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: class @Incomplete;
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: --- fail_b.carbon
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: constants {
  69. // CHECK:STDOUT: %Empty: type = class_type @Empty [template]
  70. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  71. // CHECK:STDOUT: %.2: type = class_type @.1 [template]
  72. // CHECK:STDOUT: %Incomplete: type = class_type @Incomplete [template]
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: file {
  76. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  77. // CHECK:STDOUT: .Empty = %import_ref.1
  78. // CHECK:STDOUT: .Incomplete = %import_ref.2
  79. // CHECK:STDOUT: .Core = %Core
  80. // CHECK:STDOUT: .a = %a
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT: %import_ref.1: type = import_ref ir1, inst+2, loaded [template = constants.%Empty]
  83. // CHECK:STDOUT: %import_ref.2: type = import_ref ir1, inst+5, loaded [template = constants.%Incomplete]
  84. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  85. // CHECK:STDOUT: %import_ref.3 = import_ref ir1, inst+3, unloaded
  86. // CHECK:STDOUT: %.decl: type = class_decl @.1 [template = constants.%.2] {}
  87. // CHECK:STDOUT: %Incomplete.ref: type = name_ref Incomplete, %import_ref.2 [template = constants.%Incomplete]
  88. // CHECK:STDOUT: %a.var: ref <error> = var a
  89. // CHECK:STDOUT: %a: ref <error> = bind_name a, %a.var
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: class @Empty {
  93. // CHECK:STDOUT: !members:
  94. // CHECK:STDOUT: .Self = file.%import_ref.3
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: class @.1 {
  98. // CHECK:STDOUT: !members:
  99. // CHECK:STDOUT: .Self = constants.%.2
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT:
  102. // CHECK:STDOUT: class @Incomplete;
  103. // CHECK:STDOUT: