fail_out_of_line_member.carbon 4.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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_out_of_line_member.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_out_of_line_member.carbon
  10. // TODO: Decide if we want to support this syntax. See #3763.
  11. interface Interface {
  12. fn F();
  13. }
  14. impl bool as Interface {
  15. fn F();
  16. }
  17. // CHECK:STDERR: fail_out_of_line_member.carbon:[[@LINE+4]]:4: error: `fn` introducer should be followed by a name [ExpectedDeclName]
  18. // CHECK:STDERR: fn (bool as Interface).F() {}
  19. // CHECK:STDERR: ^
  20. // CHECK:STDERR:
  21. fn (bool as Interface).F() {}
  22. class C {
  23. impl Self as Interface {
  24. fn F();
  25. }
  26. }
  27. // CHECK:STDERR: fail_out_of_line_member.carbon:[[@LINE+4]]:6: error: `.` should be followed by a name [ExpectedDeclNameAfterPeriod]
  28. // CHECK:STDERR: fn C.(Self as Interface).F() {}
  29. // CHECK:STDERR: ^
  30. // CHECK:STDERR:
  31. fn C.(Self as Interface).F() {}
  32. // CHECK:STDOUT: - filename: fail_out_of_line_member.carbon
  33. // CHECK:STDOUT: parse_tree: [
  34. // CHECK:STDOUT: {kind: 'FileStart', text: ''},
  35. // CHECK:STDOUT: {kind: 'InterfaceIntroducer', text: 'interface'},
  36. // CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'Interface'},
  37. // CHECK:STDOUT: {kind: 'InterfaceDefinitionStart', text: '{', subtree_size: 3},
  38. // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
  39. // CHECK:STDOUT: {kind: 'IdentifierNameBeforeParams', text: 'F'},
  40. // CHECK:STDOUT: {kind: 'ExplicitParamListStart', text: '('},
  41. // CHECK:STDOUT: {kind: 'ExplicitParamList', text: ')', subtree_size: 2},
  42. // CHECK:STDOUT: {kind: 'FunctionDecl', text: ';', subtree_size: 5},
  43. // CHECK:STDOUT: {kind: 'InterfaceDefinition', text: '}', subtree_size: 9},
  44. // CHECK:STDOUT: {kind: 'ImplIntroducer', text: 'impl'},
  45. // CHECK:STDOUT: {kind: 'BoolTypeLiteral', text: 'bool'},
  46. // CHECK:STDOUT: {kind: 'ImplTypeAs', text: 'as', subtree_size: 2},
  47. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'Interface'},
  48. // CHECK:STDOUT: {kind: 'ImplDefinitionStart', text: '{', subtree_size: 5},
  49. // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
  50. // CHECK:STDOUT: {kind: 'IdentifierNameBeforeParams', text: 'F'},
  51. // CHECK:STDOUT: {kind: 'ExplicitParamListStart', text: '('},
  52. // CHECK:STDOUT: {kind: 'ExplicitParamList', text: ')', subtree_size: 2},
  53. // CHECK:STDOUT: {kind: 'FunctionDecl', text: ';', subtree_size: 5},
  54. // CHECK:STDOUT: {kind: 'ImplDefinition', text: '}', subtree_size: 11},
  55. // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
  56. // CHECK:STDOUT: {kind: 'InvalidParse', text: '(', has_error: yes},
  57. // CHECK:STDOUT: {kind: 'FunctionDecl', text: '}', has_error: yes, subtree_size: 3},
  58. // CHECK:STDOUT: {kind: 'ClassIntroducer', text: 'class'},
  59. // CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'C'},
  60. // CHECK:STDOUT: {kind: 'ClassDefinitionStart', text: '{', subtree_size: 3},
  61. // CHECK:STDOUT: {kind: 'ImplIntroducer', text: 'impl'},
  62. // CHECK:STDOUT: {kind: 'SelfTypeNameExpr', text: 'Self'},
  63. // CHECK:STDOUT: {kind: 'ImplTypeAs', text: 'as', subtree_size: 2},
  64. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'Interface'},
  65. // CHECK:STDOUT: {kind: 'ImplDefinitionStart', text: '{', subtree_size: 5},
  66. // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
  67. // CHECK:STDOUT: {kind: 'IdentifierNameBeforeParams', text: 'F'},
  68. // CHECK:STDOUT: {kind: 'ExplicitParamListStart', text: '('},
  69. // CHECK:STDOUT: {kind: 'ExplicitParamList', text: ')', subtree_size: 2},
  70. // CHECK:STDOUT: {kind: 'FunctionDecl', text: ';', subtree_size: 5},
  71. // CHECK:STDOUT: {kind: 'ImplDefinition', text: '}', subtree_size: 11},
  72. // CHECK:STDOUT: {kind: 'ClassDefinition', text: '}', subtree_size: 15},
  73. // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
  74. // CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'C'},
  75. // CHECK:STDOUT: {kind: 'IdentifierNameQualifierWithoutParams', text: '.', subtree_size: 2},
  76. // CHECK:STDOUT: {kind: 'InvalidParse', text: '(', has_error: yes},
  77. // CHECK:STDOUT: {kind: 'FunctionDecl', text: '}', has_error: yes, subtree_size: 5},
  78. // CHECK:STDOUT: {kind: 'FileEnd', text: ''},
  79. // CHECK:STDOUT: ]