fail_member_lookup.carbon 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. // 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/interface/fail_member_lookup.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interface/fail_member_lookup.carbon
  14. // --- fail_member_lookup.carbon
  15. library "[[@TEST_NAME]]";
  16. interface Interface {
  17. fn F();
  18. let T:! type;
  19. }
  20. fn F() {
  21. // CHECK:STDERR: fail_member_lookup.carbon:[[@LINE+4]]:3: error: value of type `<associated entity in Interface>` is not callable [CallToNonCallable]
  22. // CHECK:STDERR: Interface.F();
  23. // CHECK:STDERR: ^~~~~~~~~~~~~
  24. // CHECK:STDERR:
  25. Interface.F();
  26. // CHECK:STDERR: fail_member_lookup.carbon:[[@LINE+7]]:10: error: cannot implicitly convert non-type value of type `<associated entity in Interface>` to `type` [ConversionFailureNonTypeToFacet]
  27. // CHECK:STDERR: var v: Interface.T;
  28. // CHECK:STDERR: ^~~~~~~~~~~
  29. // CHECK:STDERR: fail_member_lookup.carbon:[[@LINE+4]]:10: note: type `<associated entity in Interface>` does not implement interface `Core.ImplicitAs(type)` [MissingImplInMemberAccessNote]
  30. // CHECK:STDERR: var v: Interface.T;
  31. // CHECK:STDERR: ^~~~~~~~~~~
  32. // CHECK:STDERR:
  33. var v: Interface.T;
  34. }
  35. interface Different {}
  36. // CHECK:STDERR: fail_member_lookup.carbon:[[@LINE+4]]:24: error: cannot convert type `U` that implements `Different` into type implementing `Interface` [ConversionFailureFacetToFacet]
  37. // CHECK:STDERR: fn G(U:! Different) -> U.(Interface.T);
  38. // CHECK:STDERR: ^~~~~~~~~~~~~~~
  39. // CHECK:STDERR:
  40. fn G(U:! Different) -> U.(Interface.T);
  41. // CHECK:STDOUT: --- fail_member_lookup.carbon
  42. // CHECK:STDOUT:
  43. // CHECK:STDOUT: constants {
  44. // CHECK:STDOUT: %Interface.type: type = facet_type <@Interface> [concrete]
  45. // CHECK:STDOUT: %Self.7fe: %Interface.type = symbolic_binding Self, 0 [symbolic]
  46. // CHECK:STDOUT: %Interface.F.type: type = fn_type @Interface.F [concrete]
  47. // CHECK:STDOUT: %Interface.F: %Interface.F.type = struct_value () [concrete]
  48. // CHECK:STDOUT: %Interface.assoc_type: type = assoc_entity_type @Interface [concrete]
  49. // CHECK:STDOUT: %assoc0.b4c: %Interface.assoc_type = assoc_entity element0, @Interface.%Interface.F.decl [concrete]
  50. // CHECK:STDOUT: %assoc1: %Interface.assoc_type = assoc_entity element1, @Interface.%T [concrete]
  51. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  52. // CHECK:STDOUT: %F: %F.type = struct_value () [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: %Destroy.type: type = facet_type <@Destroy> [concrete]
  56. // CHECK:STDOUT: %Different.type: type = facet_type <@Different> [concrete]
  57. // CHECK:STDOUT: %Self.c20: %Different.type = symbolic_binding Self, 0 [symbolic]
  58. // CHECK:STDOUT: %type: type = facet_type <type> [concrete]
  59. // CHECK:STDOUT: %.Self: %type = symbolic_binding .Self [symbolic_self]
  60. // CHECK:STDOUT: %U: %Different.type = symbolic_binding U, 0 [symbolic]
  61. // CHECK:STDOUT: %pattern_type.fa7: type = pattern_type %Different.type [concrete]
  62. // CHECK:STDOUT: %U.binding.as_type: type = symbolic_binding_type U, 0, %U [symbolic]
  63. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  64. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: imports {
  68. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  69. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  70. // CHECK:STDOUT: .Destroy = %Core.Destroy
  71. // CHECK:STDOUT: import Core//prelude
  72. // CHECK:STDOUT: import Core//prelude/...
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT: %Core.ImplicitAs: %ImplicitAs.type.cc7 = import_ref Core//prelude/parts/as, ImplicitAs, loaded [concrete = constants.%ImplicitAs.generic]
  75. // CHECK:STDOUT: %Core.Destroy: type = import_ref Core//prelude/parts/destroy, Destroy, loaded [concrete = constants.%Destroy.type]
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: file {
  79. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  80. // CHECK:STDOUT: .Core = imports.%Core
  81. // CHECK:STDOUT: .Interface = %Interface.decl
  82. // CHECK:STDOUT: .F = %F.decl
  83. // CHECK:STDOUT: .Different = %Different.decl
  84. // CHECK:STDOUT: .G = %G.decl
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT: %Core.import = import Core
  87. // CHECK:STDOUT: %Interface.decl: type = interface_decl @Interface [concrete = constants.%Interface.type] {} {}
  88. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
  89. // CHECK:STDOUT: %Different.decl: type = interface_decl @Different [concrete = constants.%Different.type] {} {}
  90. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {
  91. // CHECK:STDOUT: %U.patt: %pattern_type.fa7 = symbolic_binding_pattern U, 0 [concrete]
  92. // CHECK:STDOUT: %return.patt: <error> = return_slot_pattern [concrete]
  93. // CHECK:STDOUT: %return.param_patt: <error> = out_param_pattern %return.patt, call_param0 [concrete]
  94. // CHECK:STDOUT: } {
  95. // CHECK:STDOUT: %U.ref: %Different.type = name_ref U, %U.loc32_6.2 [symbolic = %U.loc32_6.1 (constants.%U)]
  96. // CHECK:STDOUT: %Interface.ref: type = name_ref Interface, file.%Interface.decl [concrete = constants.%Interface.type]
  97. // CHECK:STDOUT: %T.ref: %Interface.assoc_type = name_ref T, @T.%assoc1 [concrete = constants.%assoc1]
  98. // CHECK:STDOUT: %U.as_type: type = facet_access_type %U.ref [symbolic = %U.binding.as_type (constants.%U.binding.as_type)]
  99. // CHECK:STDOUT: %.loc32: type = splice_block %Different.ref [concrete = constants.%Different.type] {
  100. // CHECK:STDOUT: %.Self: %type = symbolic_binding .Self [symbolic_self = constants.%.Self]
  101. // CHECK:STDOUT: %Different.ref: type = name_ref Different, file.%Different.decl [concrete = constants.%Different.type]
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT: %U.loc32_6.2: %Different.type = symbolic_binding U, 0 [symbolic = %U.loc32_6.1 (constants.%U)]
  104. // CHECK:STDOUT: %return.param: ref <error> = out_param call_param0
  105. // CHECK:STDOUT: %return: ref <error> = return_slot %return.param
  106. // CHECK:STDOUT: }
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: interface @Interface {
  110. // CHECK:STDOUT: %Self: %Interface.type = symbolic_binding Self, 0 [symbolic = constants.%Self.7fe]
  111. // CHECK:STDOUT: %Interface.F.decl: %Interface.F.type = fn_decl @Interface.F [concrete = constants.%Interface.F] {} {}
  112. // CHECK:STDOUT: %assoc0: %Interface.assoc_type = assoc_entity element0, %Interface.F.decl [concrete = constants.%assoc0.b4c]
  113. // CHECK:STDOUT: %T: type = assoc_const_decl @T [concrete] {
  114. // CHECK:STDOUT: %assoc1: %Interface.assoc_type = assoc_entity element1, @Interface.%T [concrete = constants.%assoc1]
  115. // CHECK:STDOUT: }
  116. // CHECK:STDOUT:
  117. // CHECK:STDOUT: !members:
  118. // CHECK:STDOUT: .Self = %Self
  119. // CHECK:STDOUT: .F = %assoc0
  120. // CHECK:STDOUT: .T = @T.%assoc1
  121. // CHECK:STDOUT: witness = (%Interface.F.decl, %T)
  122. // CHECK:STDOUT:
  123. // CHECK:STDOUT: !requires:
  124. // CHECK:STDOUT: }
  125. // CHECK:STDOUT:
  126. // CHECK:STDOUT: interface @Different {
  127. // CHECK:STDOUT: %Self: %Different.type = symbolic_binding Self, 0 [symbolic = constants.%Self.c20]
  128. // CHECK:STDOUT:
  129. // CHECK:STDOUT: !members:
  130. // CHECK:STDOUT: .Self = %Self
  131. // CHECK:STDOUT: witness = ()
  132. // CHECK:STDOUT:
  133. // CHECK:STDOUT: !requires:
  134. // CHECK:STDOUT: }
  135. // CHECK:STDOUT:
  136. // CHECK:STDOUT: generic assoc_const @T(@Interface.%Self: %Interface.type) {
  137. // CHECK:STDOUT: assoc_const T:! type;
  138. // CHECK:STDOUT: }
  139. // CHECK:STDOUT:
  140. // CHECK:STDOUT: generic fn @Interface.F(@Interface.%Self: %Interface.type) {
  141. // CHECK:STDOUT: fn();
  142. // CHECK:STDOUT: }
  143. // CHECK:STDOUT:
  144. // CHECK:STDOUT: fn @F() {
  145. // CHECK:STDOUT: !entry:
  146. // CHECK:STDOUT: %Interface.ref.loc14: type = name_ref Interface, file.%Interface.decl [concrete = constants.%Interface.type]
  147. // CHECK:STDOUT: %F.ref: %Interface.assoc_type = name_ref F, @Interface.%assoc0 [concrete = constants.%assoc0.b4c]
  148. // CHECK:STDOUT: name_binding_decl {
  149. // CHECK:STDOUT: %v.patt: <error> = ref_binding_pattern v [concrete]
  150. // CHECK:STDOUT: %v.var_patt: <error> = var_pattern %v.patt [concrete]
  151. // CHECK:STDOUT: }
  152. // CHECK:STDOUT: %v.var: ref <error> = var %v.var_patt [concrete = <error>]
  153. // CHECK:STDOUT: %.1: <error> = splice_block <error> [concrete = <error>] {
  154. // CHECK:STDOUT: %Interface.ref.loc23: type = name_ref Interface, file.%Interface.decl [concrete = constants.%Interface.type]
  155. // CHECK:STDOUT: %T.ref: %Interface.assoc_type = name_ref T, @T.%assoc1 [concrete = constants.%assoc1]
  156. // CHECK:STDOUT: %.loc23: type = converted %T.ref, <error> [concrete = <error>]
  157. // CHECK:STDOUT: }
  158. // CHECK:STDOUT: %v: ref <error> = ref_binding v, <error> [concrete = <error>]
  159. // CHECK:STDOUT: return
  160. // CHECK:STDOUT: }
  161. // CHECK:STDOUT:
  162. // CHECK:STDOUT: generic fn @G(%U.loc32_6.2: %Different.type) {
  163. // CHECK:STDOUT: %U.loc32_6.1: %Different.type = symbolic_binding U, 0 [symbolic = %U.loc32_6.1 (constants.%U)]
  164. // CHECK:STDOUT: %U.binding.as_type: type = symbolic_binding_type U, 0, %U.loc32_6.1 [symbolic = %U.binding.as_type (constants.%U.binding.as_type)]
  165. // CHECK:STDOUT:
  166. // CHECK:STDOUT: fn() -> <error>;
  167. // CHECK:STDOUT: }
  168. // CHECK:STDOUT:
  169. // CHECK:STDOUT: specific @Interface.F(constants.%Self.7fe) {}
  170. // CHECK:STDOUT:
  171. // CHECK:STDOUT: specific @T(constants.%Self.7fe) {}
  172. // CHECK:STDOUT:
  173. // CHECK:STDOUT: specific @G(constants.%U) {
  174. // CHECK:STDOUT: %U.loc32_6.1 => constants.%U
  175. // CHECK:STDOUT: %U.binding.as_type => constants.%U.binding.as_type
  176. // CHECK:STDOUT: }
  177. // CHECK:STDOUT: