diff --git a/src/tint/transform/unshadow.cc b/src/tint/transform/unshadow.cc index 3ec5f3053e..7c9f75cced 100644 --- a/src/tint/transform/unshadow.cc +++ b/src/tint/transform/unshadow.cc @@ -81,19 +81,29 @@ struct Unshadow::State { }); }; - ctx.ReplaceAll([&](const ast::Variable* v) -> const ast::Variable* { - if (auto* local = sem.Get(v)) { - if (local->Shadows()) { - return rename(local); - } - } - if (auto* param = sem.Get(v)) { - if (param->Shadows()) { - return rename(param); - } - } - return nullptr; - }); + bool made_changes = false; + + for (auto* node : ctx.src->SemNodes().Objects()) { + Switch( + node, // + [&](const sem::LocalVariable* local) { + if (local->Shadows()) { + ctx.Replace(local->Declaration(), [&, local] { return rename(local); }); + made_changes = true; + } + }, + [&](const sem::Parameter* param) { + if (param->Shadows()) { + ctx.Replace(param->Declaration(), [&, param] { return rename(param); }); + made_changes = true; + } + }); + } + + if (!made_changes) { + return SkipTransform; + } + ctx.ReplaceAll( [&](const ast::IdentifierExpression* ident) -> const tint::ast::IdentifierExpression* { if (auto* sem_ident = sem.Get(ident)) { diff --git a/src/tint/transform/unshadow_test.cc b/src/tint/transform/unshadow_test.cc index f9e976b361..d2ee8a5c4e 100644 --- a/src/tint/transform/unshadow_test.cc +++ b/src/tint/transform/unshadow_test.cc @@ -23,11 +23,8 @@ using UnshadowTest = TransformTest; TEST_F(UnshadowTest, EmptyModule) { auto* src = ""; - auto* expect = ""; - auto got = Run(src); - - EXPECT_EQ(expect, str(got)); + EXPECT_FALSE(ShouldRun(src)); } TEST_F(UnshadowTest, Noop) { @@ -48,11 +45,7 @@ fn F(c : i32) { } )"; - auto* expect = src; - - auto got = Run(src); - - EXPECT_EQ(expect, str(got)); + EXPECT_FALSE(ShouldRun(src)); } TEST_F(UnshadowTest, LocalShadowsAlias) {