| 231 | |
| 232 | template <class T> |
| 233 | void ContractLevelChecker::findDuplicateDefinitions(std::map<std::string, std::vector<T>> const& _definitions) |
| 234 | { |
| 235 | for (auto const& it: _definitions) |
| 236 | { |
| 237 | std::vector<T> const& overloads = it.second; |
| 238 | std::set<size_t> reported; |
| 239 | for (size_t i = 0; i < overloads.size() && !reported.count(i); ++i) |
| 240 | { |
| 241 | SecondarySourceLocation ssl; |
| 242 | |
| 243 | for (size_t j = i + 1; j < overloads.size(); ++j) |
| 244 | if (hasEqualExternalCallableParameters(*overloads[i], *overloads[j])) |
| 245 | { |
| 246 | solAssert( |
| 247 | ( |
| 248 | dynamic_cast<ContractDefinition const*>(overloads[i]->scope()) && |
| 249 | dynamic_cast<ContractDefinition const*>(overloads[j]->scope()) && |
| 250 | overloads[i]->name() == overloads[j]->name() |
| 251 | ) || |
| 252 | ( |
| 253 | dynamic_cast<SourceUnit const*>(overloads[i]->scope()) && |
| 254 | dynamic_cast<SourceUnit const*>(overloads[j]->scope()) |
| 255 | ), |
| 256 | "Override is neither a namesake function/event in contract scope nor " |
| 257 | "a free function/event (alias)." |
| 258 | ); |
| 259 | ssl.append("Other declaration is here:", overloads[j]->location()); |
| 260 | reported.insert(j); |
| 261 | } |
| 262 | |
| 263 | if (ssl.infos.size() > 0) |
| 264 | { |
| 265 | ErrorId error; |
| 266 | std::string message; |
| 267 | if constexpr (std::is_same_v<T, FunctionDefinition const*>) |
| 268 | { |
| 269 | error = 1686_error; |
| 270 | message = "Function with same name and parameter types defined twice."; |
| 271 | } |
| 272 | else |
| 273 | { |
| 274 | static_assert(std::is_same_v<T, EventDefinition const*>, "Expected \"FunctionDefinition const*\" or \"EventDefinition const*\""); |
| 275 | error = 5883_error; |
| 276 | message = "Event with same name and parameter types defined twice."; |
| 277 | } |
| 278 | |
| 279 | ssl.limitSize(message); |
| 280 | |
| 281 | m_errorReporter.declarationError( |
| 282 | error, |
| 283 | overloads[i]->location(), |
| 284 | ssl, |
| 285 | message |
| 286 | ); |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | } |
nothing calls this directly
no test coverage detected