fail_deduce_imported_function.carbon 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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/none.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/function/generic/fail_deduce_imported_function.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/generic/fail_deduce_imported_function.carbon
  14. // --- lib.carbon
  15. package Lib;
  16. interface Z {}
  17. fn A[T:! Z](x: {.a: T}) {}
  18. // --- fail_deduce_imported_function.carbon
  19. import Lib;
  20. fn A[T:! Lib.Z](x: {.a: T}) {}
  21. fn B() {
  22. // CHECK:STDERR: fail_deduce_imported_function.carbon:[[@LINE+7]]:3: error: cannot deduce value for generic parameter `T` [DeductionIncomplete]
  23. // CHECK:STDERR: A({.b = {}});
  24. // CHECK:STDERR: ^~~~~~~~~~~~
  25. // CHECK:STDERR: fail_deduce_imported_function.carbon:[[@LINE-6]]:1: note: while deducing parameters of generic declared here [DeductionGenericHere]
  26. // CHECK:STDERR: fn A[T:! Lib.Z](x: {.a: T}) {}
  27. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  28. // CHECK:STDERR:
  29. A({.b = {}});
  30. // CHECK:STDERR: fail_deduce_imported_function.carbon:[[@LINE+8]]:3: error: cannot deduce value for generic parameter `T` [DeductionIncomplete]
  31. // CHECK:STDERR: Lib.A({.b = {}});
  32. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  33. // CHECK:STDERR: fail_deduce_imported_function.carbon:[[@LINE-17]]:1: in import [InImport]
  34. // CHECK:STDERR: lib.carbon:4:1: note: while deducing parameters of generic declared here [DeductionGenericHere]
  35. // CHECK:STDERR: fn A[T:! Z](x: {.a: T}) {}
  36. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
  37. // CHECK:STDERR:
  38. Lib.A({.b = {}});
  39. }
  40. // CHECK:STDOUT: --- lib.carbon
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: constants {
  43. // CHECK:STDOUT: %Z.type: type = facet_type <@Z> [concrete]
  44. // CHECK:STDOUT: %Self: %Z.type = symbolic_binding Self, 0 [symbolic]
  45. // CHECK:STDOUT: %type: type = facet_type <type> [concrete]
  46. // CHECK:STDOUT: %.Self: %type = symbolic_binding .Self [symbolic_self]
  47. // CHECK:STDOUT: %T: %Z.type = symbolic_binding T, 0 [symbolic]
  48. // CHECK:STDOUT: %pattern_type.4a0: type = pattern_type %Z.type [concrete]
  49. // CHECK:STDOUT: %T.binding.as_type: type = symbolic_binding_type T, 0, %T [symbolic]
  50. // CHECK:STDOUT: %struct_type.a: type = struct_type {.a: %T.binding.as_type} [symbolic]
  51. // CHECK:STDOUT: %pattern_type.f23: type = pattern_type %struct_type.a [symbolic]
  52. // CHECK:STDOUT: %A.type: type = fn_type @A [concrete]
  53. // CHECK:STDOUT: %A: %A.type = struct_value () [concrete]
  54. // CHECK:STDOUT: %require_complete: <witness> = require_complete_type %struct_type.a [symbolic]
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: file {
  58. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  59. // CHECK:STDOUT: .Z = %Z.decl
  60. // CHECK:STDOUT: .A = %A.decl
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT: %Z.decl: type = interface_decl @Z [concrete = constants.%Z.type] {} {}
  63. // CHECK:STDOUT: %A.decl: %A.type = fn_decl @A [concrete = constants.%A] {
  64. // CHECK:STDOUT: %T.patt: %pattern_type.4a0 = symbolic_binding_pattern T, 0 [concrete]
  65. // CHECK:STDOUT: %x.patt: @A.%pattern_type (%pattern_type.f23) = value_binding_pattern x [concrete]
  66. // CHECK:STDOUT: %x.param_patt: @A.%pattern_type (%pattern_type.f23) = value_param_pattern %x.patt, call_param0 [concrete]
  67. // CHECK:STDOUT: } {
  68. // CHECK:STDOUT: %.loc4_10: type = splice_block %Z.ref [concrete = constants.%Z.type] {
  69. // CHECK:STDOUT: %.Self: %type = symbolic_binding .Self [symbolic_self = constants.%.Self]
  70. // CHECK:STDOUT: %Z.ref: type = name_ref Z, file.%Z.decl [concrete = constants.%Z.type]
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT: %T.loc4_6.2: %Z.type = symbolic_binding T, 0 [symbolic = %T.loc4_6.1 (constants.%T)]
  73. // CHECK:STDOUT: %x.param: @A.%struct_type.a.loc4_22.1 (%struct_type.a) = value_param call_param0
  74. // CHECK:STDOUT: %.loc4_22: type = splice_block %struct_type.a.loc4_22.2 [symbolic = %struct_type.a.loc4_22.1 (constants.%struct_type.a)] {
  75. // CHECK:STDOUT: %T.ref: %Z.type = name_ref T, %T.loc4_6.2 [symbolic = %T.loc4_6.1 (constants.%T)]
  76. // CHECK:STDOUT: %T.as_type: type = facet_access_type %T.ref [symbolic = %T.binding.as_type (constants.%T.binding.as_type)]
  77. // CHECK:STDOUT: %.loc4_21: type = converted %T.ref, %T.as_type [symbolic = %T.binding.as_type (constants.%T.binding.as_type)]
  78. // CHECK:STDOUT: %struct_type.a.loc4_22.2: type = struct_type {.a: @A.%T.binding.as_type (%T.binding.as_type)} [symbolic = %struct_type.a.loc4_22.1 (constants.%struct_type.a)]
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT: %x: @A.%struct_type.a.loc4_22.1 (%struct_type.a) = value_binding x, %x.param
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: interface @Z {
  85. // CHECK:STDOUT: %Self: %Z.type = symbolic_binding Self, 0 [symbolic = constants.%Self]
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: !members:
  88. // CHECK:STDOUT: .Self = %Self
  89. // CHECK:STDOUT: witness = ()
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: !requires:
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: generic fn @A(%T.loc4_6.2: %Z.type) {
  95. // CHECK:STDOUT: %T.loc4_6.1: %Z.type = symbolic_binding T, 0 [symbolic = %T.loc4_6.1 (constants.%T)]
  96. // CHECK:STDOUT: %T.binding.as_type: type = symbolic_binding_type T, 0, %T.loc4_6.1 [symbolic = %T.binding.as_type (constants.%T.binding.as_type)]
  97. // CHECK:STDOUT: %struct_type.a.loc4_22.1: type = struct_type {.a: @A.%T.binding.as_type (%T.binding.as_type)} [symbolic = %struct_type.a.loc4_22.1 (constants.%struct_type.a)]
  98. // CHECK:STDOUT: %pattern_type: type = pattern_type %struct_type.a.loc4_22.1 [symbolic = %pattern_type (constants.%pattern_type.f23)]
  99. // CHECK:STDOUT:
  100. // CHECK:STDOUT: !definition:
  101. // CHECK:STDOUT: %require_complete: <witness> = require_complete_type %struct_type.a.loc4_22.1 [symbolic = %require_complete (constants.%require_complete)]
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: fn(%x.param: @A.%struct_type.a.loc4_22.1 (%struct_type.a)) {
  104. // CHECK:STDOUT: !entry:
  105. // CHECK:STDOUT: return
  106. // CHECK:STDOUT: }
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: specific @A(constants.%T) {
  110. // CHECK:STDOUT: %T.loc4_6.1 => constants.%T
  111. // CHECK:STDOUT: %T.binding.as_type => constants.%T.binding.as_type
  112. // CHECK:STDOUT: %struct_type.a.loc4_22.1 => constants.%struct_type.a
  113. // CHECK:STDOUT: %pattern_type => constants.%pattern_type.f23
  114. // CHECK:STDOUT: }
  115. // CHECK:STDOUT:
  116. // CHECK:STDOUT: --- fail_deduce_imported_function.carbon
  117. // CHECK:STDOUT:
  118. // CHECK:STDOUT: constants {
  119. // CHECK:STDOUT: %type: type = facet_type <type> [concrete]
  120. // CHECK:STDOUT: %.Self: %type = symbolic_binding .Self [symbolic_self]
  121. // CHECK:STDOUT: %Z.type: type = facet_type <@Z> [concrete]
  122. // CHECK:STDOUT: %T: %Z.type = symbolic_binding T, 0 [symbolic]
  123. // CHECK:STDOUT: %pattern_type.819: type = pattern_type %Z.type [concrete]
  124. // CHECK:STDOUT: %T.binding.as_type: type = symbolic_binding_type T, 0, %T [symbolic]
  125. // CHECK:STDOUT: %struct_type.a: type = struct_type {.a: %T.binding.as_type} [symbolic]
  126. // CHECK:STDOUT: %pattern_type.8bb: type = pattern_type %struct_type.a [symbolic]
  127. // CHECK:STDOUT: %A.type.00d: type = fn_type @A.loc4 [concrete]
  128. // CHECK:STDOUT: %A.1db: %A.type.00d = struct_value () [concrete]
  129. // CHECK:STDOUT: %require_complete: <witness> = require_complete_type %struct_type.a [symbolic]
  130. // CHECK:STDOUT: %B.type: type = fn_type @B [concrete]
  131. // CHECK:STDOUT: %B: %B.type = struct_value () [concrete]
  132. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  133. // CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
  134. // CHECK:STDOUT: %struct_type.b: type = struct_type {.b: %empty_struct_type} [concrete]
  135. // CHECK:STDOUT: %struct: %struct_type.b = struct_value (%empty_struct) [concrete]
  136. // CHECK:STDOUT: %A.type.fad: type = fn_type @A.1 [concrete]
  137. // CHECK:STDOUT: %A.7a0: %A.type.fad = struct_value () [concrete]
  138. // CHECK:STDOUT: }
  139. // CHECK:STDOUT:
  140. // CHECK:STDOUT: imports {
  141. // CHECK:STDOUT: %Lib: <namespace> = namespace file.%Lib.import, [concrete] {
  142. // CHECK:STDOUT: .Z = %Lib.Z
  143. // CHECK:STDOUT: .A = %Lib.A
  144. // CHECK:STDOUT: import Lib//default
  145. // CHECK:STDOUT: }
  146. // CHECK:STDOUT: %Lib.Z: type = import_ref Lib//default, Z, loaded [concrete = constants.%Z.type]
  147. // CHECK:STDOUT: %Lib.import_ref.52d = import_ref Lib//default, loc3_13, unloaded
  148. // CHECK:STDOUT: %Lib.A: %A.type.fad = import_ref Lib//default, A, loaded [concrete = constants.%A.7a0]
  149. // CHECK:STDOUT: %Lib.import_ref.ea9: %Z.type = import_ref Lib//default, loc4_6, loaded [symbolic = @A.1.%T (constants.%T)]
  150. // CHECK:STDOUT: }
  151. // CHECK:STDOUT:
  152. // CHECK:STDOUT: file {
  153. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  154. // CHECK:STDOUT: .Lib = imports.%Lib
  155. // CHECK:STDOUT: .A = %A.decl
  156. // CHECK:STDOUT: .B = %B.decl
  157. // CHECK:STDOUT: }
  158. // CHECK:STDOUT: %Lib.import = import Lib
  159. // CHECK:STDOUT: %A.decl: %A.type.00d = fn_decl @A.loc4 [concrete = constants.%A.1db] {
  160. // CHECK:STDOUT: %T.patt: %pattern_type.819 = symbolic_binding_pattern T, 0 [concrete]
  161. // CHECK:STDOUT: %x.patt: @A.loc4.%pattern_type (%pattern_type.8bb) = value_binding_pattern x [concrete]
  162. // CHECK:STDOUT: %x.param_patt: @A.loc4.%pattern_type (%pattern_type.8bb) = value_param_pattern %x.patt, call_param0 [concrete]
  163. // CHECK:STDOUT: } {
  164. // CHECK:STDOUT: %.loc4_13: type = splice_block %Z.ref [concrete = constants.%Z.type] {
  165. // CHECK:STDOUT: %.Self: %type = symbolic_binding .Self [symbolic_self = constants.%.Self]
  166. // CHECK:STDOUT: %Lib.ref: <namespace> = name_ref Lib, imports.%Lib [concrete = imports.%Lib]
  167. // CHECK:STDOUT: %Z.ref: type = name_ref Z, imports.%Lib.Z [concrete = constants.%Z.type]
  168. // CHECK:STDOUT: }
  169. // CHECK:STDOUT: %T.loc4_6.2: %Z.type = symbolic_binding T, 0 [symbolic = %T.loc4_6.1 (constants.%T)]
  170. // CHECK:STDOUT: %x.param: @A.loc4.%struct_type.a.loc4_26.1 (%struct_type.a) = value_param call_param0
  171. // CHECK:STDOUT: %.loc4_26: type = splice_block %struct_type.a.loc4_26.2 [symbolic = %struct_type.a.loc4_26.1 (constants.%struct_type.a)] {
  172. // CHECK:STDOUT: %T.ref: %Z.type = name_ref T, %T.loc4_6.2 [symbolic = %T.loc4_6.1 (constants.%T)]
  173. // CHECK:STDOUT: %T.as_type: type = facet_access_type %T.ref [symbolic = %T.binding.as_type (constants.%T.binding.as_type)]
  174. // CHECK:STDOUT: %.loc4_25: type = converted %T.ref, %T.as_type [symbolic = %T.binding.as_type (constants.%T.binding.as_type)]
  175. // CHECK:STDOUT: %struct_type.a.loc4_26.2: type = struct_type {.a: @A.loc4.%T.binding.as_type (%T.binding.as_type)} [symbolic = %struct_type.a.loc4_26.1 (constants.%struct_type.a)]
  176. // CHECK:STDOUT: }
  177. // CHECK:STDOUT: %x: @A.loc4.%struct_type.a.loc4_26.1 (%struct_type.a) = value_binding x, %x.param
  178. // CHECK:STDOUT: }
  179. // CHECK:STDOUT: %B.decl: %B.type = fn_decl @B [concrete = constants.%B] {} {}
  180. // CHECK:STDOUT: }
  181. // CHECK:STDOUT:
  182. // CHECK:STDOUT: interface @Z [from "lib.carbon"] {
  183. // CHECK:STDOUT: !members:
  184. // CHECK:STDOUT: .Self = imports.%Lib.import_ref.52d
  185. // CHECK:STDOUT: witness = ()
  186. // CHECK:STDOUT:
  187. // CHECK:STDOUT: !requires:
  188. // CHECK:STDOUT: }
  189. // CHECK:STDOUT:
  190. // CHECK:STDOUT: generic fn @A.loc4(%T.loc4_6.2: %Z.type) {
  191. // CHECK:STDOUT: %T.loc4_6.1: %Z.type = symbolic_binding T, 0 [symbolic = %T.loc4_6.1 (constants.%T)]
  192. // CHECK:STDOUT: %T.binding.as_type: type = symbolic_binding_type T, 0, %T.loc4_6.1 [symbolic = %T.binding.as_type (constants.%T.binding.as_type)]
  193. // CHECK:STDOUT: %struct_type.a.loc4_26.1: type = struct_type {.a: @A.loc4.%T.binding.as_type (%T.binding.as_type)} [symbolic = %struct_type.a.loc4_26.1 (constants.%struct_type.a)]
  194. // CHECK:STDOUT: %pattern_type: type = pattern_type %struct_type.a.loc4_26.1 [symbolic = %pattern_type (constants.%pattern_type.8bb)]
  195. // CHECK:STDOUT:
  196. // CHECK:STDOUT: !definition:
  197. // CHECK:STDOUT: %require_complete: <witness> = require_complete_type %struct_type.a.loc4_26.1 [symbolic = %require_complete (constants.%require_complete)]
  198. // CHECK:STDOUT:
  199. // CHECK:STDOUT: fn(%x.param: @A.loc4.%struct_type.a.loc4_26.1 (%struct_type.a)) {
  200. // CHECK:STDOUT: !entry:
  201. // CHECK:STDOUT: return
  202. // CHECK:STDOUT: }
  203. // CHECK:STDOUT: }
  204. // CHECK:STDOUT:
  205. // CHECK:STDOUT: fn @B() {
  206. // CHECK:STDOUT: !entry:
  207. // CHECK:STDOUT: %A.ref.loc14: %A.type.00d = name_ref A, file.%A.decl [concrete = constants.%A.1db]
  208. // CHECK:STDOUT: %.loc14_12: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
  209. // CHECK:STDOUT: %.loc14_13: %struct_type.b = struct_literal (%.loc14_12) [concrete = constants.%struct]
  210. // CHECK:STDOUT: %Lib.ref: <namespace> = name_ref Lib, imports.%Lib [concrete = imports.%Lib]
  211. // CHECK:STDOUT: %A.ref.loc24: %A.type.fad = name_ref A, imports.%Lib.A [concrete = constants.%A.7a0]
  212. // CHECK:STDOUT: %.loc24_16: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
  213. // CHECK:STDOUT: %.loc24_17: %struct_type.b = struct_literal (%.loc24_16) [concrete = constants.%struct]
  214. // CHECK:STDOUT: return
  215. // CHECK:STDOUT: }
  216. // CHECK:STDOUT:
  217. // CHECK:STDOUT: generic fn @A.1(imports.%Lib.import_ref.ea9: %Z.type) [from "lib.carbon"] {
  218. // CHECK:STDOUT: %T: %Z.type = symbolic_binding T, 0 [symbolic = %T (constants.%T)]
  219. // CHECK:STDOUT: %T.binding.as_type: type = symbolic_binding_type T, 0, %T [symbolic = %T.binding.as_type (constants.%T.binding.as_type)]
  220. // CHECK:STDOUT: %struct_type.a: type = struct_type {.a: @A.1.%T.binding.as_type (%T.binding.as_type)} [symbolic = %struct_type.a (constants.%struct_type.a)]
  221. // CHECK:STDOUT: %pattern_type: type = pattern_type %struct_type.a [symbolic = %pattern_type (constants.%pattern_type.8bb)]
  222. // CHECK:STDOUT:
  223. // CHECK:STDOUT: !definition:
  224. // CHECK:STDOUT: %require_complete: <witness> = require_complete_type %struct_type.a [symbolic = %require_complete (constants.%require_complete)]
  225. // CHECK:STDOUT:
  226. // CHECK:STDOUT: fn;
  227. // CHECK:STDOUT: }
  228. // CHECK:STDOUT:
  229. // CHECK:STDOUT: specific @A.loc4(constants.%T) {
  230. // CHECK:STDOUT: %T.loc4_6.1 => constants.%T
  231. // CHECK:STDOUT: %T.binding.as_type => constants.%T.binding.as_type
  232. // CHECK:STDOUT: %struct_type.a.loc4_26.1 => constants.%struct_type.a
  233. // CHECK:STDOUT: %pattern_type => constants.%pattern_type.8bb
  234. // CHECK:STDOUT: }
  235. // CHECK:STDOUT:
  236. // CHECK:STDOUT: specific @A.1(constants.%T) {
  237. // CHECK:STDOUT: %T => constants.%T
  238. // CHECK:STDOUT: %T.binding.as_type => constants.%T.binding.as_type
  239. // CHECK:STDOUT: %struct_type.a => constants.%struct_type.a
  240. // CHECK:STDOUT: %pattern_type => constants.%pattern_type.8bb
  241. // CHECK:STDOUT: }
  242. // CHECK:STDOUT: