fail_impl_bad_interface.carbon 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  6. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  7. //
  8. // AUTOUPDATE
  9. // TIP: To test this file alone, run:
  10. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/impl/fail_impl_bad_interface.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/fail_impl_bad_interface.carbon
  13. // --- fail_impl_as_false.carbon
  14. library "[[@TEST_NAME]]";
  15. // CHECK:STDERR: fail_impl_as_false.carbon:[[@LINE+7]]:13: error: cannot implicitly convert non-type value of type `bool` to `type` [ConversionFailureNonTypeToFacet]
  16. // CHECK:STDERR: impl i32 as false {}
  17. // CHECK:STDERR: ^~~~~
  18. // CHECK:STDERR: fail_impl_as_false.carbon:[[@LINE+4]]:13: note: type `bool` does not implement interface `Core.ImplicitAs(type)` [MissingImplInMemberAccessNote]
  19. // CHECK:STDERR: impl i32 as false {}
  20. // CHECK:STDERR: ^~~~~
  21. // CHECK:STDERR:
  22. impl i32 as false {}
  23. // --- fail_impl_as_type.carbon
  24. library "[[@TEST_NAME]]";
  25. // CHECK:STDERR: fail_impl_as_type.carbon:[[@LINE+4]]:1: error: impl as non-facet type `type` [ImplAsNonFacetType]
  26. // CHECK:STDERR: impl bool as type {}
  27. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~
  28. // CHECK:STDERR:
  29. impl bool as type {}
  30. // --- fail_impl_as_type_where.carbon
  31. library "[[@TEST_NAME]]";
  32. // CHECK:STDERR: fail_impl_as_type_where.carbon:[[@LINE+4]]:1: error: impl as 0 interfaces, expected 1 [ImplOfNotOneInterface]
  33. // CHECK:STDERR: impl f64 as type where .Self impls type {}
  34. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  35. // CHECK:STDERR:
  36. impl f64 as type where .Self impls type {}
  37. // --- fail_impl_as_type_where_impls_interface.carbon
  38. library "[[@TEST_NAME]]";
  39. interface I {}
  40. // CHECK:STDERR: fail_impl_as_type_where_impls_interface.carbon:[[@LINE+4]]:1: error: impl as 0 interfaces, expected 1 [ImplOfNotOneInterface]
  41. // CHECK:STDERR: impl {.a: bool} as type where .Self impls I {}
  42. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  43. // CHECK:STDERR:
  44. impl {.a: bool} as type where .Self impls I {}
  45. // CHECK:STDOUT: --- fail_impl_as_false.carbon
  46. // CHECK:STDOUT:
  47. // CHECK:STDOUT: constants {
  48. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  49. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  50. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  51. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  52. // CHECK:STDOUT: %false: bool = bool_literal false [concrete]
  53. // CHECK:STDOUT: %ImplicitAs.type.cc7: type = generic_interface_type @ImplicitAs [concrete]
  54. // CHECK:STDOUT: %ImplicitAs.generic: %ImplicitAs.type.cc7 = struct_value () [concrete]
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: imports {
  58. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  59. // CHECK:STDOUT: .Int = %Core.Int
  60. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  61. // CHECK:STDOUT: import Core//prelude
  62. // CHECK:STDOUT: import Core//prelude/...
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/types/int, Int, loaded [concrete = constants.%Int.generic]
  65. // CHECK:STDOUT: %Core.ImplicitAs: %ImplicitAs.type.cc7 = import_ref Core//prelude/operators/as, ImplicitAs, loaded [concrete = constants.%ImplicitAs.generic]
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: file {
  69. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  70. // CHECK:STDOUT: .Core = imports.%Core
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT: %Core.import = import Core
  73. // CHECK:STDOUT: %.loc11: type = converted @impl.%false, <error> [concrete = <error>]
  74. // CHECK:STDOUT: impl_decl @impl [concrete] {} {
  75. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  76. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  77. // CHECK:STDOUT: %false: bool = bool_literal false [concrete = constants.%false]
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: impl @impl: %i32 as <error> {
  82. // CHECK:STDOUT: !members:
  83. // CHECK:STDOUT: witness = <error>
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: --- fail_impl_as_type.carbon
  87. // CHECK:STDOUT:
  88. // CHECK:STDOUT: constants {
  89. // CHECK:STDOUT: %Bool.type: type = fn_type @Bool [concrete]
  90. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [concrete]
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: imports {
  94. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  95. // CHECK:STDOUT: .Bool = %Core.Bool
  96. // CHECK:STDOUT: import Core//prelude
  97. // CHECK:STDOUT: import Core//prelude/...
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT: %Core.Bool: %Bool.type = import_ref Core//prelude/types/bool, Bool, loaded [concrete = constants.%Bool]
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT:
  102. // CHECK:STDOUT: file {
  103. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  104. // CHECK:STDOUT: .Core = imports.%Core
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT: %Core.import = import Core
  107. // CHECK:STDOUT: impl_decl @impl [concrete] {} {
  108. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [concrete = bool]
  109. // CHECK:STDOUT: %.loc8_6.1: type = value_of_initializer %bool.make_type [concrete = bool]
  110. // CHECK:STDOUT: %.loc8_6.2: type = converted %bool.make_type, %.loc8_6.1 [concrete = bool]
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT:
  114. // CHECK:STDOUT: impl @impl: %.loc8_6.2 as type {
  115. // CHECK:STDOUT: !members:
  116. // CHECK:STDOUT: witness = <error>
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: --- fail_impl_as_type_where.carbon
  120. // CHECK:STDOUT:
  121. // CHECK:STDOUT: constants {
  122. // CHECK:STDOUT: %int_64: Core.IntLiteral = int_value 64 [concrete]
  123. // CHECK:STDOUT: %Float.type: type = fn_type @Float [concrete]
  124. // CHECK:STDOUT: %Float: %Float.type = struct_value () [concrete]
  125. // CHECK:STDOUT: %.Self: type = bind_symbolic_name .Self [symbolic_self]
  126. // CHECK:STDOUT: %type: type = facet_type <type> [concrete]
  127. // CHECK:STDOUT: }
  128. // CHECK:STDOUT:
  129. // CHECK:STDOUT: imports {
  130. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  131. // CHECK:STDOUT: .Float = %Core.Float
  132. // CHECK:STDOUT: import Core//prelude
  133. // CHECK:STDOUT: import Core//prelude/...
  134. // CHECK:STDOUT: }
  135. // CHECK:STDOUT: %Core.Float: %Float.type = import_ref Core//prelude/types, Float, loaded [concrete = constants.%Float]
  136. // CHECK:STDOUT: }
  137. // CHECK:STDOUT:
  138. // CHECK:STDOUT: file {
  139. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  140. // CHECK:STDOUT: .Core = imports.%Core
  141. // CHECK:STDOUT: }
  142. // CHECK:STDOUT: %Core.import = import Core
  143. // CHECK:STDOUT: impl_decl @impl [concrete] {} {
  144. // CHECK:STDOUT: %int_64: Core.IntLiteral = int_value 64 [concrete = constants.%int_64]
  145. // CHECK:STDOUT: %float.make_type: init type = call constants.%Float(%int_64) [concrete = f64]
  146. // CHECK:STDOUT: %.loc8_6.1: type = value_of_initializer %float.make_type [concrete = f64]
  147. // CHECK:STDOUT: %.loc8_6.2: type = converted %float.make_type, %.loc8_6.1 [concrete = f64]
  148. // CHECK:STDOUT: %.Self: type = bind_symbolic_name .Self [symbolic_self = constants.%.Self]
  149. // CHECK:STDOUT: %.Self.ref: type = name_ref .Self, %.Self [symbolic_self = constants.%.Self]
  150. // CHECK:STDOUT: %.loc8_18: type = where_expr %.Self [concrete = constants.%type] {
  151. // CHECK:STDOUT: requirement_impls %.Self.ref, type
  152. // CHECK:STDOUT: }
  153. // CHECK:STDOUT: }
  154. // CHECK:STDOUT: }
  155. // CHECK:STDOUT:
  156. // CHECK:STDOUT: impl @impl: %.loc8_6.2 as %.loc8_18 {
  157. // CHECK:STDOUT: !members:
  158. // CHECK:STDOUT: witness = <error>
  159. // CHECK:STDOUT: }
  160. // CHECK:STDOUT:
  161. // CHECK:STDOUT: --- fail_impl_as_type_where_impls_interface.carbon
  162. // CHECK:STDOUT:
  163. // CHECK:STDOUT: constants {
  164. // CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
  165. // CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic]
  166. // CHECK:STDOUT: %Bool.type: type = fn_type @Bool [concrete]
  167. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [concrete]
  168. // CHECK:STDOUT: %struct_type.a: type = struct_type {.a: bool} [concrete]
  169. // CHECK:STDOUT: %.Self: type = bind_symbolic_name .Self [symbolic_self]
  170. // CHECK:STDOUT: %type_where: type = facet_type <type where .Self impls @I> [concrete]
  171. // CHECK:STDOUT: }
  172. // CHECK:STDOUT:
  173. // CHECK:STDOUT: imports {
  174. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  175. // CHECK:STDOUT: .Bool = %Core.Bool
  176. // CHECK:STDOUT: import Core//prelude
  177. // CHECK:STDOUT: import Core//prelude/...
  178. // CHECK:STDOUT: }
  179. // CHECK:STDOUT: %Core.Bool: %Bool.type = import_ref Core//prelude/types/bool, Bool, loaded [concrete = constants.%Bool]
  180. // CHECK:STDOUT: }
  181. // CHECK:STDOUT:
  182. // CHECK:STDOUT: file {
  183. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  184. // CHECK:STDOUT: .Core = imports.%Core
  185. // CHECK:STDOUT: .I = %I.decl
  186. // CHECK:STDOUT: }
  187. // CHECK:STDOUT: %Core.import = import Core
  188. // CHECK:STDOUT: %I.decl: type = interface_decl @I [concrete = constants.%I.type] {} {}
  189. // CHECK:STDOUT: impl_decl @impl [concrete] {} {
  190. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [concrete = bool]
  191. // CHECK:STDOUT: %.loc10_11.1: type = value_of_initializer %bool.make_type [concrete = bool]
  192. // CHECK:STDOUT: %.loc10_11.2: type = converted %bool.make_type, %.loc10_11.1 [concrete = bool]
  193. // CHECK:STDOUT: %struct_type.a: type = struct_type {.a: bool} [concrete = constants.%struct_type.a]
  194. // CHECK:STDOUT: %.Self: type = bind_symbolic_name .Self [symbolic_self = constants.%.Self]
  195. // CHECK:STDOUT: %.Self.ref: type = name_ref .Self, %.Self [symbolic_self = constants.%.Self]
  196. // CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [concrete = constants.%I.type]
  197. // CHECK:STDOUT: %.loc10_25: type = where_expr %.Self [concrete = constants.%type_where] {
  198. // CHECK:STDOUT: requirement_impls %.Self.ref, %I.ref
  199. // CHECK:STDOUT: }
  200. // CHECK:STDOUT: }
  201. // CHECK:STDOUT: }
  202. // CHECK:STDOUT:
  203. // CHECK:STDOUT: interface @I {
  204. // CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
  205. // CHECK:STDOUT:
  206. // CHECK:STDOUT: !members:
  207. // CHECK:STDOUT: .Self = %Self
  208. // CHECK:STDOUT: witness = ()
  209. // CHECK:STDOUT: }
  210. // CHECK:STDOUT:
  211. // CHECK:STDOUT: impl @impl: %struct_type.a as %.loc10_25 {
  212. // CHECK:STDOUT: !members:
  213. // CHECK:STDOUT: witness = <error>
  214. // CHECK:STDOUT: }
  215. // CHECK:STDOUT: