template.carbon 5.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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/generic_params/template.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/parse/testdata/generics/generic_params/template.carbon
  10. // --- basic.carbon
  11. fn foo(template a:! i32);
  12. // --- fail_template_ref.carbon
  13. // CHECK:STDERR: fail_template_ref.carbon:[[@LINE+4]]:17: error: expected `:` binding after `ref` [ExpectedRuntimeBindingPatternAfterRef]
  14. // CHECK:STDERR: fn foo(template ref a:! i32);
  15. // CHECK:STDERR: ^~~
  16. // CHECK:STDERR:
  17. fn foo(template ref a:! i32);
  18. // CHECK:STDERR: fail_template_ref.carbon:[[@LINE+4]]:8: error: expected `:!` binding after `template` [ExpectedGenericBindingPatternAfterTemplate]
  19. // CHECK:STDERR: fn foo(template ref a: i32);
  20. // CHECK:STDERR: ^~~~~~~~
  21. // CHECK:STDERR:
  22. fn foo(template ref a: i32);
  23. // CHECK:STDERR: fail_template_ref.carbon:[[@LINE+4]]:12: error: expected name in binding pattern [ExpectedBindingPattern]
  24. // CHECK:STDERR: fn foo(ref template a:! i32);
  25. // CHECK:STDERR: ^~~~~~~~
  26. // CHECK:STDERR:
  27. fn foo(ref template a:! i32);
  28. // CHECK:STDOUT: - filename: basic.carbon
  29. // CHECK:STDOUT: parse_tree: [
  30. // CHECK:STDOUT: {kind: 'FileStart', text: ''},
  31. // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
  32. // CHECK:STDOUT: {kind: 'IdentifierNameBeforeParams', text: 'foo'},
  33. // CHECK:STDOUT: {kind: 'ExplicitParamListStart', text: '('},
  34. // CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'a'},
  35. // CHECK:STDOUT: {kind: 'TemplateBindingName', text: 'template', subtree_size: 2},
  36. // CHECK:STDOUT: {kind: 'CompileTimeBindingPatternStart', text: ':!', subtree_size: 3},
  37. // CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
  38. // CHECK:STDOUT: {kind: 'CompileTimeBindingPattern', text: ':!', subtree_size: 5},
  39. // CHECK:STDOUT: {kind: 'ExplicitParamList', text: ')', subtree_size: 7},
  40. // CHECK:STDOUT: {kind: 'FunctionDecl', text: ';', subtree_size: 10},
  41. // CHECK:STDOUT: {kind: 'FileEnd', text: ''},
  42. // CHECK:STDOUT: ]
  43. // CHECK:STDOUT: - filename: fail_template_ref.carbon
  44. // CHECK:STDOUT: parse_tree: [
  45. // CHECK:STDOUT: {kind: 'FileStart', text: ''},
  46. // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
  47. // CHECK:STDOUT: {kind: 'IdentifierNameBeforeParams', text: 'foo'},
  48. // CHECK:STDOUT: {kind: 'ExplicitParamListStart', text: '('},
  49. // CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'a'},
  50. // CHECK:STDOUT: {kind: 'TemplateBindingName', text: 'template', subtree_size: 2},
  51. // CHECK:STDOUT: {kind: 'RefBindingName', text: 'ref', has_error: yes, subtree_size: 3},
  52. // CHECK:STDOUT: {kind: 'CompileTimeBindingPatternStart', text: ':!', has_error: yes, subtree_size: 4},
  53. // CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
  54. // CHECK:STDOUT: {kind: 'CompileTimeBindingPattern', text: ':!', has_error: yes, subtree_size: 6},
  55. // CHECK:STDOUT: {kind: 'ExplicitParamList', text: ')', has_error: yes, subtree_size: 8},
  56. // CHECK:STDOUT: {kind: 'FunctionDecl', text: ';', subtree_size: 11},
  57. // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
  58. // CHECK:STDOUT: {kind: 'IdentifierNameBeforeParams', text: 'foo'},
  59. // CHECK:STDOUT: {kind: 'ExplicitParamListStart', text: '('},
  60. // CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'a'},
  61. // CHECK:STDOUT: {kind: 'TemplateBindingName', text: 'template', has_error: yes, subtree_size: 2},
  62. // CHECK:STDOUT: {kind: 'RefBindingName', text: 'ref', has_error: yes, subtree_size: 3},
  63. // CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
  64. // CHECK:STDOUT: {kind: 'LetBindingPattern', text: ':', has_error: yes, subtree_size: 5},
  65. // CHECK:STDOUT: {kind: 'ExplicitParamList', text: ')', has_error: yes, subtree_size: 7},
  66. // CHECK:STDOUT: {kind: 'FunctionDecl', text: ';', subtree_size: 10},
  67. // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
  68. // CHECK:STDOUT: {kind: 'IdentifierNameBeforeParams', text: 'foo'},
  69. // CHECK:STDOUT: {kind: 'ExplicitParamListStart', text: '('},
  70. // CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'template', has_error: yes},
  71. // CHECK:STDOUT: {kind: 'InvalidParse', text: 'template', has_error: yes},
  72. // CHECK:STDOUT: {kind: 'LetBindingPattern', text: 'ref', has_error: yes, subtree_size: 3},
  73. // CHECK:STDOUT: {kind: 'ExplicitParamList', text: ')', has_error: yes, subtree_size: 5},
  74. // CHECK:STDOUT: {kind: 'FunctionDecl', text: ';', subtree_size: 8},
  75. // CHECK:STDOUT: {kind: 'FileEnd', text: ''},
  76. // CHECK:STDOUT: ]