mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-30 22:02:41 +01:00
Don't use VarDecl replacements on range for loops. (#604)
This commit is contained in:
@@ -14,7 +14,11 @@ namespace Carbon {
|
||||
VarDecl::VarDecl(std::map<std::string, Replacements>& in_replacements,
|
||||
cam::MatchFinder* finder)
|
||||
: Matcher(in_replacements) {
|
||||
finder->addMatcher(cam::varDecl().bind(Label), this);
|
||||
// Skip range-based for loops in this var-inserter.
|
||||
finder->addMatcher(cam::varDecl(cam::unless(cam::hasParent(cam::declStmt(
|
||||
cam::hasParent(cam::cxxForRangeStmt())))))
|
||||
.bind(Label),
|
||||
this);
|
||||
}
|
||||
|
||||
// Returns a string for the type.
|
||||
|
||||
@@ -129,7 +129,8 @@ TEST_F(VarDeclTest, ParamsConst) {
|
||||
}
|
||||
|
||||
TEST_F(VarDeclTest, ParamStruct) {
|
||||
// This is to ensure the 'struct' keyword doesn't get added to the call type.
|
||||
// This is to ensure the 'struct' keyword doesn't get added to the qualified
|
||||
// type.
|
||||
constexpr char Before[] = R"cpp(
|
||||
struct Circle {};
|
||||
auto Draw(int times, const Circle& circle) -> bool;
|
||||
@@ -155,20 +156,20 @@ TEST_F(VarDeclTest, Member) {
|
||||
ExpectReplacement(Before, Before);
|
||||
}
|
||||
|
||||
TEST_F(VarDeclTest, DISABLED_RangeFor) {
|
||||
// TODO: Handle range based for loops. Test shouldn't be enabled without
|
||||
// addressing this because the output is quirky and fragile.
|
||||
TEST_F(VarDeclTest, RangeFor) {
|
||||
constexpr char Before[] = R"cpp(
|
||||
void Foo() {
|
||||
int items[] = {1};
|
||||
for (int i : items) {
|
||||
int j;
|
||||
}
|
||||
}
|
||||
)cpp";
|
||||
constexpr char After[] = R"(
|
||||
void Foo() {
|
||||
var items: int[] = {1};
|
||||
var items: int [1];
|
||||
for (int i : items) {
|
||||
var j: int;
|
||||
}
|
||||
}
|
||||
)";
|
||||
|
||||
Reference in New Issue
Block a user