Index: lib/ASTMatchers/Dynamic/Parser.cpp =================================================================== --- lib/ASTMatchers/Dynamic/Parser.cpp +++ lib/ASTMatchers/Dynamic/Parser.cpp @@ -339,8 +339,28 @@ if (const VariantValue NamedValue = NamedValues ? NamedValues->lookup(NameToken.Text) : VariantValue()) { - *Value = NamedValue; - return true; + + if (Tokenizer->nextTokenKind() != TokenInfo::TK_Period) { + *Value = NamedValue; + return true; + } + + std::string BindID; + TokenInfo EndToken; + if (!parseBindID(BindID, EndToken)) + return false; + + assert(NamedValue.isMatcher()); + llvm::Optional Result = + NamedValue.getMatcher().getSingleMatcher(); + if (Result.hasValue()) { + llvm::Optional Bound = Result->tryBind(BindID); + if (Bound.hasValue()) { + *Value = VariantMatcher::SingleMatcher(*Bound); + return true; + } + } + return false; } // If the syntax is correct and the name is not a matcher either, report // unknown named value. Index: unittests/ASTMatchers/Dynamic/ParserTest.cpp =================================================================== --- unittests/ASTMatchers/Dynamic/ParserTest.cpp +++ unittests/ASTMatchers/Dynamic/ParserTest.cpp @@ -359,6 +359,44 @@ Comps[2].MatcherDecl); } +TEST(ParserTest, ParseBindOnLet) { + + auto NamedValues = getTestNamedValues(); + + Diagnostics Error; + + { + llvm::Optional topLevelLetBinding( + Parser::parseMatcherExpression("hasParamA.bind(\"parmABinding\")", + nullptr, &NamedValues, &Error)); + EXPECT_EQ("", Error.toStringFull()); + auto M = topLevelLetBinding->unconditionalConvertTo(); + + EXPECT_TRUE(matchAndVerifyResultTrue( + "void foo(int a);", M, + llvm::make_unique>("parmABinding"))); + EXPECT_TRUE(matchAndVerifyResultFalse( + "void foo(int b);", M, + llvm::make_unique>("parmABinding"))); + } + + { + llvm::Optional nestedLetBinding( + Parser::parseMatcherExpression( + "functionDecl(hasParamA.bind(\"parmABinding\"))", nullptr, + &NamedValues, &Error)); + EXPECT_EQ("", Error.toStringFull()); + auto M = nestedLetBinding->unconditionalConvertTo(); + + EXPECT_TRUE(matchAndVerifyResultTrue( + "void foo(int a);", M, + llvm::make_unique>("parmABinding"))); + EXPECT_TRUE(matchAndVerifyResultFalse( + "void foo(int b);", M, + llvm::make_unique>("parmABinding"))); + } +} + } // end anonymous namespace } // end namespace dynamic } // end namespace ast_matchers