fail_not_facet.carbon 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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+4]]: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. fn G(U:! NOT_DECLARED where .Self == bool);
  24. // --- fail_var.carbon
  25. library "[[@TEST_NAME]]";
  26. // CHECK:STDERR: fail_var.carbon:[[@LINE+3]]:8: error: name `e` not found [NameNotFound]
  27. // CHECK:STDERR: var v: e where .x = 3;
  28. // CHECK:STDERR: ^
  29. var v: e where .x = 3;
  30. // CHECK:STDOUT: --- fail_left_where_not_facet.carbon
  31. // CHECK:STDOUT:
  32. // CHECK:STDOUT: constants {
  33. // CHECK:STDOUT: %.1: Core.IntLiteral = int_value 32 [template]
  34. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  35. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  36. // CHECK:STDOUT: %i32: type = int_type signed, %.1 [template]
  37. // CHECK:STDOUT: %.Self: <error> = bind_symbolic_name .Self, 0 [symbolic]
  38. // CHECK:STDOUT: %Bool.type: type = fn_type @Bool [template]
  39. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [template]
  40. // CHECK:STDOUT: %T: <error> = bind_symbolic_name T, 0 [symbolic]
  41. // CHECK:STDOUT: %T.patt: <error> = symbolic_binding_pattern T, 0 [symbolic]
  42. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  43. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: imports {
  47. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  48. // CHECK:STDOUT: .Int = %import_ref.1
  49. // CHECK:STDOUT: .Bool = %import_ref.2
  50. // CHECK:STDOUT: import Core//prelude
  51. // CHECK:STDOUT: import Core//prelude/...
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: file {
  56. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  57. // CHECK:STDOUT: .Core = imports.%Core
  58. // CHECK:STDOUT: .F = %F.decl
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT: %Core.import = import Core
  61. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  62. // CHECK:STDOUT: %T.patt.loc8_6.1: <error> = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc8_6.2 (constants.%T.patt)]
  63. // 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)]
  64. // CHECK:STDOUT: } {
  65. // CHECK:STDOUT: %.loc8_10.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  66. // CHECK:STDOUT: %int.make_type_signed: init type = call constants.%Int(%.loc8_10.1) [template = constants.%i32]
  67. // CHECK:STDOUT: %.loc8_10.2: type = value_of_initializer %int.make_type_signed [template = constants.%i32]
  68. // CHECK:STDOUT: %.loc8_10.3: type = converted %int.make_type_signed, %.loc8_10.2 [template = constants.%i32]
  69. // CHECK:STDOUT: %.Self: <error> = bind_symbolic_name .Self, 0 [symbolic = constants.%.Self]
  70. // CHECK:STDOUT: %.Self.ref: <error> = name_ref .Self, %.Self [symbolic = constants.%.Self]
  71. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  72. // CHECK:STDOUT: %.loc8_14: type = where_expr %.Self [template = <error>] {
  73. // CHECK:STDOUT: requirement_equivalent %.Self.ref, %bool.make_type
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT: %T.param: <error> = value_param runtime_param<invalid>
  76. // CHECK:STDOUT: %T.loc8_6.1: <error> = bind_symbolic_name T, 0, %T.param [symbolic = %T.loc8_6.2 (constants.%T)]
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: generic fn @F(%T.loc8_6.1: <error>) {
  81. // CHECK:STDOUT: %T.loc8_6.2: <error> = bind_symbolic_name T, 0 [symbolic = %T.loc8_6.2 (constants.%T)]
  82. // CHECK:STDOUT: %T.patt.loc8_6.2: <error> = symbolic_binding_pattern T, 0 [symbolic = %T.patt.loc8_6.2 (constants.%T.patt)]
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: fn(%T.param_patt: <error>);
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: specific @F(constants.%T) {
  88. // CHECK:STDOUT: %T.loc8_6.2 => constants.%T
  89. // CHECK:STDOUT: %T.patt.loc8_6.2 => constants.%T
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: --- fail_left_where_unknown.carbon
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: constants {
  95. // CHECK:STDOUT: %.Self: <error> = bind_symbolic_name .Self, 0 [symbolic]
  96. // CHECK:STDOUT: %Bool.type: type = fn_type @Bool [template]
  97. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [template]
  98. // CHECK:STDOUT: %U: <error> = bind_symbolic_name U, 0 [symbolic]
  99. // CHECK:STDOUT: %U.patt: <error> = symbolic_binding_pattern U, 0 [symbolic]
  100. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  101. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT:
  104. // CHECK:STDOUT: imports {
  105. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  106. // CHECK:STDOUT: .Bool = %import_ref
  107. // CHECK:STDOUT: import Core//prelude
  108. // CHECK:STDOUT: import Core//prelude/...
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT:
  112. // CHECK:STDOUT: file {
  113. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  114. // CHECK:STDOUT: .Core = imports.%Core
  115. // CHECK:STDOUT: .G = %G.decl
  116. // CHECK:STDOUT: }
  117. // CHECK:STDOUT: %Core.import = import Core
  118. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  119. // CHECK:STDOUT: %U.patt.loc8_6.1: <error> = symbolic_binding_pattern U, 0 [symbolic = %U.patt.loc8_6.2 (constants.%U.patt)]
  120. // CHECK:STDOUT: %U.param_patt: <error> = value_param_pattern %U.patt.loc8_6.1, runtime_param<invalid> [symbolic = %U.patt.loc8_6.2 (constants.%U.patt)]
  121. // CHECK:STDOUT: } {
  122. // CHECK:STDOUT: %NOT_DECLARED.ref: <error> = name_ref NOT_DECLARED, <error> [template = <error>]
  123. // CHECK:STDOUT: %.Self: <error> = bind_symbolic_name .Self, 0 [symbolic = constants.%.Self]
  124. // CHECK:STDOUT: %.Self.ref: <error> = name_ref .Self, %.Self [symbolic = constants.%.Self]
  125. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  126. // CHECK:STDOUT: %.loc8: type = where_expr %.Self [template = <error>] {
  127. // CHECK:STDOUT: requirement_equivalent %.Self.ref, %bool.make_type
  128. // CHECK:STDOUT: }
  129. // CHECK:STDOUT: %U.param: <error> = value_param runtime_param<invalid>
  130. // CHECK:STDOUT: %U.loc8_6.1: <error> = bind_symbolic_name U, 0, %U.param [symbolic = %U.loc8_6.2 (constants.%U)]
  131. // CHECK:STDOUT: }
  132. // CHECK:STDOUT: }
  133. // CHECK:STDOUT:
  134. // CHECK:STDOUT: generic fn @G(%U.loc8_6.1: <error>) {
  135. // CHECK:STDOUT: %U.loc8_6.2: <error> = bind_symbolic_name U, 0 [symbolic = %U.loc8_6.2 (constants.%U)]
  136. // CHECK:STDOUT: %U.patt.loc8_6.2: <error> = symbolic_binding_pattern U, 0 [symbolic = %U.patt.loc8_6.2 (constants.%U.patt)]
  137. // CHECK:STDOUT:
  138. // CHECK:STDOUT: fn(%U.param_patt: <error>);
  139. // CHECK:STDOUT: }
  140. // CHECK:STDOUT:
  141. // CHECK:STDOUT: specific @G(constants.%U) {
  142. // CHECK:STDOUT: %U.loc8_6.2 => constants.%U
  143. // CHECK:STDOUT: %U.patt.loc8_6.2 => constants.%U
  144. // CHECK:STDOUT: }
  145. // CHECK:STDOUT:
  146. // CHECK:STDOUT: --- fail_var.carbon
  147. // CHECK:STDOUT:
  148. // CHECK:STDOUT: constants {
  149. // CHECK:STDOUT: %.Self: <error> = bind_symbolic_name .Self, 0 [symbolic]
  150. // CHECK:STDOUT: %.1: Core.IntLiteral = int_value 3 [template]
  151. // CHECK:STDOUT: }
  152. // CHECK:STDOUT:
  153. // CHECK:STDOUT: imports {
  154. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  155. // CHECK:STDOUT: import Core//prelude
  156. // CHECK:STDOUT: import Core//prelude/...
  157. // CHECK:STDOUT: }
  158. // CHECK:STDOUT: }
  159. // CHECK:STDOUT:
  160. // CHECK:STDOUT: file {
  161. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  162. // CHECK:STDOUT: .Core = imports.%Core
  163. // CHECK:STDOUT: .v = %v
  164. // CHECK:STDOUT: }
  165. // CHECK:STDOUT: %Core.import = import Core
  166. // CHECK:STDOUT: %e.ref: <error> = name_ref e, <error> [template = <error>]
  167. // CHECK:STDOUT: %.Self: <error> = bind_symbolic_name .Self, 0 [symbolic = constants.%.Self]
  168. // CHECK:STDOUT: %.Self.ref: <error> = name_ref .Self, %.Self [symbolic = constants.%.Self]
  169. // CHECK:STDOUT: %x.ref: <error> = name_ref x, <error> [template = <error>]
  170. // CHECK:STDOUT: %.loc7_21: Core.IntLiteral = int_value 3 [template = constants.%.1]
  171. // CHECK:STDOUT: %.loc7_10: type = where_expr %.Self [template = <error>] {
  172. // CHECK:STDOUT: requirement_rewrite %x.ref, <error>
  173. // CHECK:STDOUT: }
  174. // CHECK:STDOUT: %v.var: ref <error> = var v
  175. // CHECK:STDOUT: %v: ref <error> = bind_name v, %v.var
  176. // CHECK:STDOUT: }
  177. // CHECK:STDOUT: