MCPcopy Create free account
hub / github.com/argotorg/solidity / findDuplicateDefinitions

Method findDuplicateDefinitions

libsolidity/analysis/ContractLevelChecker.cpp:233–290  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

231
232template <class T>
233void 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}

Callers

nothing calls this directly

Calls 10

scopeMethod · 0.80
insertMethod · 0.80
limitSizeMethod · 0.80
declarationErrorMethod · 0.80
sizeMethod · 0.45
countMethod · 0.45
nameMethod · 0.45
appendMethod · 0.45
locationMethod · 0.45

Tested by

no test coverage detected