fail_missing_var.carbon 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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/for/fail_missing_var.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/parse/testdata/for/fail_missing_var.carbon
  10. fn foo() {
  11. // CHECK:STDERR: fail_missing_var.carbon:[[@LINE+4]]:8: error: expected `var` declaration [ExpectedVariableDecl]
  12. // CHECK:STDERR: for (x: i32 in y) {
  13. // CHECK:STDERR: ^
  14. // CHECK:STDERR:
  15. for (x: i32 in y) {
  16. Print(x);
  17. }
  18. }
  19. // CHECK:STDOUT: - filename: fail_missing_var.carbon
  20. // CHECK:STDOUT: parse_tree: [
  21. // CHECK:STDOUT: {kind: 'FileStart', text: ''},
  22. // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
  23. // CHECK:STDOUT: {kind: 'IdentifierNameBeforeParams', text: 'foo'},
  24. // CHECK:STDOUT: {kind: 'TuplePatternStart', text: '('},
  25. // CHECK:STDOUT: {kind: 'TuplePattern', text: ')', subtree_size: 2},
  26. // CHECK:STDOUT: {kind: 'FunctionDefinitionStart', text: '{', subtree_size: 5},
  27. // CHECK:STDOUT: {kind: 'ForHeaderStart', text: '('},
  28. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'y'},
  29. // CHECK:STDOUT: {kind: 'ForHeader', text: ')', has_error: yes, subtree_size: 3},
  30. // CHECK:STDOUT: {kind: 'CodeBlockStart', text: '{'},
  31. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'Print'},
  32. // CHECK:STDOUT: {kind: 'CallExprStart', text: '(', subtree_size: 2},
  33. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'x'},
  34. // CHECK:STDOUT: {kind: 'CallExpr', text: ')', subtree_size: 4},
  35. // CHECK:STDOUT: {kind: 'ExprStatement', text: ';', subtree_size: 5},
  36. // CHECK:STDOUT: {kind: 'CodeBlock', text: '}', subtree_size: 7},
  37. // CHECK:STDOUT: {kind: 'ForStatement', text: 'for', subtree_size: 11},
  38. // CHECK:STDOUT: {kind: 'FunctionDefinition', text: '}', subtree_size: 17},
  39. // CHECK:STDOUT: {kind: 'FileEnd', text: ''},
  40. // CHECK:STDOUT: ]