fail_assoc_const_alias.carbon 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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/convert.carbon
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interface/fail_assoc_const_alias.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interface/fail_assoc_const_alias.carbon
  12. // --- fail_alias_to_different_interface.carbon
  13. library "[[@TEST_NAME]]";
  14. interface I {
  15. let T:! type;
  16. }
  17. interface J {
  18. alias U = I.T;
  19. // CHECK:STDERR: fail_alias_to_different_interface.carbon:[[@LINE+4]]:13: error: cannot convert type `Self` that implements `J` into type implementing `I` [ConversionFailureFacetToFacet]
  20. // CHECK:STDERR: fn F() -> U;
  21. // CHECK:STDERR: ^
  22. // CHECK:STDERR:
  23. fn F() -> U;
  24. }
  25. // --- alias_to_different_interface_with_requires.carbon
  26. library "[[@TEST_NAME]]";
  27. interface I2 {
  28. let T2:! type;
  29. }
  30. interface J2;
  31. impl forall [V:! J2] V as I2 where .T2 = () {}
  32. //@dump-sem-ir-begin
  33. interface J2 {
  34. alias U2 = I2.T2;
  35. fn F2() -> U2;
  36. }
  37. //@dump-sem-ir-end
  38. // --- fail_call_method_alias.carbon
  39. library "[[@TEST_NAME]]";
  40. interface A {
  41. fn F[self: Self]() -> type;
  42. }
  43. interface B {
  44. alias F = A.F;
  45. // CHECK:STDERR: fail_call_method_alias.carbon:[[@LINE+4]]:13: error: cannot convert type `Self` that implements `B` into type implementing `A` [ConversionFailureFacetToFacet]
  46. // CHECK:STDERR: fn G() -> F();
  47. // CHECK:STDERR: ^
  48. // CHECK:STDERR:
  49. fn G() -> F();
  50. }
  51. // --- call_with_compound_member_access.carbon
  52. library "[[@TEST_NAME]]";
  53. interface C {
  54. fn F[self: Self]();
  55. // TODO: Add `default` once supported.
  56. fn G[self: Self]() {
  57. //@dump-sem-ir-begin
  58. self.F();
  59. self.(F)();
  60. //@dump-sem-ir-end
  61. }
  62. }
  63. // CHECK:STDOUT: --- alias_to_different_interface_with_requires.carbon
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: constants {
  66. // CHECK:STDOUT: %I2.type: type = facet_type <@I2> [concrete]
  67. // CHECK:STDOUT: %I2.assoc_type: type = assoc_entity_type @I2 [concrete]
  68. // CHECK:STDOUT: %assoc0.7c1: %I2.assoc_type = assoc_entity element0, @I2.WithSelf.%T2 [concrete]
  69. // CHECK:STDOUT: %J2.type: type = facet_type <@J2> [concrete]
  70. // CHECK:STDOUT: %Self.4a7: %J2.type = symbolic_binding Self, 0 [symbolic]
  71. // CHECK:STDOUT: %Self.binding.as_type: type = symbolic_binding_type Self, 0, %Self.4a7 [symbolic]
  72. // CHECK:STDOUT: %I2.lookup_impl_witness.d97: <witness> = lookup_impl_witness %Self.4a7, @I2 [symbolic]
  73. // CHECK:STDOUT: %.ef7: require_specific_def_type = require_specific_def @V.binding.as_type.as.I2.impl(%Self.4a7) [symbolic]
  74. // CHECK:STDOUT: %I2.facet.7a5: %I2.type = facet_value %Self.binding.as_type, (%I2.lookup_impl_witness.d97) [symbolic]
  75. // CHECK:STDOUT: %impl.elem0.006: type = impl_witness_access %I2.lookup_impl_witness.d97, element0 [symbolic]
  76. // CHECK:STDOUT: %.805: Core.Form = init_form %impl.elem0.006 [symbolic]
  77. // CHECK:STDOUT: %pattern_type.a14: type = pattern_type %impl.elem0.006 [symbolic]
  78. // CHECK:STDOUT: %J2.WithSelf.F2.type: type = fn_type @J2.WithSelf.F2, @J2.WithSelf(%Self.4a7) [symbolic]
  79. // CHECK:STDOUT: %J2.WithSelf.F2: %J2.WithSelf.F2.type = struct_value () [symbolic]
  80. // CHECK:STDOUT: %J2.assoc_type: type = assoc_entity_type @J2 [concrete]
  81. // CHECK:STDOUT: %assoc0.41c: %J2.assoc_type = assoc_entity element0, @J2.WithSelf.%J2.WithSelf.F2.decl [concrete]
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: file {
  85. // CHECK:STDOUT: %J2.decl.loc12: type = interface_decl @J2 [concrete = constants.%J2.type] {} {}
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT:
  88. // CHECK:STDOUT: interface @J2 {
  89. // CHECK:STDOUT: %Self: %J2.type = symbolic_binding Self, 0 [symbolic = constants.%Self.4a7]
  90. // CHECK:STDOUT: %J2.WithSelf.decl = interface_with_self_decl @J2 [concrete]
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: !with Self:
  93. // CHECK:STDOUT: %I2.ref: type = name_ref I2, file.%I2.decl [concrete = constants.%I2.type]
  94. // CHECK:STDOUT: %T2.ref: %I2.assoc_type = name_ref T2, @T2.%assoc0 [concrete = constants.%assoc0.7c1]
  95. // CHECK:STDOUT: %U2: %I2.assoc_type = alias_binding U2, @T2.%assoc0 [concrete = constants.%assoc0.7c1]
  96. // CHECK:STDOUT: %J2.WithSelf.F2.decl: @J2.WithSelf.%J2.WithSelf.F2.type (%J2.WithSelf.F2.type) = fn_decl @J2.WithSelf.F2 [symbolic = @J2.WithSelf.%J2.WithSelf.F2 (constants.%J2.WithSelf.F2)] {
  97. // CHECK:STDOUT: %return.param_patt: @J2.WithSelf.F2.%pattern_type (%pattern_type.a14) = out_param_pattern [concrete]
  98. // CHECK:STDOUT: %return.patt: @J2.WithSelf.F2.%pattern_type (%pattern_type.a14) = return_slot_pattern %return.param_patt, %U2.ref [concrete]
  99. // CHECK:STDOUT: } {
  100. // CHECK:STDOUT: %Self.as_type: type = facet_access_type @J2.%Self [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)]
  101. // CHECK:STDOUT: %I2.facet.loc14_14.2: %I2.type = facet_value %Self.as_type, (constants.%I2.lookup_impl_witness.d97) [symbolic = %I2.facet.loc14_14.1 (constants.%I2.facet.7a5)]
  102. // CHECK:STDOUT: %.loc14_14.3: %I2.type = converted @J2.%Self, %I2.facet.loc14_14.2 [symbolic = %I2.facet.loc14_14.1 (constants.%I2.facet.7a5)]
  103. // CHECK:STDOUT: %impl.elem0.loc14_14.2: type = impl_witness_access constants.%I2.lookup_impl_witness.d97, element0 [symbolic = %impl.elem0.loc14_14.1 (constants.%impl.elem0.006)]
  104. // CHECK:STDOUT: %U2.ref: type = name_ref U2, %impl.elem0.loc14_14.2 [symbolic = %impl.elem0.loc14_14.1 (constants.%impl.elem0.006)]
  105. // CHECK:STDOUT: %.loc14_14.4: Core.Form = init_form %U2.ref [symbolic = %.loc14_14.2 (constants.%.805)]
  106. // CHECK:STDOUT: %return.param: ref @J2.WithSelf.F2.%impl.elem0.loc14_14.1 (%impl.elem0.006) = out_param call_param0
  107. // CHECK:STDOUT: %return: ref @J2.WithSelf.F2.%impl.elem0.loc14_14.1 (%impl.elem0.006) = return_slot %return.param
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT: %assoc0: %J2.assoc_type = assoc_entity element0, %J2.WithSelf.F2.decl [concrete = constants.%assoc0.41c]
  110. // CHECK:STDOUT:
  111. // CHECK:STDOUT: !members:
  112. // CHECK:STDOUT: .Self = %Self
  113. // CHECK:STDOUT: .I2 = <poisoned>
  114. // CHECK:STDOUT: .I2 = <poisoned>
  115. // CHECK:STDOUT: .U2 = @J2.WithSelf.%U2
  116. // CHECK:STDOUT: .F2 = @J2.WithSelf.%assoc0
  117. // CHECK:STDOUT: witness = (@J2.WithSelf.%J2.WithSelf.F2.decl)
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: !requires:
  120. // CHECK:STDOUT: }
  121. // CHECK:STDOUT:
  122. // CHECK:STDOUT: generic fn @J2.WithSelf.F2(@J2.%Self: %J2.type) {
  123. // CHECK:STDOUT: %Self: %J2.type = symbolic_binding Self, 0 [symbolic = %Self (constants.%Self.4a7)]
  124. // CHECK:STDOUT: %Self.binding.as_type: type = symbolic_binding_type Self, 0, %Self [symbolic = %Self.binding.as_type (constants.%Self.binding.as_type)]
  125. // CHECK:STDOUT: %.loc14_14.1: require_specific_def_type = require_specific_def @V.binding.as_type.as.I2.impl(%Self) [symbolic = %.loc14_14.1 (constants.%.ef7)]
  126. // CHECK:STDOUT: %I2.lookup_impl_witness: <witness> = lookup_impl_witness %Self, @I2 [symbolic = %I2.lookup_impl_witness (constants.%I2.lookup_impl_witness.d97)]
  127. // CHECK:STDOUT: %I2.facet.loc14_14.1: %I2.type = facet_value %Self.binding.as_type, (%I2.lookup_impl_witness) [symbolic = %I2.facet.loc14_14.1 (constants.%I2.facet.7a5)]
  128. // CHECK:STDOUT: %impl.elem0.loc14_14.1: type = impl_witness_access %I2.lookup_impl_witness, element0 [symbolic = %impl.elem0.loc14_14.1 (constants.%impl.elem0.006)]
  129. // CHECK:STDOUT: %.loc14_14.2: Core.Form = init_form %impl.elem0.loc14_14.1 [symbolic = %.loc14_14.2 (constants.%.805)]
  130. // CHECK:STDOUT: %pattern_type: type = pattern_type %impl.elem0.loc14_14.1 [symbolic = %pattern_type (constants.%pattern_type.a14)]
  131. // CHECK:STDOUT:
  132. // CHECK:STDOUT: fn() -> out %return.param: @J2.WithSelf.F2.%impl.elem0.loc14_14.1 (%impl.elem0.006);
  133. // CHECK:STDOUT: }
  134. // CHECK:STDOUT:
  135. // CHECK:STDOUT: specific @J2.WithSelf(constants.%Self.4a7) {}
  136. // CHECK:STDOUT:
  137. // CHECK:STDOUT: specific @J2.WithSelf.F2(constants.%Self.4a7) {
  138. // CHECK:STDOUT: %Self => constants.%Self.4a7
  139. // CHECK:STDOUT: %Self.binding.as_type => constants.%Self.binding.as_type
  140. // CHECK:STDOUT: %.loc14_14.1 => constants.%.ef7
  141. // CHECK:STDOUT: %I2.lookup_impl_witness => constants.%I2.lookup_impl_witness.d97
  142. // CHECK:STDOUT: %I2.facet.loc14_14.1 => constants.%I2.facet.7a5
  143. // CHECK:STDOUT: %impl.elem0.loc14_14.1 => constants.%impl.elem0.006
  144. // CHECK:STDOUT: %.loc14_14.2 => constants.%.805
  145. // CHECK:STDOUT: %pattern_type => constants.%pattern_type.a14
  146. // CHECK:STDOUT: }
  147. // CHECK:STDOUT:
  148. // CHECK:STDOUT: --- call_with_compound_member_access.carbon
  149. // CHECK:STDOUT:
  150. // CHECK:STDOUT: constants {
  151. // CHECK:STDOUT: %C.type: type = facet_type <@C> [concrete]
  152. // CHECK:STDOUT: %Self: %C.type = symbolic_binding Self, 0 [symbolic]
  153. // CHECK:STDOUT: %Self.binding.as_type: type = symbolic_binding_type Self, 0, %Self [symbolic]
  154. // CHECK:STDOUT: %pattern_type: type = pattern_type %Self.binding.as_type [symbolic]
  155. // CHECK:STDOUT: %C.WithSelf.F.type: type = fn_type @C.WithSelf.F, @C.WithSelf(%Self) [symbolic]
  156. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  157. // CHECK:STDOUT: %C.WithSelf.F: %C.WithSelf.F.type = struct_value () [symbolic]
  158. // CHECK:STDOUT: %C.assoc_type: type = assoc_entity_type @C [concrete]
  159. // CHECK:STDOUT: %assoc0: %C.assoc_type = assoc_entity element0, @C.WithSelf.%C.WithSelf.F.decl [concrete]
  160. // CHECK:STDOUT: %C.WithSelf.G.type: type = fn_type @C.WithSelf.G, @C.WithSelf(%Self) [symbolic]
  161. // CHECK:STDOUT: %C.WithSelf.G: %C.WithSelf.G.type = struct_value () [symbolic]
  162. // CHECK:STDOUT: %C.lookup_impl_witness: <witness> = lookup_impl_witness %Self, @C [symbolic]
  163. // CHECK:STDOUT: %.018: type = fn_type_with_self_type %C.WithSelf.F.type, %Self [symbolic]
  164. // CHECK:STDOUT: %impl.elem0: %.018 = impl_witness_access %C.lookup_impl_witness, element0 [symbolic]
  165. // CHECK:STDOUT: %specific_impl_fn: <specific function> = specific_impl_function %impl.elem0, @C.WithSelf.F(%Self) [symbolic]
  166. // CHECK:STDOUT: }
  167. // CHECK:STDOUT:
  168. // CHECK:STDOUT: interface @C {
  169. // CHECK:STDOUT: <elided>
  170. // CHECK:STDOUT:
  171. // CHECK:STDOUT: !with Self:
  172. // CHECK:STDOUT: <elided>
  173. // CHECK:STDOUT:
  174. // CHECK:STDOUT: !members:
  175. // CHECK:STDOUT: .Self = %Self
  176. // CHECK:STDOUT: .F = @C.WithSelf.%assoc0
  177. // CHECK:STDOUT: .G = @C.WithSelf.%assoc1
  178. // CHECK:STDOUT: witness = (@C.WithSelf.%C.WithSelf.F.decl, @C.WithSelf.%C.WithSelf.G.decl)
  179. // CHECK:STDOUT:
  180. // CHECK:STDOUT: !requires:
  181. // CHECK:STDOUT: }
  182. // CHECK:STDOUT:
  183. // CHECK:STDOUT: generic fn @C.WithSelf.G(@C.%Self: %C.type) {
  184. // CHECK:STDOUT: <elided>
  185. // CHECK:STDOUT:
  186. // CHECK:STDOUT: !definition:
  187. // CHECK:STDOUT: <elided>
  188. // CHECK:STDOUT: %C.WithSelf.F.type: type = fn_type @C.WithSelf.F, @C.WithSelf(%Self) [symbolic = %C.WithSelf.F.type (constants.%C.WithSelf.F.type)]
  189. // CHECK:STDOUT: %.loc8: type = fn_type_with_self_type %C.WithSelf.F.type, %Self [symbolic = %.loc8 (constants.%.018)]
  190. // CHECK:STDOUT: %C.lookup_impl_witness: <witness> = lookup_impl_witness %Self, @C [symbolic = %C.lookup_impl_witness (constants.%C.lookup_impl_witness)]
  191. // CHECK:STDOUT: %impl.elem0.loc8_9.2: @C.WithSelf.G.%.loc8 (%.018) = impl_witness_access %C.lookup_impl_witness, element0 [symbolic = %impl.elem0.loc8_9.2 (constants.%impl.elem0)]
  192. // CHECK:STDOUT: %specific_impl_fn.loc8_9.2: <specific function> = specific_impl_function %impl.elem0.loc8_9.2, @C.WithSelf.F(%Self) [symbolic = %specific_impl_fn.loc8_9.2 (constants.%specific_impl_fn)]
  193. // CHECK:STDOUT:
  194. // CHECK:STDOUT: fn(%self.param: @C.WithSelf.G.%Self.binding.as_type (%Self.binding.as_type)) {
  195. // CHECK:STDOUT: !entry:
  196. // CHECK:STDOUT: %self.ref.loc8: @C.WithSelf.G.%Self.binding.as_type (%Self.binding.as_type) = name_ref self, %self
  197. // CHECK:STDOUT: %F.ref.loc8: %C.assoc_type = name_ref F, @C.WithSelf.%assoc0 [concrete = constants.%assoc0]
  198. // CHECK:STDOUT: %impl.elem0.loc8_9.1: @C.WithSelf.G.%.loc8 (%.018) = impl_witness_access constants.%C.lookup_impl_witness, element0 [symbolic = %impl.elem0.loc8_9.2 (constants.%impl.elem0)]
  199. // CHECK:STDOUT: %bound_method.loc8_9: <bound method> = bound_method %self.ref.loc8, %impl.elem0.loc8_9.1
  200. // CHECK:STDOUT: %specific_impl_fn.loc8_9.1: <specific function> = specific_impl_function %impl.elem0.loc8_9.1, @C.WithSelf.F(constants.%Self) [symbolic = %specific_impl_fn.loc8_9.2 (constants.%specific_impl_fn)]
  201. // CHECK:STDOUT: %bound_method.loc8_12: <bound method> = bound_method %self.ref.loc8, %specific_impl_fn.loc8_9.1
  202. // CHECK:STDOUT: %C.WithSelf.F.call.loc8: init %empty_tuple.type = call %bound_method.loc8_12(%self.ref.loc8)
  203. // CHECK:STDOUT: %self.ref.loc9: @C.WithSelf.G.%Self.binding.as_type (%Self.binding.as_type) = name_ref self, %self
  204. // CHECK:STDOUT: %impl.elem0.loc9: @C.WithSelf.G.%.loc8 (%.018) = impl_witness_access constants.%C.lookup_impl_witness, element0 [symbolic = %impl.elem0.loc8_9.2 (constants.%impl.elem0)]
  205. // CHECK:STDOUT: %F.ref.loc9: @C.WithSelf.G.%.loc8 (%.018) = name_ref F, %impl.elem0.loc9 [symbolic = %impl.elem0.loc8_9.2 (constants.%impl.elem0)]
  206. // CHECK:STDOUT: %bound_method.loc9_9: <bound method> = bound_method %self.ref.loc9, %F.ref.loc9
  207. // CHECK:STDOUT: %specific_impl_fn.loc9: <specific function> = specific_impl_function %F.ref.loc9, @C.WithSelf.F(constants.%Self) [symbolic = %specific_impl_fn.loc8_9.2 (constants.%specific_impl_fn)]
  208. // CHECK:STDOUT: %bound_method.loc9_14: <bound method> = bound_method %self.ref.loc9, %specific_impl_fn.loc9
  209. // CHECK:STDOUT: %C.WithSelf.F.call.loc9: init %empty_tuple.type = call %bound_method.loc9_14(%self.ref.loc9)
  210. // CHECK:STDOUT: <elided>
  211. // CHECK:STDOUT: }
  212. // CHECK:STDOUT: }
  213. // CHECK:STDOUT:
  214. // CHECK:STDOUT: specific @C.WithSelf(constants.%Self) {
  215. // CHECK:STDOUT: !definition:
  216. // CHECK:STDOUT: %Self => constants.%Self
  217. // CHECK:STDOUT: %C.WithSelf.F.type => constants.%C.WithSelf.F.type
  218. // CHECK:STDOUT: %C.WithSelf.F => constants.%C.WithSelf.F
  219. // CHECK:STDOUT: %C.WithSelf.G.type => constants.%C.WithSelf.G.type
  220. // CHECK:STDOUT: %C.WithSelf.G => constants.%C.WithSelf.G
  221. // CHECK:STDOUT: }
  222. // CHECK:STDOUT:
  223. // CHECK:STDOUT: specific @C.WithSelf.G(constants.%Self) {
  224. // CHECK:STDOUT: %Self => constants.%Self
  225. // CHECK:STDOUT: %Self.binding.as_type => constants.%Self.binding.as_type
  226. // CHECK:STDOUT: %pattern_type => constants.%pattern_type
  227. // CHECK:STDOUT: }
  228. // CHECK:STDOUT: