fail_impl_bad_interface.carbon 10 KB

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