generic.carbon 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/named_constraint/generic.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/named_constraint/generic.carbon
  12. // --- generic.carbon
  13. library "[[@TEST_NAME]]";
  14. //@include-in-dumps
  15. constraint GenericType(T:! type) {}
  16. interface Z {}
  17. constraint GenericZ(U:! Z) {}
  18. constraint ForwardDeclaredGeneric(T:! type);
  19. constraint ForwardDeclaredGeneric(T:! type) {}
  20. // --- fail_mismatched_generic_param_types.carbon
  21. library "[[@TEST_NAME]]";
  22. constraint ForwardDeclaredGeneric(T:! ());
  23. // CHECK:STDERR: fail_mismatched_generic_param_types.carbon:[[@LINE+7]]:35: error: type `<pattern for type>` of parameter 1 in redeclaration differs from previous parameter type `<pattern for ()>` [RedeclParamDiffersType]
  24. // CHECK:STDERR: constraint ForwardDeclaredGeneric(T:! type) {}
  25. // CHECK:STDERR: ^
  26. // CHECK:STDERR: fail_mismatched_generic_param_types.carbon:[[@LINE-4]]:35: note: previous declaration's corresponding parameter here [RedeclParamPrevious]
  27. // CHECK:STDERR: constraint ForwardDeclaredGeneric(T:! ());
  28. // CHECK:STDERR: ^
  29. // CHECK:STDERR:
  30. constraint ForwardDeclaredGeneric(T:! type) {}
  31. // --- fail_mismatched_generic_param_arity.carbon
  32. library "[[@TEST_NAME]]";
  33. constraint ForwardDeclaredGeneric(T:! type, U:! type);
  34. // CHECK:STDERR: fail_mismatched_generic_param_arity.carbon:[[@LINE+7]]:1: error: redeclaration differs because of parameter count of 1 [RedeclParamCountDiffers]
  35. // CHECK:STDERR: constraint ForwardDeclaredGeneric(T:! type) {}
  36. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  37. // CHECK:STDERR: fail_mismatched_generic_param_arity.carbon:[[@LINE-4]]:1: note: previously declared with parameter count of 2 [RedeclParamCountPrevious]
  38. // CHECK:STDERR: constraint ForwardDeclaredGeneric(T:! type, U:! type);
  39. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  40. // CHECK:STDERR:
  41. constraint ForwardDeclaredGeneric(T:! type) {}
  42. // --- fail_inside_definition.carbon
  43. library "[[@TEST_NAME]]";
  44. constraint Generic(T:! type) {}
  45. // CHECK:STDERR: fail_inside_definition.carbon:[[@LINE+7]]:1: error: redefinition of `constraint Generic` [RedeclRedef]
  46. // CHECK:STDERR: constraint Generic(T:! type) {}
  47. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  48. // CHECK:STDERR: fail_inside_definition.carbon:[[@LINE-4]]:1: note: previously defined here [RedeclPrevDef]
  49. // CHECK:STDERR: constraint Generic(T:! type) {}
  50. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  51. // CHECK:STDERR:
  52. constraint Generic(T:! type) {}
  53. // CHECK:STDOUT: --- generic.carbon
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: constants {
  56. // CHECK:STDOUT: %type: type = facet_type <type> [concrete]
  57. // CHECK:STDOUT: %.Self: %type = bind_symbolic_name .Self [symbolic_self]
  58. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
  59. // CHECK:STDOUT: %pattern_type.98f: type = pattern_type type [concrete]
  60. // CHECK:STDOUT: %GenericType.type: type = generic_named_constaint_type @GenericType [concrete]
  61. // CHECK:STDOUT: %empty_struct.bd5: %GenericType.type = struct_value () [concrete]
  62. // CHECK:STDOUT: %Self.eca39f.1: %type = bind_symbolic_name Self, 1 [symbolic]
  63. // CHECK:STDOUT: %Z.type: type = facet_type <@Z> [concrete]
  64. // CHECK:STDOUT: %Self.1d7: %Z.type = bind_symbolic_name Self, 0 [symbolic]
  65. // CHECK:STDOUT: %U: %Z.type = bind_symbolic_name U, 0 [symbolic]
  66. // CHECK:STDOUT: %pattern_type.4a0: type = pattern_type %Z.type [concrete]
  67. // CHECK:STDOUT: %GenericZ.type: type = generic_named_constaint_type @GenericZ [concrete]
  68. // CHECK:STDOUT: %empty_struct.05e: %GenericZ.type = struct_value () [concrete]
  69. // CHECK:STDOUT: %Self.eca39f.2: %type = bind_symbolic_name Self, 1 [symbolic]
  70. // CHECK:STDOUT: %ForwardDeclaredGeneric.type: type = generic_named_constaint_type @ForwardDeclaredGeneric [concrete]
  71. // CHECK:STDOUT: %empty_struct.1a7: %ForwardDeclaredGeneric.type = struct_value () [concrete]
  72. // CHECK:STDOUT: %Self.eca39f.3: %type = bind_symbolic_name Self, 1 [symbolic]
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: file {
  76. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  77. // CHECK:STDOUT: .GenericType = %GenericType.decl
  78. // CHECK:STDOUT: .Z = %Z.decl
  79. // CHECK:STDOUT: .GenericZ = %GenericZ.decl
  80. // CHECK:STDOUT: .ForwardDeclaredGeneric = %ForwardDeclaredGeneric.decl.loc9
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT: %GenericType.decl: %GenericType.type = constraint_decl @GenericType [concrete = constants.%empty_struct.bd5] {
  83. // CHECK:STDOUT: %T.patt: %pattern_type.98f = symbolic_binding_pattern T, 0 [concrete]
  84. // CHECK:STDOUT: } {
  85. // CHECK:STDOUT: %.Self: %type = bind_symbolic_name .Self [symbolic_self = constants.%.Self]
  86. // CHECK:STDOUT: %T.loc4_24.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc4_24.1 (constants.%T)]
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT: %Z.decl: type = interface_decl @Z [concrete = constants.%Z.type] {} {}
  89. // CHECK:STDOUT: %GenericZ.decl: %GenericZ.type = constraint_decl @GenericZ [concrete = constants.%empty_struct.05e] {
  90. // CHECK:STDOUT: %U.patt: %pattern_type.4a0 = symbolic_binding_pattern U, 0 [concrete]
  91. // CHECK:STDOUT: } {
  92. // CHECK:STDOUT: %.loc7: type = splice_block %Z.ref [concrete = constants.%Z.type] {
  93. // CHECK:STDOUT: %.Self: %type = bind_symbolic_name .Self [symbolic_self = constants.%.Self]
  94. // CHECK:STDOUT: %Z.ref: type = name_ref Z, file.%Z.decl [concrete = constants.%Z.type]
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT: %U.loc7_21.2: %Z.type = bind_symbolic_name U, 0 [symbolic = %U.loc7_21.1 (constants.%U)]
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT: %ForwardDeclaredGeneric.decl.loc9: %ForwardDeclaredGeneric.type = constraint_decl @ForwardDeclaredGeneric [concrete = constants.%empty_struct.1a7] {
  99. // CHECK:STDOUT: %T.patt: %pattern_type.98f = symbolic_binding_pattern T, 0 [concrete]
  100. // CHECK:STDOUT: } {
  101. // CHECK:STDOUT: %.Self.2: %type = bind_symbolic_name .Self [symbolic_self = constants.%.Self]
  102. // CHECK:STDOUT: %T.loc9_35.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc9_35.1 (constants.%T)]
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT: %ForwardDeclaredGeneric.decl.loc10: %ForwardDeclaredGeneric.type = constraint_decl @ForwardDeclaredGeneric [concrete = constants.%empty_struct.1a7] {
  105. // CHECK:STDOUT: %T.patt: %pattern_type.98f = symbolic_binding_pattern T, 0 [concrete]
  106. // CHECK:STDOUT: } {
  107. // CHECK:STDOUT: %.Self.1: %type = bind_symbolic_name .Self [symbolic_self = constants.%.Self]
  108. // CHECK:STDOUT: %T.loc10: type = bind_symbolic_name T, 0 [symbolic = %T.loc9_35.1 (constants.%T)]
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT:
  112. // CHECK:STDOUT: interface @Z {
  113. // CHECK:STDOUT: %Self: %Z.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self.1d7]
  114. // CHECK:STDOUT:
  115. // CHECK:STDOUT: !members:
  116. // CHECK:STDOUT: .Self = %Self
  117. // CHECK:STDOUT: witness = ()
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT:
  120. // CHECK:STDOUT: generic constraint @GenericType(%T.loc4_24.2: type) {
  121. // CHECK:STDOUT: %T.loc4_24.1: type = bind_symbolic_name T, 0 [symbolic = %T.loc4_24.1 (constants.%T)]
  122. // CHECK:STDOUT:
  123. // CHECK:STDOUT: !definition:
  124. // CHECK:STDOUT: %Self.2: %type = bind_symbolic_name Self, 1 [symbolic = %Self.2 (constants.%Self.eca39f.1)]
  125. // CHECK:STDOUT:
  126. // CHECK:STDOUT: constraint {
  127. // CHECK:STDOUT: %Self.1: %type = bind_symbolic_name Self, 1 [symbolic = %Self.2 (constants.%Self.eca39f.1)]
  128. // CHECK:STDOUT:
  129. // CHECK:STDOUT: !members:
  130. // CHECK:STDOUT: .Self = %Self.1
  131. // CHECK:STDOUT: }
  132. // CHECK:STDOUT: }
  133. // CHECK:STDOUT:
  134. // CHECK:STDOUT: generic constraint @GenericZ(%U.loc7_21.2: %Z.type) {
  135. // CHECK:STDOUT: %U.loc7_21.1: %Z.type = bind_symbolic_name U, 0 [symbolic = %U.loc7_21.1 (constants.%U)]
  136. // CHECK:STDOUT:
  137. // CHECK:STDOUT: !definition:
  138. // CHECK:STDOUT: %Self.2: %type = bind_symbolic_name Self, 1 [symbolic = %Self.2 (constants.%Self.eca39f.2)]
  139. // CHECK:STDOUT:
  140. // CHECK:STDOUT: constraint {
  141. // CHECK:STDOUT: %Self.1: %type = bind_symbolic_name Self, 1 [symbolic = %Self.2 (constants.%Self.eca39f.2)]
  142. // CHECK:STDOUT:
  143. // CHECK:STDOUT: !members:
  144. // CHECK:STDOUT: .Self = %Self.1
  145. // CHECK:STDOUT: }
  146. // CHECK:STDOUT: }
  147. // CHECK:STDOUT:
  148. // CHECK:STDOUT: generic constraint @ForwardDeclaredGeneric(%T.loc9_35.2: type) {
  149. // CHECK:STDOUT: %T.loc9_35.1: type = bind_symbolic_name T, 0 [symbolic = %T.loc9_35.1 (constants.%T)]
  150. // CHECK:STDOUT:
  151. // CHECK:STDOUT: !definition:
  152. // CHECK:STDOUT: %Self.2: %type = bind_symbolic_name Self, 1 [symbolic = %Self.2 (constants.%Self.eca39f.3)]
  153. // CHECK:STDOUT:
  154. // CHECK:STDOUT: constraint {
  155. // CHECK:STDOUT: %Self.1: %type = bind_symbolic_name Self, 1 [symbolic = %Self.2 (constants.%Self.eca39f.3)]
  156. // CHECK:STDOUT:
  157. // CHECK:STDOUT: !members:
  158. // CHECK:STDOUT: .Self = %Self.1
  159. // CHECK:STDOUT: }
  160. // CHECK:STDOUT: }
  161. // CHECK:STDOUT:
  162. // CHECK:STDOUT: specific @GenericType(constants.%T) {
  163. // CHECK:STDOUT: %T.loc4_24.1 => constants.%T
  164. // CHECK:STDOUT: }
  165. // CHECK:STDOUT:
  166. // CHECK:STDOUT: specific @GenericZ(constants.%U) {
  167. // CHECK:STDOUT: %U.loc7_21.1 => constants.%U
  168. // CHECK:STDOUT: }
  169. // CHECK:STDOUT:
  170. // CHECK:STDOUT: specific @ForwardDeclaredGeneric(constants.%T) {
  171. // CHECK:STDOUT: %T.loc9_35.1 => constants.%T
  172. // CHECK:STDOUT: }
  173. // CHECK:STDOUT: