fail_impl_bad_interface.carbon 11 KB

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