match.carbon 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. fn f() -> i32 {
  7. var x: i32 = 3;
  8. match (f(x)) {
  9. case (a: i32, b: i32) => { return 0; }
  10. case (a: i32) if (a < 0) => { return 2; }
  11. case a: i32 if (a != x) => { return 3; }
  12. default => { return 4; }
  13. }
  14. return 0;
  15. }
  16. // CHECK:STDOUT: - filename: match.carbon
  17. // CHECK:STDOUT: parse_tree: [
  18. // CHECK:STDOUT: {kind: 'FileStart', text: ''},
  19. // CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
  20. // CHECK:STDOUT: {kind: 'IdentifierName', text: 'f'},
  21. // CHECK:STDOUT: {kind: 'TuplePatternStart', text: '('},
  22. // CHECK:STDOUT: {kind: 'TuplePattern', text: ')', subtree_size: 2},
  23. // CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
  24. // CHECK:STDOUT: {kind: 'ReturnType', text: '->', subtree_size: 2},
  25. // CHECK:STDOUT: {kind: 'FunctionDefinitionStart', text: '{', subtree_size: 7},
  26. // CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'},
  27. // CHECK:STDOUT: {kind: 'IdentifierName', text: 'x'},
  28. // CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
  29. // CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 3},
  30. // CHECK:STDOUT: {kind: 'VariableInitializer', text: '='},
  31. // CHECK:STDOUT: {kind: 'IntLiteral', text: '3'},
  32. // CHECK:STDOUT: {kind: 'VariableDecl', text: ';', subtree_size: 7},
  33. // CHECK:STDOUT: {kind: 'MatchIntroducer', text: 'match'},
  34. // CHECK:STDOUT: {kind: 'MatchConditionStart', text: '('},
  35. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'f'},
  36. // CHECK:STDOUT: {kind: 'CallExprStart', text: '(', subtree_size: 2},
  37. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'x'},
  38. // CHECK:STDOUT: {kind: 'CallExpr', text: ')', subtree_size: 4},
  39. // CHECK:STDOUT: {kind: 'MatchCondition', text: ')', subtree_size: 6},
  40. // CHECK:STDOUT: {kind: 'MatchStatementStart', text: '{', subtree_size: 8},
  41. // CHECK:STDOUT: {kind: 'MatchCaseIntroducer', text: 'case'},
  42. // CHECK:STDOUT: {kind: 'TuplePatternStart', text: '('},
  43. // CHECK:STDOUT: {kind: 'IdentifierName', text: 'a'},
  44. // CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
  45. // CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 3},
  46. // CHECK:STDOUT: {kind: 'PatternListComma', text: ','},
  47. // CHECK:STDOUT: {kind: 'IdentifierName', text: 'b'},
  48. // CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
  49. // CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 3},
  50. // CHECK:STDOUT: {kind: 'TuplePattern', text: ')', subtree_size: 9},
  51. // CHECK:STDOUT: {kind: 'MatchCaseEqualGreater', text: '=>'},
  52. // CHECK:STDOUT: {kind: 'MatchCaseStart', text: '{', subtree_size: 12},
  53. // CHECK:STDOUT: {kind: 'ReturnStatementStart', text: 'return'},
  54. // CHECK:STDOUT: {kind: 'IntLiteral', text: '0'},
  55. // CHECK:STDOUT: {kind: 'ReturnStatement', text: ';', subtree_size: 3},
  56. // CHECK:STDOUT: {kind: 'MatchCase', text: '}', subtree_size: 16},
  57. // CHECK:STDOUT: {kind: 'MatchCaseIntroducer', text: 'case'},
  58. // CHECK:STDOUT: {kind: 'TuplePatternStart', text: '('},
  59. // CHECK:STDOUT: {kind: 'IdentifierName', text: 'a'},
  60. // CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
  61. // CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 3},
  62. // CHECK:STDOUT: {kind: 'TuplePattern', text: ')', subtree_size: 5},
  63. // CHECK:STDOUT: {kind: 'MatchCaseGuardIntroducer', text: 'if'},
  64. // CHECK:STDOUT: {kind: 'MatchCaseGuardStart', text: '('},
  65. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'a'},
  66. // CHECK:STDOUT: {kind: 'IntLiteral', text: '0'},
  67. // CHECK:STDOUT: {kind: 'InfixOperatorLess', text: '<', subtree_size: 3},
  68. // CHECK:STDOUT: {kind: 'MatchCaseGuard', text: ')', subtree_size: 6},
  69. // CHECK:STDOUT: {kind: 'MatchCaseEqualGreater', text: '=>'},
  70. // CHECK:STDOUT: {kind: 'MatchCaseStart', text: '{', subtree_size: 14},
  71. // CHECK:STDOUT: {kind: 'ReturnStatementStart', text: 'return'},
  72. // CHECK:STDOUT: {kind: 'IntLiteral', text: '2'},
  73. // CHECK:STDOUT: {kind: 'ReturnStatement', text: ';', subtree_size: 3},
  74. // CHECK:STDOUT: {kind: 'MatchCase', text: '}', subtree_size: 18},
  75. // CHECK:STDOUT: {kind: 'MatchCaseIntroducer', text: 'case'},
  76. // CHECK:STDOUT: {kind: 'IdentifierName', text: 'a'},
  77. // CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
  78. // CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 3},
  79. // CHECK:STDOUT: {kind: 'MatchCaseGuardIntroducer', text: 'if'},
  80. // CHECK:STDOUT: {kind: 'MatchCaseGuardStart', text: '('},
  81. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'a'},
  82. // CHECK:STDOUT: {kind: 'IdentifierNameExpr', text: 'x'},
  83. // CHECK:STDOUT: {kind: 'InfixOperatorExclaimEqual', text: '!=', subtree_size: 3},
  84. // CHECK:STDOUT: {kind: 'MatchCaseGuard', text: ')', subtree_size: 6},
  85. // CHECK:STDOUT: {kind: 'MatchCaseEqualGreater', text: '=>'},
  86. // CHECK:STDOUT: {kind: 'MatchCaseStart', text: '{', subtree_size: 12},
  87. // CHECK:STDOUT: {kind: 'ReturnStatementStart', text: 'return'},
  88. // CHECK:STDOUT: {kind: 'IntLiteral', text: '3'},
  89. // CHECK:STDOUT: {kind: 'ReturnStatement', text: ';', subtree_size: 3},
  90. // CHECK:STDOUT: {kind: 'MatchCase', text: '}', subtree_size: 16},
  91. // CHECK:STDOUT: {kind: 'MatchDefaultIntroducer', text: 'default'},
  92. // CHECK:STDOUT: {kind: 'MatchDefaultEqualGreater', text: '=>'},
  93. // CHECK:STDOUT: {kind: 'MatchDefaultStart', text: '{', subtree_size: 3},
  94. // CHECK:STDOUT: {kind: 'ReturnStatementStart', text: 'return'},
  95. // CHECK:STDOUT: {kind: 'IntLiteral', text: '4'},
  96. // CHECK:STDOUT: {kind: 'ReturnStatement', text: ';', subtree_size: 3},
  97. // CHECK:STDOUT: {kind: 'MatchDefault', text: '}', subtree_size: 7},
  98. // CHECK:STDOUT: {kind: 'MatchStatement', text: '}', subtree_size: 66},
  99. // CHECK:STDOUT: {kind: 'ReturnStatementStart', text: 'return'},
  100. // CHECK:STDOUT: {kind: 'IntLiteral', text: '0'},
  101. // CHECK:STDOUT: {kind: 'ReturnStatement', text: ';', subtree_size: 3},
  102. // CHECK:STDOUT: {kind: 'FunctionDefinition', text: '}', subtree_size: 84},
  103. // CHECK:STDOUT: {kind: 'FileEnd', text: ''},
  104. // CHECK:STDOUT: ]