fail_impl_bad_interface.carbon 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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_bad_interface.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_bad_interface.carbon
  10. // --- fail_impl_as_false.carbon
  11. library "[[@TEST_NAME]]";
  12. // CHECK:STDERR: fail_impl_as_false.carbon:[[@LINE+7]]:13: error: cannot implicitly convert from `bool` to `type` [ImplicitAsConversionFailure]
  13. // CHECK:STDERR: impl i32 as false {}
  14. // CHECK:STDERR: ^~~~~
  15. // CHECK:STDERR: fail_impl_as_false.carbon:[[@LINE+4]]:13: note: type `bool` does not implement interface `ImplicitAs(type)` [MissingImplInMemberAccessNote]
  16. // CHECK:STDERR: impl i32 as false {}
  17. // CHECK:STDERR: ^~~~~
  18. // CHECK:STDERR:
  19. impl i32 as false {}
  20. // --- fail_impl_as_type.carbon
  21. library "[[@TEST_NAME]]";
  22. // CHECK:STDERR: fail_impl_as_type.carbon:[[@LINE+4]]:1: error: impl as non-facet-type [ImplAsNonFacetType]
  23. // CHECK:STDERR: impl bool as type {}
  24. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~
  25. // CHECK:STDERR:
  26. impl bool as type {}
  27. // --- fail_impl_as_type_where.carbon
  28. library "[[@TEST_NAME]]";
  29. // Note: This code is not expected to pass checking, even once the TODO is
  30. // addressed.
  31. // CHECK:STDERR: fail_impl_as_type_where.carbon:[[@LINE+3]]:1: error: semantics TODO: `impl as not 1 interface` [SemanticsTodo]
  32. // CHECK:STDERR: impl f64 as type where .Self impls type {}
  33. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  34. impl f64 as type where .Self impls type {}
  35. // CHECK:STDOUT: --- fail_impl_as_false.carbon
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: constants {
  38. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  39. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [template]
  40. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  41. // CHECK:STDOUT: %.1: bool = bool_literal false [template]
  42. // CHECK:STDOUT: %ImplicitAs.type.1: type = generic_interface_type @ImplicitAs [template]
  43. // CHECK:STDOUT: %ImplicitAs: %ImplicitAs.type.1 = struct_value () [template]
  44. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest, 0 [symbolic]
  45. // CHECK:STDOUT: %ImplicitAs.type.2: type = facet_type <@ImplicitAs, @ImplicitAs(%Dest)> [symbolic]
  46. // CHECK:STDOUT: %Self.1: @ImplicitAs.%ImplicitAs.type (%ImplicitAs.type.2) = bind_symbolic_name Self, 1 [symbolic]
  47. // CHECK:STDOUT: %Dest.patt: type = symbolic_binding_pattern Dest, 0 [symbolic]
  48. // CHECK:STDOUT: %Self.2: %ImplicitAs.type.2 = bind_symbolic_name Self, 1 [symbolic]
  49. // CHECK:STDOUT: %Convert.type.1: type = fn_type @Convert, @ImplicitAs(%Dest) [symbolic]
  50. // CHECK:STDOUT: %Convert.1: %Convert.type.1 = struct_value () [symbolic]
  51. // CHECK:STDOUT: %.2: type = assoc_entity_type %ImplicitAs.type.2, %Convert.type.1 [symbolic]
  52. // CHECK:STDOUT: %.3: %.2 = assoc_entity element0, imports.%import_ref.6 [symbolic]
  53. // CHECK:STDOUT: %ImplicitAs.type.3: type = facet_type <@ImplicitAs, @ImplicitAs(type)> [template]
  54. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert, @ImplicitAs(type) [template]
  55. // CHECK:STDOUT: %Convert.2: %Convert.type.2 = struct_value () [template]
  56. // CHECK:STDOUT: %.4: type = assoc_entity_type %ImplicitAs.type.3, %Convert.type.2 [template]
  57. // CHECK:STDOUT: %.5: %.4 = assoc_entity element0, imports.%import_ref.6 [template]
  58. // CHECK:STDOUT: %.6: %.2 = assoc_entity element0, imports.%import_ref.7 [symbolic]
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT:
  61. // CHECK:STDOUT: imports {
  62. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  63. // CHECK:STDOUT: .Int32 = %import_ref.1
  64. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  65. // CHECK:STDOUT: import Core//prelude
  66. // CHECK:STDOUT: import Core//prelude/...
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref Core//prelude/types, inst+15, loaded [template = constants.%Int32]
  69. // CHECK:STDOUT: %import_ref.2: %ImplicitAs.type.1 = import_ref Core//prelude/operators/as, inst+48, loaded [template = constants.%ImplicitAs]
  70. // CHECK:STDOUT: %import_ref.3 = import_ref Core//prelude/operators/as, inst+54, unloaded
  71. // CHECK:STDOUT: %import_ref.4: @ImplicitAs.%.1 (%.2) = import_ref Core//prelude/operators/as, inst+76, loaded [symbolic = @ImplicitAs.%.2 (constants.%.6)]
  72. // CHECK:STDOUT: %import_ref.5 = import_ref Core//prelude/operators/as, inst+69, unloaded
  73. // CHECK:STDOUT: %import_ref.6 = import_ref Core//prelude/operators/as, inst+69, unloaded
  74. // CHECK:STDOUT: %import_ref.7 = import_ref Core//prelude/operators/as, inst+69, unloaded
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: file {
  78. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  79. // CHECK:STDOUT: .Core = imports.%Core
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT: %Core.import = import Core
  82. // CHECK:STDOUT: %.loc11: type = converted @impl.%.loc11_13, <error> [template = <error>]
  83. // CHECK:STDOUT: impl_decl @impl [template] {} {
  84. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  85. // CHECK:STDOUT: %.loc11_6.1: type = value_of_initializer %int.make_type_32 [template = i32]
  86. // CHECK:STDOUT: %.loc11_6.2: type = converted %int.make_type_32, %.loc11_6.1 [template = i32]
  87. // CHECK:STDOUT: %.loc11_13: bool = bool_literal false [template = constants.%.1]
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: generic interface @ImplicitAs(constants.%Dest: type) {
  92. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest, 0 [symbolic = %Dest (constants.%Dest)]
  93. // CHECK:STDOUT: %Dest.patt: type = symbolic_binding_pattern Dest, 0 [symbolic = %Dest.patt (constants.%Dest.patt)]
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: !definition:
  96. // CHECK:STDOUT: %ImplicitAs.type: type = facet_type <@ImplicitAs, @ImplicitAs(%Dest)> [symbolic = %ImplicitAs.type (constants.%ImplicitAs.type.2)]
  97. // CHECK:STDOUT: %Self: %ImplicitAs.type.2 = bind_symbolic_name Self, 1 [symbolic = %Self (constants.%Self.2)]
  98. // CHECK:STDOUT: %Convert.type: type = fn_type @Convert, @ImplicitAs(%Dest) [symbolic = %Convert.type (constants.%Convert.type.1)]
  99. // CHECK:STDOUT: %Convert: @ImplicitAs.%Convert.type (%Convert.type.1) = struct_value () [symbolic = %Convert (constants.%Convert.1)]
  100. // CHECK:STDOUT: %.1: type = assoc_entity_type @ImplicitAs.%ImplicitAs.type (%ImplicitAs.type.2), @ImplicitAs.%Convert.type (%Convert.type.1) [symbolic = %.1 (constants.%.2)]
  101. // CHECK:STDOUT: %.2: @ImplicitAs.%.1 (%.2) = assoc_entity element0, imports.%import_ref.6 [symbolic = %.2 (constants.%.3)]
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: interface {
  104. // CHECK:STDOUT: !members:
  105. // CHECK:STDOUT: .Self = imports.%import_ref.3
  106. // CHECK:STDOUT: .Convert = imports.%import_ref.4
  107. // CHECK:STDOUT: witness = (imports.%import_ref.5)
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT:
  111. // CHECK:STDOUT: impl @impl: %.loc11_6.2 as <error> {
  112. // CHECK:STDOUT: !members:
  113. // CHECK:STDOUT: witness = <error>
  114. // CHECK:STDOUT: }
  115. // CHECK:STDOUT:
  116. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  117. // CHECK:STDOUT:
  118. // CHECK:STDOUT: generic fn @Convert(constants.%Dest: type, constants.%Self.1: @ImplicitAs.%ImplicitAs.type (%ImplicitAs.type.2)) {
  119. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest, 0 [symbolic = %Dest (constants.%Dest)]
  120. // CHECK:STDOUT: %ImplicitAs.type: type = facet_type <@ImplicitAs, @ImplicitAs(%Dest)> [symbolic = %ImplicitAs.type (constants.%ImplicitAs.type.2)]
  121. // CHECK:STDOUT: %Self: %ImplicitAs.type.2 = bind_symbolic_name Self, 1 [symbolic = %Self (constants.%Self.2)]
  122. // CHECK:STDOUT:
  123. // CHECK:STDOUT: fn[%self.param_patt: @Convert.%Self (%Self.2)]() -> @Convert.%Dest (%Dest);
  124. // CHECK:STDOUT: }
  125. // CHECK:STDOUT:
  126. // CHECK:STDOUT: specific @ImplicitAs(constants.%Dest) {
  127. // CHECK:STDOUT: %Dest => constants.%Dest
  128. // CHECK:STDOUT: %Dest.patt => constants.%Dest
  129. // CHECK:STDOUT: }
  130. // CHECK:STDOUT:
  131. // CHECK:STDOUT: specific @ImplicitAs(@ImplicitAs.%Dest) {
  132. // CHECK:STDOUT: %Dest => constants.%Dest
  133. // CHECK:STDOUT: %Dest.patt => constants.%Dest
  134. // CHECK:STDOUT: }
  135. // CHECK:STDOUT:
  136. // CHECK:STDOUT: specific @ImplicitAs(@Convert.%Dest) {
  137. // CHECK:STDOUT: %Dest => constants.%Dest
  138. // CHECK:STDOUT: %Dest.patt => constants.%Dest
  139. // CHECK:STDOUT: }
  140. // CHECK:STDOUT:
  141. // CHECK:STDOUT: specific @Convert(constants.%Dest, constants.%Self.1) {
  142. // CHECK:STDOUT: %Dest => constants.%Dest
  143. // CHECK:STDOUT: %ImplicitAs.type => constants.%ImplicitAs.type.2
  144. // CHECK:STDOUT: %Self => constants.%Self.1
  145. // CHECK:STDOUT: }
  146. // CHECK:STDOUT:
  147. // CHECK:STDOUT: specific @ImplicitAs(type) {
  148. // CHECK:STDOUT: %Dest => type
  149. // CHECK:STDOUT: %Dest.patt => type
  150. // CHECK:STDOUT:
  151. // CHECK:STDOUT: !definition:
  152. // CHECK:STDOUT: %ImplicitAs.type => constants.%ImplicitAs.type.3
  153. // CHECK:STDOUT: %Self => constants.%Self.2
  154. // CHECK:STDOUT: %Convert.type => constants.%Convert.type.2
  155. // CHECK:STDOUT: %Convert => constants.%Convert.2
  156. // CHECK:STDOUT: %.1 => constants.%.4
  157. // CHECK:STDOUT: %.2 => constants.%.5
  158. // CHECK:STDOUT: }
  159. // CHECK:STDOUT:
  160. // CHECK:STDOUT: --- fail_impl_as_type.carbon
  161. // CHECK:STDOUT:
  162. // CHECK:STDOUT: constants {
  163. // CHECK:STDOUT: %Bool.type: type = fn_type @Bool [template]
  164. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [template]
  165. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [template]
  166. // CHECK:STDOUT: }
  167. // CHECK:STDOUT:
  168. // CHECK:STDOUT: imports {
  169. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  170. // CHECK:STDOUT: .Bool = %import_ref
  171. // CHECK:STDOUT: import Core//prelude
  172. // CHECK:STDOUT: import Core//prelude/...
  173. // CHECK:STDOUT: }
  174. // CHECK:STDOUT: %import_ref: %Bool.type = import_ref Core//prelude/types/bool, inst+5, loaded [template = constants.%Bool]
  175. // CHECK:STDOUT: }
  176. // CHECK:STDOUT:
  177. // CHECK:STDOUT: file {
  178. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  179. // CHECK:STDOUT: .Core = imports.%Core
  180. // CHECK:STDOUT: }
  181. // CHECK:STDOUT: %Core.import = import Core
  182. // CHECK:STDOUT: impl_decl @impl [template] {} {
  183. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  184. // CHECK:STDOUT: %.loc8_6.1: type = value_of_initializer %bool.make_type [template = bool]
  185. // CHECK:STDOUT: %.loc8_6.2: type = converted %bool.make_type, %.loc8_6.1 [template = bool]
  186. // CHECK:STDOUT: }
  187. // CHECK:STDOUT: }
  188. // CHECK:STDOUT:
  189. // CHECK:STDOUT: impl @impl: %.loc8_6.2 as type {
  190. // CHECK:STDOUT: !members:
  191. // CHECK:STDOUT: witness = <error>
  192. // CHECK:STDOUT: }
  193. // CHECK:STDOUT:
  194. // CHECK:STDOUT: fn @Bool() -> type = "bool.make_type";
  195. // CHECK:STDOUT:
  196. // CHECK:STDOUT: --- fail_impl_as_type_where.carbon
  197. // CHECK:STDOUT:
  198. // CHECK:STDOUT: constants {
  199. // CHECK:STDOUT: %.1: Core.IntLiteral = int_value 64 [template]
  200. // CHECK:STDOUT: %Float.type: type = fn_type @Float [template]
  201. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [template]
  202. // CHECK:STDOUT: %Float: %Float.type = struct_value () [template]
  203. // CHECK:STDOUT: %.Self: type = bind_symbolic_name .Self, 0 [symbolic]
  204. // CHECK:STDOUT: %type_where: type = facet_type <type where TODO> [template]
  205. // CHECK:STDOUT: }
  206. // CHECK:STDOUT:
  207. // CHECK:STDOUT: imports {
  208. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  209. // CHECK:STDOUT: .Float = %import_ref
  210. // CHECK:STDOUT: import Core//prelude
  211. // CHECK:STDOUT: import Core//prelude/...
  212. // CHECK:STDOUT: }
  213. // CHECK:STDOUT: %import_ref: %Float.type = import_ref Core//prelude/types, inst+60, loaded [template = constants.%Float]
  214. // CHECK:STDOUT: }
  215. // CHECK:STDOUT:
  216. // CHECK:STDOUT: file {
  217. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  218. // CHECK:STDOUT: .Core = imports.%Core
  219. // CHECK:STDOUT: }
  220. // CHECK:STDOUT: %Core.import = import Core
  221. // CHECK:STDOUT: impl_decl @impl [template] {} {
  222. // CHECK:STDOUT: %.loc10_6.1: Core.IntLiteral = int_value 64 [template = constants.%.1]
  223. // CHECK:STDOUT: %float.make_type: init type = call constants.%Float(%.loc10_6.1) [template = f64]
  224. // CHECK:STDOUT: %.loc10_6.2: type = value_of_initializer %float.make_type [template = f64]
  225. // CHECK:STDOUT: %.loc10_6.3: type = converted %float.make_type, %.loc10_6.2 [template = f64]
  226. // CHECK:STDOUT: %.Self: type = bind_symbolic_name .Self, 0 [symbolic = constants.%.Self]
  227. // CHECK:STDOUT: %.Self.ref: type = name_ref .Self, %.Self [symbolic = constants.%.Self]
  228. // CHECK:STDOUT: %.loc10_18: type = where_expr %.Self [template = constants.%type_where] {
  229. // CHECK:STDOUT: requirement_impls %.Self.ref, type
  230. // CHECK:STDOUT: }
  231. // CHECK:STDOUT: }
  232. // CHECK:STDOUT: }
  233. // CHECK:STDOUT:
  234. // CHECK:STDOUT: impl @impl: %.loc10_6.3 as %.loc10_18 {
  235. // CHECK:STDOUT: !members:
  236. // CHECK:STDOUT: witness = <error>
  237. // CHECK:STDOUT: }
  238. // CHECK:STDOUT:
  239. // CHECK:STDOUT: fn @Float(%size.param_patt: Core.IntLiteral) -> type = "float.make_type";
  240. // CHECK:STDOUT: