| 4130 | } |
| 4131 | |
| 4132 | static const Token *findShadowed(const Scope *scope, const Variable& var, int linenr) |
| 4133 | { |
| 4134 | if (!scope) |
| 4135 | return nullptr; |
| 4136 | for (const Variable &v : scope->varlist) { |
| 4137 | if (scope->isExecutable() && v.nameToken()->linenr() > linenr) |
| 4138 | continue; |
| 4139 | if (v.name() == var.name()) |
| 4140 | return v.nameToken(); |
| 4141 | } |
| 4142 | auto it = std::find_if(scope->functionList.cbegin(), scope->functionList.cend(), [&](const Function& f) { |
| 4143 | return f.type == FunctionType::eFunction && f.name() == var.name() && precedes(f.tokenDef, var.nameToken()); |
| 4144 | }); |
| 4145 | if (it != scope->functionList.end()) |
| 4146 | return it->tokenDef; |
| 4147 | |
| 4148 | if (scope->type == ScopeType::eLambda) |
| 4149 | return nullptr; |
| 4150 | const Token* shadowed = findShadowed(scope->nestedIn, var, linenr); |
| 4151 | if (!shadowed) |
| 4152 | shadowed = findShadowed(scope->functionOf, var, linenr); |
| 4153 | return shadowed; |
| 4154 | } |
| 4155 | |
| 4156 | void CheckOtherImpl::checkShadowVariables() |
| 4157 | { |
no test coverage detected