fail_not_facet.carbon 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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/...
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref Core//prelude/types, inst+15, loaded [template = constants.%Int32]
  61. // CHECK:STDOUT: %import_ref.2: %Bool.type = import_ref Core//prelude/types/bool, inst+5, loaded [template = constants.%Bool]
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: file {
  65. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  66. // CHECK:STDOUT: .Core = imports.%Core
  67. // CHECK:STDOUT: .F = %F.decl
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT: %Core.import = import Core
  70. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  71. // CHECK:STDOUT: %T.patt.loc8_6.1: <error> = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc8_6.2 (constants.%T.patt)]
  72. // 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)]
  73. // CHECK:STDOUT: } {
  74. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  75. // CHECK:STDOUT: %.loc8_10.1: type = value_of_initializer %int.make_type_32 [template = i32]
  76. // CHECK:STDOUT: %.loc8_10.2: type = converted %int.make_type_32, %.loc8_10.1 [template = i32]
  77. // CHECK:STDOUT: %.Self: <error> = bind_symbolic_name .Self, 0 [symbolic = constants.%.Self]
  78. // CHECK:STDOUT: %.Self.ref: <error> = name_ref .Self, %.Self [symbolic = constants.%.Self]
  79. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  80. // CHECK:STDOUT: %.loc8_14: type = where_expr %.Self [template = <error>] {
  81. // CHECK:STDOUT: requirement_equivalent %.Self.ref, %bool.make_type
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT: %T.param: <error> = value_param runtime_param<invalid>
  84. // CHECK:STDOUT: %T.loc8_6.1: <error> = bind_symbolic_name T, 0, %T.param [symbolic = %T.loc8_6.2 (constants.%T)]
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT:
  88. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: fn @Bool() -> type = "bool.make_type";
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: generic fn @F(%T.loc8_6.1: <error>) {
  93. // CHECK:STDOUT: %T.loc8_6.2: <error> = bind_symbolic_name T, 0 [symbolic = %T.loc8_6.2 (constants.%T)]
  94. // CHECK:STDOUT: %T.patt.loc8_6.2: <error> = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc8_6.2 (constants.%T.patt)]
  95. // CHECK:STDOUT:
  96. // CHECK:STDOUT: fn(%T.param_patt: <error>);
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: specific @F(constants.%T) {
  100. // CHECK:STDOUT: %T.loc8_6.2 => constants.%T
  101. // CHECK:STDOUT: %T.patt.loc8_6.2 => constants.%T
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT:
  104. // CHECK:STDOUT: --- fail_left_where_unknown.carbon
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: constants {
  107. // CHECK:STDOUT: %.Self: <error> = bind_symbolic_name .Self, 0 [symbolic]
  108. // CHECK:STDOUT: %Bool.type: type = fn_type @Bool [template]
  109. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  110. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [template]
  111. // CHECK:STDOUT: %U: <error> = bind_symbolic_name U, 0 [symbolic]
  112. // CHECK:STDOUT: %U.patt: <error> = symbolic_binding_pattern U, 0 [symbolic]
  113. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  114. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  115. // CHECK:STDOUT: }
  116. // CHECK:STDOUT:
  117. // CHECK:STDOUT: imports {
  118. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  119. // CHECK:STDOUT: .Bool = %import_ref
  120. // CHECK:STDOUT: import Core//prelude
  121. // CHECK:STDOUT: import Core//prelude/...
  122. // CHECK:STDOUT: }
  123. // CHECK:STDOUT: %import_ref: %Bool.type = import_ref Core//prelude/types/bool, inst+5, loaded [template = constants.%Bool]
  124. // CHECK:STDOUT: }
  125. // CHECK:STDOUT:
  126. // CHECK:STDOUT: file {
  127. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  128. // CHECK:STDOUT: .Core = imports.%Core
  129. // CHECK:STDOUT: .G = %G.decl
  130. // CHECK:STDOUT: }
  131. // CHECK:STDOUT: %Core.import = import Core
  132. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  133. // CHECK:STDOUT: %U.patt.loc12_6.1: <error> = symbolic_binding_pattern U, 0 [symbolic = %U.patt.loc12_6.2 (constants.%U.patt)]
  134. // 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)]
  135. // CHECK:STDOUT: } {
  136. // CHECK:STDOUT: %NOT_DECLARED.ref: <error> = name_ref NOT_DECLARED, <error> [template = <error>]
  137. // CHECK:STDOUT: %.Self: <error> = bind_symbolic_name .Self, 0 [symbolic = constants.%.Self]
  138. // CHECK:STDOUT: %.Self.ref: <error> = name_ref .Self, %.Self [symbolic = constants.%.Self]
  139. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  140. // CHECK:STDOUT: %.loc12: type = where_expr %.Self [template = <error>] {
  141. // CHECK:STDOUT: requirement_equivalent %.Self.ref, %bool.make_type
  142. // CHECK:STDOUT: }
  143. // CHECK:STDOUT: %U.param: <error> = value_param runtime_param<invalid>
  144. // CHECK:STDOUT: %U.loc12_6.1: <error> = bind_symbolic_name U, 0, %U.param [symbolic = %U.loc12_6.2 (constants.%U)]
  145. // CHECK:STDOUT: }
  146. // CHECK:STDOUT: }
  147. // CHECK:STDOUT:
  148. // CHECK:STDOUT: fn @Bool() -> type = "bool.make_type";
  149. // CHECK:STDOUT:
  150. // CHECK:STDOUT: generic fn @G(%U.loc12_6.1: <error>) {
  151. // CHECK:STDOUT: %U.loc12_6.2: <error> = bind_symbolic_name U, 0 [symbolic = %U.loc12_6.2 (constants.%U)]
  152. // CHECK:STDOUT: %U.patt.loc12_6.2: <error> = symbolic_binding_pattern U, 0 [symbolic = %U.patt.loc12_6.2 (constants.%U.patt)]
  153. // CHECK:STDOUT:
  154. // CHECK:STDOUT: fn(%U.param_patt: <error>);
  155. // CHECK:STDOUT: }
  156. // CHECK:STDOUT:
  157. // CHECK:STDOUT: specific @G(constants.%U) {
  158. // CHECK:STDOUT: %U.loc12_6.2 => constants.%U
  159. // CHECK:STDOUT: %U.patt.loc12_6.2 => constants.%U
  160. // CHECK:STDOUT: }
  161. // CHECK:STDOUT:
  162. // CHECK:STDOUT: --- fail_var.carbon
  163. // CHECK:STDOUT:
  164. // CHECK:STDOUT: constants {
  165. // CHECK:STDOUT: %.Self: <error> = bind_symbolic_name .Self, 0 [symbolic]
  166. // CHECK:STDOUT: %.1: i32 = int_value 3 [template]
  167. // CHECK:STDOUT: }
  168. // CHECK:STDOUT:
  169. // CHECK:STDOUT: imports {
  170. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  171. // CHECK:STDOUT: import Core//prelude
  172. // CHECK:STDOUT: import Core//prelude/...
  173. // CHECK:STDOUT: }
  174. // CHECK:STDOUT: }
  175. // CHECK:STDOUT:
  176. // CHECK:STDOUT: file {
  177. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  178. // CHECK:STDOUT: .Core = imports.%Core
  179. // CHECK:STDOUT: .v = %v
  180. // CHECK:STDOUT: }
  181. // CHECK:STDOUT: %Core.import = import Core
  182. // CHECK:STDOUT: %e.ref: <error> = name_ref e, <error> [template = <error>]
  183. // CHECK:STDOUT: %.Self: <error> = bind_symbolic_name .Self, 0 [symbolic = constants.%.Self]
  184. // CHECK:STDOUT: %.Self.ref: <error> = name_ref .Self, %.Self [symbolic = constants.%.Self]
  185. // CHECK:STDOUT: %.loc11_21: i32 = int_value 3 [template = constants.%.1]
  186. // CHECK:STDOUT: %.loc11_10: type = where_expr %.Self [template = <error>] {
  187. // CHECK:STDOUT: requirement_rewrite <error>, <error>
  188. // CHECK:STDOUT: }
  189. // CHECK:STDOUT: %v.var: ref <error> = var v
  190. // CHECK:STDOUT: %v: ref <error> = bind_name v, %v.var
  191. // CHECK:STDOUT: }
  192. // CHECK:STDOUT: