fail_not_facet.carbon 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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/where_expr/fail_not_facet.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/where_expr/fail_not_facet.carbon
  10. // --- fail_left_where_not_facet.carbon
  11. library "[[@TEST_NAME]]";
  12. // CHECK:STDERR: fail_left_where_not_facet.carbon:[[@LINE+4]]:10: error: left argument of `where` operator must be a facet type [WhereOnNonFacetType]
  13. // CHECK:STDERR: fn F(T:! i32 where .Self == bool);
  14. // CHECK:STDERR: ^~~
  15. // CHECK:STDERR:
  16. fn F(T:! i32 where .Self == bool);
  17. // --- fail_left_where_unknown.carbon
  18. library "[[@TEST_NAME]]";
  19. // CHECK:STDERR: fail_left_where_unknown.carbon:[[@LINE+8]]:10: error: name `NOT_DECLARED` not found [NameNotFound]
  20. // CHECK:STDERR: fn G(U:! NOT_DECLARED where .Self == bool);
  21. // CHECK:STDERR: ^~~~~~~~~~~~
  22. // CHECK:STDERR:
  23. // CHECK:STDERR: fail_left_where_unknown.carbon:[[@LINE+4]]:10: error: left argument of `where` operator must be a facet type [WhereOnNonFacetType]
  24. // CHECK:STDERR: fn G(U:! NOT_DECLARED where .Self == bool);
  25. // CHECK:STDERR: ^~~~~~~~~~~~
  26. // CHECK:STDERR:
  27. fn G(U:! NOT_DECLARED where .Self == bool);
  28. // --- fail_var.carbon
  29. library "[[@TEST_NAME]]";
  30. // CHECK:STDERR: fail_var.carbon:[[@LINE+7]]:8: error: name `e` not found [NameNotFound]
  31. // CHECK:STDERR: var v: e where .x = 3;
  32. // CHECK:STDERR: ^
  33. // CHECK:STDERR:
  34. // CHECK:STDERR: fail_var.carbon:[[@LINE+3]]:8: error: left argument of `where` operator must be a facet type [WhereOnNonFacetType]
  35. // CHECK:STDERR: var v: e where .x = 3;
  36. // CHECK:STDERR: ^
  37. var v: e where .x = 3;
  38. // CHECK:STDOUT: --- fail_left_where_not_facet.carbon
  39. // CHECK:STDOUT:
  40. // CHECK:STDOUT: constants {
  41. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  42. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  43. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  44. // CHECK:STDOUT: %.Self: <error> = bind_symbolic_name .Self, 0 [symbolic]
  45. // CHECK:STDOUT: %Bool.type: type = fn_type @Bool [template]
  46. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [template]
  47. // CHECK:STDOUT: %T: <error> = bind_symbolic_name T, 0 [symbolic]
  48. // CHECK:STDOUT: %T.patt: <error> = symbolic_binding_pattern T, 0 [symbolic]
  49. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  50. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: imports {
  54. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  55. // CHECK:STDOUT: .Int32 = %import_ref.1
  56. // CHECK:STDOUT: .Bool = %import_ref.2
  57. // CHECK:STDOUT: import Core//prelude
  58. // CHECK:STDOUT: import Core//prelude/operators
  59. // CHECK:STDOUT: import Core//prelude/types
  60. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  61. // CHECK:STDOUT: import Core//prelude/operators/as
  62. // CHECK:STDOUT: import Core//prelude/operators/index
  63. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  64. // CHECK:STDOUT: import Core//prelude/operators/comparison
  65. // CHECK:STDOUT: import Core//prelude/types/bool
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref Core//prelude/types, inst+15, loaded [template = constants.%Int32]
  68. // CHECK:STDOUT: %import_ref.2: %Bool.type = import_ref Core//prelude/types/bool, inst+5, loaded [template = constants.%Bool]
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: file {
  72. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  73. // CHECK:STDOUT: .Core = imports.%Core
  74. // CHECK:STDOUT: .F = %F.decl
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT: %Core.import = import Core
  77. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  78. // CHECK:STDOUT: %T.patt.loc8_6.1: <error> = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc8_6.2 (constants.%T.patt)]
  79. // CHECK:STDOUT: %T.param_patt: <error> = value_param_pattern %T.patt.loc8_6.1, runtime_param<invalid> [symbolic = %T.patt.loc8_6.2 (constants.%T.patt)]
  80. // CHECK:STDOUT: } {
  81. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  82. // CHECK:STDOUT: %.loc8_10.1: type = value_of_initializer %int.make_type_32 [template = i32]
  83. // CHECK:STDOUT: %.loc8_10.2: type = converted %int.make_type_32, %.loc8_10.1 [template = i32]
  84. // CHECK:STDOUT: %.Self: <error> = bind_symbolic_name .Self, 0 [symbolic = constants.%.Self]
  85. // CHECK:STDOUT: %.Self.ref: <error> = name_ref .Self, %.Self [symbolic = constants.%.Self]
  86. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  87. // CHECK:STDOUT: %.loc8_14: type = where_expr %.Self [template = <error>] {
  88. // CHECK:STDOUT: requirement_equivalent %.Self.ref, %bool.make_type
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT: %T.param: <error> = value_param runtime_param<invalid>
  91. // CHECK:STDOUT: %T.loc8_6.1: <error> = bind_symbolic_name T, 0, %T.param [symbolic = %T.loc8_6.2 (constants.%T)]
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: fn @Bool() -> type = "bool.make_type";
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: generic fn @F(%T.loc8_6.1: <error>) {
  100. // CHECK:STDOUT: %T.loc8_6.2: <error> = bind_symbolic_name T, 0 [symbolic = %T.loc8_6.2 (constants.%T)]
  101. // CHECK:STDOUT: %T.patt.loc8_6.2: <error> = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc8_6.2 (constants.%T.patt)]
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: fn(%T.param_patt: <error>);
  104. // CHECK:STDOUT: }
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: specific @F(constants.%T) {
  107. // CHECK:STDOUT: %T.loc8_6.2 => constants.%T
  108. // CHECK:STDOUT: %T.patt.loc8_6.2 => constants.%T
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT:
  111. // CHECK:STDOUT: --- fail_left_where_unknown.carbon
  112. // CHECK:STDOUT:
  113. // CHECK:STDOUT: constants {
  114. // CHECK:STDOUT: %.Self: <error> = bind_symbolic_name .Self, 0 [symbolic]
  115. // CHECK:STDOUT: %Bool.type: type = fn_type @Bool [template]
  116. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  117. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [template]
  118. // CHECK:STDOUT: %U: <error> = bind_symbolic_name U, 0 [symbolic]
  119. // CHECK:STDOUT: %U.patt: <error> = symbolic_binding_pattern U, 0 [symbolic]
  120. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  121. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  122. // CHECK:STDOUT: }
  123. // CHECK:STDOUT:
  124. // CHECK:STDOUT: imports {
  125. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  126. // CHECK:STDOUT: .Bool = %import_ref
  127. // CHECK:STDOUT: import Core//prelude
  128. // CHECK:STDOUT: import Core//prelude/operators
  129. // CHECK:STDOUT: import Core//prelude/types
  130. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  131. // CHECK:STDOUT: import Core//prelude/operators/as
  132. // CHECK:STDOUT: import Core//prelude/operators/index
  133. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  134. // CHECK:STDOUT: import Core//prelude/operators/comparison
  135. // CHECK:STDOUT: import Core//prelude/types/bool
  136. // CHECK:STDOUT: }
  137. // CHECK:STDOUT: %import_ref: %Bool.type = import_ref Core//prelude/types/bool, inst+5, loaded [template = constants.%Bool]
  138. // CHECK:STDOUT: }
  139. // CHECK:STDOUT:
  140. // CHECK:STDOUT: file {
  141. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  142. // CHECK:STDOUT: .Core = imports.%Core
  143. // CHECK:STDOUT: .G = %G.decl
  144. // CHECK:STDOUT: }
  145. // CHECK:STDOUT: %Core.import = import Core
  146. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  147. // CHECK:STDOUT: %U.patt.loc12_6.1: <error> = symbolic_binding_pattern U, 0 [symbolic = %U.patt.loc12_6.2 (constants.%U.patt)]
  148. // CHECK:STDOUT: %U.param_patt: <error> = value_param_pattern %U.patt.loc12_6.1, runtime_param<invalid> [symbolic = %U.patt.loc12_6.2 (constants.%U.patt)]
  149. // CHECK:STDOUT: } {
  150. // CHECK:STDOUT: %NOT_DECLARED.ref: <error> = name_ref NOT_DECLARED, <error> [template = <error>]
  151. // CHECK:STDOUT: %.Self: <error> = bind_symbolic_name .Self, 0 [symbolic = constants.%.Self]
  152. // CHECK:STDOUT: %.Self.ref: <error> = name_ref .Self, %.Self [symbolic = constants.%.Self]
  153. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  154. // CHECK:STDOUT: %.loc12: type = where_expr %.Self [template = <error>] {
  155. // CHECK:STDOUT: requirement_equivalent %.Self.ref, %bool.make_type
  156. // CHECK:STDOUT: }
  157. // CHECK:STDOUT: %U.param: <error> = value_param runtime_param<invalid>
  158. // CHECK:STDOUT: %U.loc12_6.1: <error> = bind_symbolic_name U, 0, %U.param [symbolic = %U.loc12_6.2 (constants.%U)]
  159. // CHECK:STDOUT: }
  160. // CHECK:STDOUT: }
  161. // CHECK:STDOUT:
  162. // CHECK:STDOUT: fn @Bool() -> type = "bool.make_type";
  163. // CHECK:STDOUT:
  164. // CHECK:STDOUT: generic fn @G(%U.loc12_6.1: <error>) {
  165. // CHECK:STDOUT: %U.loc12_6.2: <error> = bind_symbolic_name U, 0 [symbolic = %U.loc12_6.2 (constants.%U)]
  166. // CHECK:STDOUT: %U.patt.loc12_6.2: <error> = symbolic_binding_pattern U, 0 [symbolic = %U.patt.loc12_6.2 (constants.%U.patt)]
  167. // CHECK:STDOUT:
  168. // CHECK:STDOUT: fn(%U.param_patt: <error>);
  169. // CHECK:STDOUT: }
  170. // CHECK:STDOUT:
  171. // CHECK:STDOUT: specific @G(constants.%U) {
  172. // CHECK:STDOUT: %U.loc12_6.2 => constants.%U
  173. // CHECK:STDOUT: %U.patt.loc12_6.2 => constants.%U
  174. // CHECK:STDOUT: }
  175. // CHECK:STDOUT:
  176. // CHECK:STDOUT: --- fail_var.carbon
  177. // CHECK:STDOUT:
  178. // CHECK:STDOUT: constants {
  179. // CHECK:STDOUT: %.Self: <error> = bind_symbolic_name .Self, 0 [symbolic]
  180. // CHECK:STDOUT: %.1: i32 = int_literal 3 [template]
  181. // CHECK:STDOUT: }
  182. // CHECK:STDOUT:
  183. // CHECK:STDOUT: imports {
  184. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  185. // CHECK:STDOUT: import Core//prelude
  186. // CHECK:STDOUT: import Core//prelude/operators
  187. // CHECK:STDOUT: import Core//prelude/types
  188. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  189. // CHECK:STDOUT: import Core//prelude/operators/as
  190. // CHECK:STDOUT: import Core//prelude/operators/index
  191. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  192. // CHECK:STDOUT: import Core//prelude/operators/comparison
  193. // CHECK:STDOUT: import Core//prelude/types/bool
  194. // CHECK:STDOUT: }
  195. // CHECK:STDOUT: }
  196. // CHECK:STDOUT:
  197. // CHECK:STDOUT: file {
  198. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  199. // CHECK:STDOUT: .Core = imports.%Core
  200. // CHECK:STDOUT: .v = %v
  201. // CHECK:STDOUT: }
  202. // CHECK:STDOUT: %Core.import = import Core
  203. // CHECK:STDOUT: %e.ref: <error> = name_ref e, <error> [template = <error>]
  204. // CHECK:STDOUT: %.Self: <error> = bind_symbolic_name .Self, 0 [symbolic = constants.%.Self]
  205. // CHECK:STDOUT: %.Self.ref: <error> = name_ref .Self, %.Self [symbolic = constants.%.Self]
  206. // CHECK:STDOUT: %.loc11_21: i32 = int_literal 3 [template = constants.%.1]
  207. // CHECK:STDOUT: %.loc11_10: type = where_expr %.Self [template = <error>] {
  208. // CHECK:STDOUT: requirement_rewrite <error>, <error>
  209. // CHECK:STDOUT: }
  210. // CHECK:STDOUT: %v.var: ref <error> = var v
  211. // CHECK:STDOUT: %v: ref <error> = bind_name v, %v.var
  212. // CHECK:STDOUT: }
  213. // CHECK:STDOUT: