fail_impl.carbon 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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/parse/testdata/generics/impl/fail_impl.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/parse/testdata/generics/impl/fail_impl.carbon
  10. // CHECK:STDERR: fail_impl.carbon:[[@LINE+4]]:10: error: expected `as` in `impl` declaration [ImplExpectedAs]
  11. // CHECK:STDERR: impl foo bar;
  12. // CHECK:STDERR: ^~~
  13. // CHECK:STDERR:
  14. impl foo bar;
  15. // CHECK:STDERR: fail_impl.carbon:[[@LINE+4]]:12: error: expected expression [ExpectedExpr]
  16. // CHECK:STDERR: impl i32 as;
  17. // CHECK:STDERR: ^
  18. // CHECK:STDERR:
  19. impl i32 as;
  20. // CHECK:STDERR: fail_impl.carbon:[[@LINE+4]]:18: error: `impl` declarations must either end with a `;` or have a `{ ... }` block for a definition [ExpectedDeclSemiOrDefinition]
  21. // CHECK:STDERR: impl bool as bar unexpected;
  22. // CHECK:STDERR: ^~~~~~~~~~
  23. // CHECK:STDERR:
  24. impl bool as bar unexpected;
  25. // CHECK:STDERR: fail_impl.carbon:[[@LINE+4]]:6: error: expected expression [ExpectedExpr]
  26. // CHECK:STDERR: impl return as A;
  27. // CHECK:STDERR: ^~~~~~
  28. // CHECK:STDERR:
  29. impl return as A;
  30. // CHECK:STDERR: fail_impl.carbon:[[@LINE+4]]:6: error: expected expression [ExpectedExpr]
  31. // CHECK:STDERR: impl return B;
  32. // CHECK:STDERR: ^~~~~~
  33. // CHECK:STDERR:
  34. impl return B;
  35. // CHECK:STDERR: fail_impl.carbon:[[@LINE+8]]:13: error: expected `[` after `forall` in `impl` declaration [ImplExpectedAfterForall]
  36. // CHECK:STDERR: impl forall f32;
  37. // CHECK:STDERR: ^~~
  38. // CHECK:STDERR:
  39. // CHECK:STDERR: fail_impl.carbon:[[@LINE+4]]:16: error: expected `as` in `impl` declaration [ImplExpectedAs]
  40. // CHECK:STDERR: impl forall f32;
  41. // CHECK:STDERR: ^
  42. // CHECK:STDERR:
  43. impl forall f32;
  44. // CHECK:STDERR: fail_impl.carbon:[[@LINE+4]]:19: error: expected `as` in `impl` declaration [ImplExpectedAs]
  45. // CHECK:STDERR: impl forall [] u32;
  46. // CHECK:STDERR: ^
  47. // CHECK:STDERR:
  48. impl forall [] u32;
  49. // CHECK:STDERR: fail_impl.carbon:[[@LINE+4]]:25: error: expected `as` in `impl` declaration [ImplExpectedAs]
  50. // CHECK:STDERR: impl forall [invalid] i8;
  51. // CHECK:STDERR: ^
  52. // CHECK:STDERR:
  53. impl forall [invalid] i8;
  54. // CHECK:STDERR: fail_impl.carbon:[[@LINE+4]]:13: error: expected `[` after `forall` in `impl` declaration [ImplExpectedAfterForall]
  55. // CHECK:STDERR: impl forall f16 as Quux;
  56. // CHECK:STDERR: ^~~
  57. // CHECK:STDERR:
  58. impl forall f16 as Quux;
  59. // CHECK:STDERR: fail_impl.carbon:[[@LINE+4]]:27: error: expected `as` in `impl` declaration [ImplExpectedAs]
  60. // CHECK:STDERR: impl forall [T:! type] str;
  61. // CHECK:STDERR: ^
  62. // CHECK:STDERR:
  63. impl forall [T:! type] str;
  64. // CHECK:STDERR: fail_impl.carbon:[[@LINE+4]]:26: error: expected `as` in `impl` declaration [ImplExpectedAs]
  65. // CHECK:STDERR: impl forall [T:! type] T missing_as;
  66. // CHECK:STDERR: ^~~~~~~~~~
  67. // CHECK:STDERR:
  68. impl forall [T:! type] T missing_as;
  69. // CHECK:STDERR: fail_impl.carbon:[[@LINE+4]]:39: error: `impl` declarations must either end with a `;` or have a `{ ... }` block for a definition [ExpectedDeclSemiOrDefinition]
  70. // CHECK:STDERR: impl forall [T:! type] T as Interface extra;
  71. // CHECK:STDERR: ^~~~~
  72. // CHECK:STDERR:
  73. impl forall [T:! type] T as Interface extra;
  74. // CHECK:STDERR: fail_impl.carbon:[[@LINE+4]]:5: error: expected expression [ExpectedExpr]
  75. // CHECK:STDERR: impl;
  76. // CHECK:STDERR: ^
  77. // CHECK:STDERR:
  78. impl;
  79. impl
  80. // CHECK:STDERR: fail_impl.carbon:[[@LINE+90]]:21: error: expected expression [ExpectedExpr]
  81. // CHECK:STDERR: // CHECK:STDOUT: ]
  82. // CHECK:STDERR: ^
  83. // CHECK:STDERR:
  84. // CHECK:STDOUT: - filename: fail_impl.carbon
  85. // CHECK:STDOUT: parse_tree: [
  86. // CHECK:STDOUT: {kind: 'FileStart', text: ''},
  87. // CHECK:STDOUT: {kind: 'ImplIntroducer', text: 'impl'},
  88. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'foo'},
  89. // CHECK:STDOUT: {kind: 'ImplDecl', text: ';', has_error: yes, subtree_size: 3},
  90. // CHECK:STDOUT: {kind: 'ImplIntroducer', text: 'impl'},
  91. // CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
  92. // CHECK:STDOUT: {kind: 'ImplTypeAs', text: 'as', subtree_size: 2},
  93. // CHECK:STDOUT: {kind: 'InvalidParse', text: ';', has_error: yes},
  94. // CHECK:STDOUT: {kind: 'ImplDecl', text: ';', has_error: yes, subtree_size: 5},
  95. // CHECK:STDOUT: {kind: 'ImplIntroducer', text: 'impl'},
  96. // CHECK:STDOUT: {kind: 'BoolTypeLiteral', text: 'bool'},
  97. // CHECK:STDOUT: {kind: 'ImplTypeAs', text: 'as', subtree_size: 2},
  98. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'bar'},
  99. // CHECK:STDOUT: {kind: 'ImplDecl', text: ';', has_error: yes, subtree_size: 5},
  100. // CHECK:STDOUT: {kind: 'ImplIntroducer', text: 'impl'},
  101. // CHECK:STDOUT: {kind: 'InvalidParse', text: 'return', has_error: yes},
  102. // CHECK:STDOUT: {kind: 'ImplDecl', text: ';', has_error: yes, subtree_size: 3},
  103. // CHECK:STDOUT: {kind: 'ImplIntroducer', text: 'impl'},
  104. // CHECK:STDOUT: {kind: 'InvalidParse', text: 'return', has_error: yes},
  105. // CHECK:STDOUT: {kind: 'ImplDecl', text: ';', has_error: yes, subtree_size: 3},
  106. // CHECK:STDOUT: {kind: 'ImplIntroducer', text: 'impl'},
  107. // CHECK:STDOUT: {kind: 'Forall', text: 'forall'},
  108. // CHECK:STDOUT: {kind: 'InvalidParse', text: 'f32', has_error: yes},
  109. // CHECK:STDOUT: {kind: 'FloatTypeLiteral', text: 'f32'},
  110. // CHECK:STDOUT: {kind: 'ImplDecl', text: ';', has_error: yes, subtree_size: 5},
  111. // CHECK:STDOUT: {kind: 'ImplIntroducer', text: 'impl'},
  112. // CHECK:STDOUT: {kind: 'Forall', text: 'forall'},
  113. // CHECK:STDOUT: {kind: 'ImplicitParamListStart', text: '['},
  114. // CHECK:STDOUT: {kind: 'ImplicitParamList', text: ']', subtree_size: 2},
  115. // CHECK:STDOUT: {kind: 'UnsignedIntTypeLiteral', text: 'u32'},
  116. // CHECK:STDOUT: {kind: 'ImplDecl', text: ';', has_error: yes, subtree_size: 6},
  117. // CHECK:STDOUT: {kind: 'ImplIntroducer', text: 'impl'},
  118. // CHECK:STDOUT: {kind: 'Forall', text: 'forall'},
  119. // CHECK:STDOUT: {kind: 'ImplicitParamListStart', text: '['},
  120. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'invalid'},
  121. // CHECK:STDOUT: {kind: 'ImplicitParamList', text: ']', subtree_size: 3},
  122. // CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i8'},
  123. // CHECK:STDOUT: {kind: 'ImplDecl', text: ';', has_error: yes, subtree_size: 7},
  124. // CHECK:STDOUT: {kind: 'ImplIntroducer', text: 'impl'},
  125. // CHECK:STDOUT: {kind: 'Forall', text: 'forall'},
  126. // CHECK:STDOUT: {kind: 'InvalidParse', text: 'f16', has_error: yes},
  127. // CHECK:STDOUT: {kind: 'FloatTypeLiteral', text: 'f16'},
  128. // CHECK:STDOUT: {kind: 'ImplTypeAs', text: 'as', subtree_size: 2},
  129. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'Quux'},
  130. // CHECK:STDOUT: {kind: 'ImplDecl', text: ';', has_error: yes, subtree_size: 7},
  131. // CHECK:STDOUT: {kind: 'ImplIntroducer', text: 'impl'},
  132. // CHECK:STDOUT: {kind: 'Forall', text: 'forall'},
  133. // CHECK:STDOUT: {kind: 'ImplicitParamListStart', text: '['},
  134. // CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeSignature', text: 'T'},
  135. // CHECK:STDOUT: {kind: 'CompileTimeBindingPatternStart', text: ':!', subtree_size: 2},
  136. // CHECK:STDOUT: {kind: 'TypeTypeLiteral', text: 'type'},
  137. // CHECK:STDOUT: {kind: 'CompileTimeBindingPattern', text: ':!', subtree_size: 4},
  138. // CHECK:STDOUT: {kind: 'ImplicitParamList', text: ']', subtree_size: 6},
  139. // CHECK:STDOUT: {kind: 'StringTypeLiteral', text: 'str'},
  140. // CHECK:STDOUT: {kind: 'ImplDecl', text: ';', has_error: yes, subtree_size: 10},
  141. // CHECK:STDOUT: {kind: 'ImplIntroducer', text: 'impl'},
  142. // CHECK:STDOUT: {kind: 'Forall', text: 'forall'},
  143. // CHECK:STDOUT: {kind: 'ImplicitParamListStart', text: '['},
  144. // CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeSignature', text: 'T'},
  145. // CHECK:STDOUT: {kind: 'CompileTimeBindingPatternStart', text: ':!', subtree_size: 2},
  146. // CHECK:STDOUT: {kind: 'TypeTypeLiteral', text: 'type'},
  147. // CHECK:STDOUT: {kind: 'CompileTimeBindingPattern', text: ':!', subtree_size: 4},
  148. // CHECK:STDOUT: {kind: 'ImplicitParamList', text: ']', subtree_size: 6},
  149. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'T'},
  150. // CHECK:STDOUT: {kind: 'ImplDecl', text: ';', has_error: yes, subtree_size: 10},
  151. // CHECK:STDOUT: {kind: 'ImplIntroducer', text: 'impl'},
  152. // CHECK:STDOUT: {kind: 'Forall', text: 'forall'},
  153. // CHECK:STDOUT: {kind: 'ImplicitParamListStart', text: '['},
  154. // CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeSignature', text: 'T'},
  155. // CHECK:STDOUT: {kind: 'CompileTimeBindingPatternStart', text: ':!', subtree_size: 2},
  156. // CHECK:STDOUT: {kind: 'TypeTypeLiteral', text: 'type'},
  157. // CHECK:STDOUT: {kind: 'CompileTimeBindingPattern', text: ':!', subtree_size: 4},
  158. // CHECK:STDOUT: {kind: 'ImplicitParamList', text: ']', subtree_size: 6},
  159. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'T'},
  160. // CHECK:STDOUT: {kind: 'ImplTypeAs', text: 'as', subtree_size: 2},
  161. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'Interface'},
  162. // CHECK:STDOUT: {kind: 'ImplDecl', text: ';', has_error: yes, subtree_size: 12},
  163. // CHECK:STDOUT: {kind: 'ImplIntroducer', text: 'impl'},
  164. // CHECK:STDOUT: {kind: 'InvalidParse', text: ';', has_error: yes},
  165. // CHECK:STDOUT: {kind: 'ImplDecl', text: ';', has_error: yes, subtree_size: 3},
  166. // CHECK:STDOUT: {kind: 'ImplIntroducer', text: 'impl'},
  167. // CHECK:STDOUT: {kind: 'InvalidParse', text: '', has_error: yes},
  168. // CHECK:STDOUT: {kind: 'ImplDecl', text: 'impl', has_error: yes, subtree_size: 3},
  169. // CHECK:STDOUT: {kind: 'FileEnd', text: ''},
  170. // CHECK:STDOUT: ]