Fix `$mask` variable mutation in `GetDependencies` inner loop (#2247)