fail_impl_as_scope.carbon 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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/impl/fail_impl_as_scope.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/fail_impl_as_scope.carbon
  10. // --- fail_global.carbon
  11. library "[[@TEST_NAME]]";
  12. interface Simple {
  13. fn F();
  14. }
  15. // CHECK:STDERR: fail_global.carbon:[[@LINE+4]]:6: error: `impl as` can only be used in a class [ImplAsOutsideClass]
  16. // CHECK:STDERR: impl as Simple {
  17. // CHECK:STDERR: ^~
  18. // CHECK:STDERR:
  19. impl as Simple {
  20. fn F() {}
  21. }
  22. // --- fail_function.carbon
  23. library "[[@TEST_NAME]]";
  24. interface Simple {
  25. fn F();
  26. }
  27. fn Function() {
  28. // CHECK:STDERR: fail_function.carbon:[[@LINE+4]]:8: error: `impl as` can only be used in a class [ImplAsOutsideClass]
  29. // CHECK:STDERR: impl as Simple {
  30. // CHECK:STDERR: ^~
  31. // CHECK:STDERR:
  32. impl as Simple {
  33. fn F() {}
  34. }
  35. }
  36. // CHECK:STDOUT: --- fail_global.carbon
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: constants {
  39. // CHECK:STDOUT: %Simple.type: type = facet_type <@Simple> [concrete]
  40. // CHECK:STDOUT: %Self: %Simple.type = bind_symbolic_name Self, 0 [symbolic]
  41. // CHECK:STDOUT: %F.type.e2e: type = fn_type @F.1 [concrete]
  42. // CHECK:STDOUT: %F.df8: %F.type.e2e = struct_value () [concrete]
  43. // CHECK:STDOUT: %Simple.assoc_type: type = assoc_entity_type %Simple.type [concrete]
  44. // CHECK:STDOUT: %assoc0: %Simple.assoc_type = assoc_entity element0, @Simple.%F.decl [concrete]
  45. // CHECK:STDOUT: %F.type.fe5: type = fn_type @F.2 [concrete]
  46. // CHECK:STDOUT: %F.32d: %F.type.fe5 = struct_value () [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: .Simple = %Simple.decl
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT: %Core.import = import Core
  62. // CHECK:STDOUT: %Simple.decl: type = interface_decl @Simple [concrete = constants.%Simple.type] {} {}
  63. // CHECK:STDOUT: impl_decl @impl [concrete] {} {
  64. // CHECK:STDOUT: %Self.ref: type = name_ref Self, <error> [concrete = <error>]
  65. // CHECK:STDOUT: %Simple.ref: type = name_ref Simple, file.%Simple.decl [concrete = constants.%Simple.type]
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: interface @Simple {
  70. // CHECK:STDOUT: %Self: %Simple.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
  71. // CHECK:STDOUT: %F.decl: %F.type.e2e = fn_decl @F.1 [concrete = constants.%F.df8] {} {}
  72. // CHECK:STDOUT: %assoc0: %Simple.assoc_type = assoc_entity element0, %F.decl [concrete = constants.%assoc0]
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: !members:
  75. // CHECK:STDOUT: .Self = %Self
  76. // CHECK:STDOUT: .F = %assoc0
  77. // CHECK:STDOUT: witness = (%F.decl)
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: impl @impl: %Self.ref as %Simple.ref {
  81. // CHECK:STDOUT: %F.decl: %F.type.fe5 = fn_decl @F.2 [concrete = constants.%F.32d] {} {}
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: !members:
  84. // CHECK:STDOUT: .F = %F.decl
  85. // CHECK:STDOUT: witness = <error>
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT:
  88. // CHECK:STDOUT: generic fn @F.1(@Simple.%Self: %Simple.type) {
  89. // CHECK:STDOUT: fn();
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: fn @F.2() {
  93. // CHECK:STDOUT: !entry:
  94. // CHECK:STDOUT: return
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: specific @F.1(constants.%Self) {}
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: --- fail_function.carbon
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: constants {
  102. // CHECK:STDOUT: %Simple.type: type = facet_type <@Simple> [concrete]
  103. // CHECK:STDOUT: %Self: %Simple.type = bind_symbolic_name Self, 0 [symbolic]
  104. // CHECK:STDOUT: %F.type.e2e: type = fn_type @F.1 [concrete]
  105. // CHECK:STDOUT: %F.df8: %F.type.e2e = struct_value () [concrete]
  106. // CHECK:STDOUT: %Simple.assoc_type: type = assoc_entity_type %Simple.type [concrete]
  107. // CHECK:STDOUT: %assoc0: %Simple.assoc_type = assoc_entity element0, @Simple.%F.decl [concrete]
  108. // CHECK:STDOUT: %Function.type: type = fn_type @Function [concrete]
  109. // CHECK:STDOUT: %Function: %Function.type = struct_value () [concrete]
  110. // CHECK:STDOUT: %F.type.bc7: type = fn_type @F.2 [concrete]
  111. // CHECK:STDOUT: %F.0a2: %F.type.bc7 = struct_value () [concrete]
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT:
  114. // CHECK:STDOUT: imports {
  115. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  116. // CHECK:STDOUT: import Core//prelude
  117. // CHECK:STDOUT: import Core//prelude/...
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT: }
  120. // CHECK:STDOUT:
  121. // CHECK:STDOUT: file {
  122. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  123. // CHECK:STDOUT: .Core = imports.%Core
  124. // CHECK:STDOUT: .Simple = %Simple.decl
  125. // CHECK:STDOUT: .Function = %Function.decl
  126. // CHECK:STDOUT: }
  127. // CHECK:STDOUT: %Core.import = import Core
  128. // CHECK:STDOUT: %Simple.decl: type = interface_decl @Simple [concrete = constants.%Simple.type] {} {}
  129. // CHECK:STDOUT: %Function.decl: %Function.type = fn_decl @Function [concrete = constants.%Function] {} {}
  130. // CHECK:STDOUT: }
  131. // CHECK:STDOUT:
  132. // CHECK:STDOUT: interface @Simple {
  133. // CHECK:STDOUT: %Self: %Simple.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
  134. // CHECK:STDOUT: %F.decl: %F.type.e2e = fn_decl @F.1 [concrete = constants.%F.df8] {} {}
  135. // CHECK:STDOUT: %assoc0: %Simple.assoc_type = assoc_entity element0, %F.decl [concrete = constants.%assoc0]
  136. // CHECK:STDOUT:
  137. // CHECK:STDOUT: !members:
  138. // CHECK:STDOUT: .Self = %Self
  139. // CHECK:STDOUT: .F = %assoc0
  140. // CHECK:STDOUT: witness = (%F.decl)
  141. // CHECK:STDOUT: }
  142. // CHECK:STDOUT:
  143. // CHECK:STDOUT: impl @impl: %Self.ref as %Simple.ref {
  144. // CHECK:STDOUT: %F.decl: %F.type.bc7 = fn_decl @F.2 [concrete = constants.%F.0a2] {} {}
  145. // CHECK:STDOUT:
  146. // CHECK:STDOUT: !members:
  147. // CHECK:STDOUT: .F = %F.decl
  148. // CHECK:STDOUT: witness = <error>
  149. // CHECK:STDOUT: }
  150. // CHECK:STDOUT:
  151. // CHECK:STDOUT: generic fn @F.1(@Simple.%Self: %Simple.type) {
  152. // CHECK:STDOUT: fn();
  153. // CHECK:STDOUT: }
  154. // CHECK:STDOUT:
  155. // CHECK:STDOUT: fn @Function() {
  156. // CHECK:STDOUT: !entry:
  157. // CHECK:STDOUT: impl_decl @impl [concrete] {} {
  158. // CHECK:STDOUT: %Self.ref: type = name_ref Self, <error> [concrete = <error>]
  159. // CHECK:STDOUT: %Simple.ref: type = name_ref Simple, file.%Simple.decl [concrete = constants.%Simple.type]
  160. // CHECK:STDOUT: }
  161. // CHECK:STDOUT: return
  162. // CHECK:STDOUT: }
  163. // CHECK:STDOUT:
  164. // CHECK:STDOUT: fn @F.2() {
  165. // CHECK:STDOUT: !entry:
  166. // CHECK:STDOUT: return
  167. // CHECK:STDOUT: }
  168. // CHECK:STDOUT:
  169. // CHECK:STDOUT: specific @F.1(constants.%Self) {}
  170. // CHECK:STDOUT: