| 138 | } |
| 139 | } |
| 140 | void ContractLevelChecker::checkDuplicateFunctions(ContractDefinition const& _contract) |
| 141 | { |
| 142 | /// Checks that two functions with the same name defined in this contract have different |
| 143 | /// argument types and that there is at most one constructor. |
| 144 | std::map<std::string, std::vector<FunctionDefinition const*>> functions; |
| 145 | FunctionDefinition const* constructor = nullptr; |
| 146 | FunctionDefinition const* fallback = nullptr; |
| 147 | FunctionDefinition const* receive = nullptr; |
| 148 | for (FunctionDefinition const* function: _contract.definedFunctions()) |
| 149 | if (function->isConstructor()) |
| 150 | { |
| 151 | if (constructor) |
| 152 | m_errorReporter.declarationError( |
| 153 | 7997_error, |
| 154 | function->location(), |
| 155 | SecondarySourceLocation().append("Another declaration is here:", constructor->location()), |
| 156 | "More than one constructor defined." |
| 157 | ); |
| 158 | constructor = function; |
| 159 | } |
| 160 | else if (function->isFallback()) |
| 161 | { |
| 162 | if (fallback) |
| 163 | m_errorReporter.declarationError( |
| 164 | 7301_error, |
| 165 | function->location(), |
| 166 | SecondarySourceLocation().append("Another declaration is here:", fallback->location()), |
| 167 | "Only one fallback function is allowed." |
| 168 | ); |
| 169 | fallback = function; |
| 170 | } |
| 171 | else if (function->isReceive()) |
| 172 | { |
| 173 | if (receive) |
| 174 | m_errorReporter.declarationError( |
| 175 | 4046_error, |
| 176 | function->location(), |
| 177 | SecondarySourceLocation().append("Another declaration is here:", receive->location()), |
| 178 | "Only one receive function is allowed." |
| 179 | ); |
| 180 | receive = function; |
| 181 | } |
| 182 | else |
| 183 | { |
| 184 | solAssert(!function->name().empty(), ""); |
| 185 | functions[function->name()].push_back(function); |
| 186 | } |
| 187 | |
| 188 | findDuplicateDefinitions(functions); |
| 189 | } |
| 190 | |
| 191 | void ContractLevelChecker::checkDuplicateEvents(ContractDefinition const& _contract) |
| 192 | { |
nothing calls this directly
no test coverage detected