fail_not_top_level.carbon 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/convert.carbon
  6. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  7. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  8. //
  9. // AUTOUPDATE
  10. // TIP: To test this file alone, run:
  11. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/namespace/fail_not_top_level.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/namespace/fail_not_top_level.carbon
  14. fn F() {
  15. // CHECK:STDERR: fail_not_top_level.carbon:[[@LINE+4]]:3: error: `namespace` declaration not at top level [NamespaceDeclNotAtTopLevel]
  16. // CHECK:STDERR: namespace N;
  17. // CHECK:STDERR: ^~~~~~~~~~~~
  18. // CHECK:STDERR:
  19. namespace N;
  20. fn N.F() {}
  21. }
  22. class C {
  23. // CHECK:STDERR: fail_not_top_level.carbon:[[@LINE+4]]:3: error: `namespace` declaration not at top level [NamespaceDeclNotAtTopLevel]
  24. // CHECK:STDERR: namespace N;
  25. // CHECK:STDERR: ^~~~~~~~~~~~
  26. // CHECK:STDERR:
  27. namespace N;
  28. fn N.F() {}
  29. }
  30. interface I {
  31. // CHECK:STDERR: fail_not_top_level.carbon:[[@LINE+4]]:3: error: `namespace` declaration not at top level [NamespaceDeclNotAtTopLevel]
  32. // CHECK:STDERR: namespace N;
  33. // CHECK:STDERR: ^~~~~~~~~~~~
  34. // CHECK:STDERR:
  35. namespace N;
  36. fn N.I() {}
  37. }
  38. // CHECK:STDOUT: --- fail_not_top_level.carbon
  39. // CHECK:STDOUT:
  40. // CHECK:STDOUT: constants {
  41. // CHECK:STDOUT: %F.type.b25: type = fn_type @F.loc15 [concrete]
  42. // CHECK:STDOUT: %F.c41: %F.type.b25 = struct_value () [concrete]
  43. // CHECK:STDOUT: %F.type.bee: type = fn_type @F.loc21 [concrete]
  44. // CHECK:STDOUT: %F.39e: %F.type.bee = struct_value () [concrete]
  45. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  46. // CHECK:STDOUT: %F.type.1cc: type = fn_type @F.loc30 [concrete]
  47. // CHECK:STDOUT: %F.f49: %F.type.1cc = struct_value () [concrete]
  48. // CHECK:STDOUT: %Destroy.type: type = facet_type <@Destroy> [concrete]
  49. // CHECK:STDOUT: %pattern_type.f6d: type = pattern_type auto [concrete]
  50. // CHECK:STDOUT: %Destroy.impl_witness: <witness> = impl_witness @C.%Destroy.impl_witness_table [concrete]
  51. // CHECK:STDOUT: %ptr.019: type = ptr_type %C [concrete]
  52. // CHECK:STDOUT: %pattern_type.44a: type = pattern_type %ptr.019 [concrete]
  53. // CHECK:STDOUT: %C.as.Destroy.impl.Op.type: type = fn_type @C.as.Destroy.impl.Op [concrete]
  54. // CHECK:STDOUT: %C.as.Destroy.impl.Op: %C.as.Destroy.impl.Op.type = struct_value () [concrete]
  55. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  56. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  57. // CHECK:STDOUT: %I.type.733: type = facet_type <@I.loc33> [concrete]
  58. // CHECK:STDOUT: %Self.826: %I.type.733 = bind_symbolic_name Self, 0 [symbolic]
  59. // CHECK:STDOUT: %I.type.d37: type = fn_type @I.loc39 [concrete]
  60. // CHECK:STDOUT: %I: %I.type.d37 = struct_value () [concrete]
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: imports {
  64. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  65. // CHECK:STDOUT: .Destroy = %Core.Destroy
  66. // CHECK:STDOUT: import Core//prelude
  67. // CHECK:STDOUT: import Core//prelude/...
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT: %Core.Destroy: type = import_ref Core//prelude/parts/destroy, Destroy, loaded [concrete = constants.%Destroy.type]
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: file {
  73. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  74. // CHECK:STDOUT: .Core = imports.%Core
  75. // CHECK:STDOUT: .F = %F.decl
  76. // CHECK:STDOUT: .C = %C.decl
  77. // CHECK:STDOUT: .I = %I.decl
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT: %Core.import = import Core
  80. // CHECK:STDOUT: %F.decl: %F.type.b25 = fn_decl @F.loc15 [concrete = constants.%F.c41] {} {}
  81. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  82. // CHECK:STDOUT: %I.decl: type = interface_decl @I.loc33 [concrete = constants.%I.type.733] {} {}
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: interface @I.loc33 {
  86. // CHECK:STDOUT: %Self: %I.type.733 = bind_symbolic_name Self, 0 [symbolic = constants.%Self.826]
  87. // CHECK:STDOUT: %N: <namespace> = namespace [concrete] {
  88. // CHECK:STDOUT: .I = %I.decl
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT: %I.decl: %I.type.d37 = fn_decl @I.loc39 [concrete = constants.%I] {} {}
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: !members:
  93. // CHECK:STDOUT: .Self = %Self
  94. // CHECK:STDOUT: .N = %N
  95. // CHECK:STDOUT: witness = ()
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: impl @C.as.Destroy.impl: @C.%Self.ref as constants.%Destroy.type {
  99. // CHECK:STDOUT: %C.as.Destroy.impl.Op.decl: %C.as.Destroy.impl.Op.type = fn_decl @C.as.Destroy.impl.Op [concrete = constants.%C.as.Destroy.impl.Op] {
  100. // CHECK:STDOUT: %self.patt: %pattern_type.44a = binding_pattern self [concrete]
  101. // CHECK:STDOUT: %self.param_patt: %pattern_type.44a = value_param_pattern %self.patt, call_param0 [concrete]
  102. // CHECK:STDOUT: %.loc24: %pattern_type.f6d = addr_pattern %self.param_patt [concrete]
  103. // CHECK:STDOUT: } {
  104. // CHECK:STDOUT: %self.param: %ptr.019 = value_param call_param0
  105. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [concrete = constants.%C]
  106. // CHECK:STDOUT: %self: %ptr.019 = bind_name self, %self.param
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: !members:
  110. // CHECK:STDOUT: .Op = %C.as.Destroy.impl.Op.decl
  111. // CHECK:STDOUT: witness = @C.%Destroy.impl_witness
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT:
  114. // CHECK:STDOUT: class @C {
  115. // CHECK:STDOUT: %N: <namespace> = namespace [concrete] {
  116. // CHECK:STDOUT: .F = %F.decl
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT: %F.decl: %F.type.1cc = fn_decl @F.loc30 [concrete = constants.%F.f49] {} {}
  119. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [concrete = constants.%C]
  120. // CHECK:STDOUT: impl_decl @C.as.Destroy.impl [concrete] {} {}
  121. // CHECK:STDOUT: %Destroy.impl_witness_table = impl_witness_table (@C.as.Destroy.impl.%C.as.Destroy.impl.Op.decl), @C.as.Destroy.impl [concrete]
  122. // CHECK:STDOUT: %Destroy.impl_witness: <witness> = impl_witness %Destroy.impl_witness_table [concrete = constants.%Destroy.impl_witness]
  123. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type]
  124. // CHECK:STDOUT: complete_type_witness = %complete_type
  125. // CHECK:STDOUT:
  126. // CHECK:STDOUT: !members:
  127. // CHECK:STDOUT: .Self = constants.%C
  128. // CHECK:STDOUT: .N = %N
  129. // CHECK:STDOUT: }
  130. // CHECK:STDOUT:
  131. // CHECK:STDOUT: fn @F.loc15() {
  132. // CHECK:STDOUT: !entry:
  133. // CHECK:STDOUT: %N: <namespace> = namespace [concrete] {
  134. // CHECK:STDOUT: .F = %F.decl
  135. // CHECK:STDOUT: }
  136. // CHECK:STDOUT: %F.decl: %F.type.bee = fn_decl @F.loc21 [concrete = constants.%F.39e] {} {}
  137. // CHECK:STDOUT: return
  138. // CHECK:STDOUT: }
  139. // CHECK:STDOUT:
  140. // CHECK:STDOUT: fn @F.loc21() {
  141. // CHECK:STDOUT: !entry:
  142. // CHECK:STDOUT: return
  143. // CHECK:STDOUT: }
  144. // CHECK:STDOUT:
  145. // CHECK:STDOUT: fn @F.loc30() {
  146. // CHECK:STDOUT: !entry:
  147. // CHECK:STDOUT: return
  148. // CHECK:STDOUT: }
  149. // CHECK:STDOUT:
  150. // CHECK:STDOUT: fn @C.as.Destroy.impl.Op(%self.param: %ptr.019) = "no_op";
  151. // CHECK:STDOUT:
  152. // CHECK:STDOUT: generic fn @I.loc39(@I.loc33.%Self: %I.type.733) {
  153. // CHECK:STDOUT: !definition:
  154. // CHECK:STDOUT:
  155. // CHECK:STDOUT: fn() {
  156. // CHECK:STDOUT: !entry:
  157. // CHECK:STDOUT: return
  158. // CHECK:STDOUT: }
  159. // CHECK:STDOUT: }
  160. // CHECK:STDOUT:
  161. // CHECK:STDOUT: specific @I.loc39(constants.%Self.826) {}
  162. // CHECK:STDOUT: