fail_not_facet.carbon 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  6. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  7. //
  8. // AUTOUPDATE
  9. // TIP: To test this file alone, run:
  10. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/where_expr/fail_not_facet.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/where_expr/fail_not_facet.carbon
  13. // --- fail_left_where_not_facet.carbon
  14. library "[[@TEST_NAME]]";
  15. // CHECK:STDERR: fail_left_where_not_facet.carbon:[[@LINE+4]]:10: error: left argument of `where` operator must be a facet type [WhereOnNonFacetType]
  16. // CHECK:STDERR: fn F(T:! i32 where .Self == bool);
  17. // CHECK:STDERR: ^~~
  18. // CHECK:STDERR:
  19. fn F(T:! i32 where .Self == bool);
  20. // --- fail_left_where_unknown.carbon
  21. library "[[@TEST_NAME]]";
  22. // CHECK:STDERR: fail_left_where_unknown.carbon:[[@LINE+4]]:10: error: name `NOT_DECLARED` not found [NameNotFound]
  23. // CHECK:STDERR: fn G(U:! NOT_DECLARED where .Self == bool);
  24. // CHECK:STDERR: ^~~~~~~~~~~~
  25. // CHECK:STDERR:
  26. fn G(U:! NOT_DECLARED where .Self == bool);
  27. // --- fail_var.carbon
  28. library "[[@TEST_NAME]]";
  29. // CHECK:STDERR: fail_var.carbon:[[@LINE+4]]:8: error: name `e` not found [NameNotFound]
  30. // CHECK:STDERR: var v: e where .x = 3;
  31. // CHECK:STDERR: ^
  32. // CHECK:STDERR:
  33. var v: e where .x = 3;
  34. // CHECK:STDOUT: --- fail_left_where_not_facet.carbon
  35. // CHECK:STDOUT:
  36. // CHECK:STDOUT: constants {
  37. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  38. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  39. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  40. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  41. // CHECK:STDOUT: %Bool.type: type = fn_type @Bool [concrete]
  42. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [concrete]
  43. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  44. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT:
  47. // CHECK:STDOUT: imports {
  48. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  49. // CHECK:STDOUT: .Int = %Core.Int
  50. // CHECK:STDOUT: .Bool = %Core.Bool
  51. // CHECK:STDOUT: import Core//prelude
  52. // CHECK:STDOUT: import Core//prelude/...
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/types/int, Int, loaded [concrete = constants.%Int.generic]
  55. // CHECK:STDOUT: %Core.Bool: %Bool.type = import_ref Core//prelude/types/bool, Bool, loaded [concrete = constants.%Bool]
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: file {
  59. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  60. // CHECK:STDOUT: .Core = imports.%Core
  61. // CHECK:STDOUT: .F = %F.decl
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT: %Core.import = import Core
  64. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  65. // CHECK:STDOUT: %T.patt: <error> = symbolic_binding_pattern T, 0 [concrete]
  66. // CHECK:STDOUT: } {
  67. // CHECK:STDOUT: %.loc8_14.1: type = splice_block %.loc8_14.2 [concrete = <error>] {
  68. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  69. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  70. // CHECK:STDOUT: %.Self: <error> = bind_symbolic_name .Self [concrete = <error>]
  71. // CHECK:STDOUT: %.Self.ref: <error> = name_ref .Self, %.Self [concrete = <error>]
  72. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [concrete = bool]
  73. // CHECK:STDOUT: %.loc8_14.2: type = where_expr %.Self [concrete = <error>] {
  74. // CHECK:STDOUT: requirement_equivalent %.Self.ref, %bool.make_type
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT: %T: <error> = bind_symbolic_name T, 0 [concrete = <error>]
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: generic fn @F(%T: <error>) {
  82. // CHECK:STDOUT: fn();
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: specific @F(<error>) {}
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: --- fail_left_where_unknown.carbon
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: constants {
  90. // CHECK:STDOUT: %Bool.type: type = fn_type @Bool [concrete]
  91. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [concrete]
  92. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  93. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT:
  96. // CHECK:STDOUT: imports {
  97. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  98. // CHECK:STDOUT: .Bool = %Core.Bool
  99. // CHECK:STDOUT: import Core//prelude
  100. // CHECK:STDOUT: import Core//prelude/...
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT: %Core.Bool: %Bool.type = import_ref Core//prelude/types/bool, Bool, loaded [concrete = constants.%Bool]
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT:
  105. // CHECK:STDOUT: file {
  106. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  107. // CHECK:STDOUT: .Core = imports.%Core
  108. // CHECK:STDOUT: .NOT_DECLARED = <poisoned>
  109. // CHECK:STDOUT: .G = %G.decl
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT: %Core.import = import Core
  112. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {
  113. // CHECK:STDOUT: %U.patt: <error> = symbolic_binding_pattern U, 0 [concrete]
  114. // CHECK:STDOUT: } {
  115. // CHECK:STDOUT: %.loc8_23.1: type = splice_block %.loc8_23.2 [concrete = <error>] {
  116. // CHECK:STDOUT: %NOT_DECLARED.ref: <error> = name_ref NOT_DECLARED, <error> [concrete = <error>]
  117. // CHECK:STDOUT: %.Self: <error> = bind_symbolic_name .Self [concrete = <error>]
  118. // CHECK:STDOUT: %.Self.ref: <error> = name_ref .Self, %.Self [concrete = <error>]
  119. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [concrete = bool]
  120. // CHECK:STDOUT: %.loc8_23.2: type = where_expr %.Self [concrete = <error>] {
  121. // CHECK:STDOUT: requirement_equivalent %.Self.ref, %bool.make_type
  122. // CHECK:STDOUT: }
  123. // CHECK:STDOUT: }
  124. // CHECK:STDOUT: %U: <error> = bind_symbolic_name U, 0 [concrete = <error>]
  125. // CHECK:STDOUT: }
  126. // CHECK:STDOUT: }
  127. // CHECK:STDOUT:
  128. // CHECK:STDOUT: generic fn @G(%U: <error>) {
  129. // CHECK:STDOUT: fn();
  130. // CHECK:STDOUT: }
  131. // CHECK:STDOUT:
  132. // CHECK:STDOUT: specific @G(<error>) {}
  133. // CHECK:STDOUT:
  134. // CHECK:STDOUT: --- fail_var.carbon
  135. // CHECK:STDOUT:
  136. // CHECK:STDOUT: constants {
  137. // CHECK:STDOUT: %int_3: Core.IntLiteral = int_value 3 [concrete]
  138. // CHECK:STDOUT: }
  139. // CHECK:STDOUT:
  140. // CHECK:STDOUT: imports {
  141. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  142. // CHECK:STDOUT: import Core//prelude
  143. // CHECK:STDOUT: import Core//prelude/...
  144. // CHECK:STDOUT: }
  145. // CHECK:STDOUT: }
  146. // CHECK:STDOUT:
  147. // CHECK:STDOUT: file {
  148. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  149. // CHECK:STDOUT: .Core = imports.%Core
  150. // CHECK:STDOUT: .e = <poisoned>
  151. // CHECK:STDOUT: .v = %v
  152. // CHECK:STDOUT: }
  153. // CHECK:STDOUT: %Core.import = import Core
  154. // CHECK:STDOUT: name_binding_decl {
  155. // CHECK:STDOUT: %v.patt: <error> = binding_pattern v [concrete]
  156. // CHECK:STDOUT: %v.var_patt: <error> = var_pattern %v.patt [concrete]
  157. // CHECK:STDOUT: }
  158. // CHECK:STDOUT: %v.var: ref <error> = var %v.var_patt [concrete = <error>]
  159. // CHECK:STDOUT: %.loc8_10.1: type = splice_block %.loc8_10.2 [concrete = <error>] {
  160. // CHECK:STDOUT: %e.ref: <error> = name_ref e, <error> [concrete = <error>]
  161. // CHECK:STDOUT: %.Self: <error> = bind_symbolic_name .Self [concrete = <error>]
  162. // CHECK:STDOUT: %.Self.ref: <error> = name_ref .Self, %.Self [concrete = <error>]
  163. // CHECK:STDOUT: %x.ref: <error> = name_ref x, <error> [concrete = <error>]
  164. // CHECK:STDOUT: %int_3: Core.IntLiteral = int_value 3 [concrete = constants.%int_3]
  165. // CHECK:STDOUT: %.loc8_10.2: type = where_expr %.Self [concrete = <error>] {
  166. // CHECK:STDOUT: requirement_rewrite %x.ref, <error>
  167. // CHECK:STDOUT: }
  168. // CHECK:STDOUT: }
  169. // CHECK:STDOUT: %v: <error> = bind_name v, <error> [concrete = <error>]
  170. // CHECK:STDOUT: }
  171. // CHECK:STDOUT: