| 2043 | } |
| 2044 | |
| 2045 | void TypeChecker::typeCheckConstructor(FunctionDefinition const& _function) |
| 2046 | { |
| 2047 | solAssert(_function.isConstructor(), ""); |
| 2048 | if (_function.overrides()) |
| 2049 | m_errorReporter.typeError(1209_error, _function.location(), "Constructors cannot override."); |
| 2050 | if (!_function.returnParameters().empty()) |
| 2051 | m_errorReporter.typeError(9712_error, _function.returnParameterList()->location(), "Non-empty \"returns\" directive for constructor."); |
| 2052 | if (_function.stateMutability() != StateMutability::NonPayable && _function.stateMutability() != StateMutability::Payable) |
| 2053 | m_errorReporter.typeError( |
| 2054 | 1558_error, |
| 2055 | _function.location(), |
| 2056 | "Constructor must be payable or non-payable, but is \"" + |
| 2057 | stateMutabilityToString(_function.stateMutability()) + |
| 2058 | "\"." |
| 2059 | ); |
| 2060 | if (!_function.noVisibilitySpecified()) |
| 2061 | { |
| 2062 | auto const& contract = dynamic_cast<ContractDefinition const&>(*_function.scope()); |
| 2063 | if (_function.visibility() != Visibility::Public && _function.visibility() != Visibility::Internal) |
| 2064 | m_errorReporter.typeError(9239_error, _function.location(), "Constructor cannot have visibility."); |
| 2065 | else if (_function.isPublic() && contract.abstract()) |
| 2066 | m_errorReporter.declarationError( |
| 2067 | 8295_error, |
| 2068 | _function.location(), |
| 2069 | "Abstract contracts cannot have public constructors. Remove the \"public\" keyword to fix this." |
| 2070 | ); |
| 2071 | else if (!_function.isPublic() && !contract.abstract()) |
| 2072 | m_errorReporter.declarationError( |
| 2073 | 1845_error, |
| 2074 | _function.location(), |
| 2075 | "Non-abstract contracts cannot have internal constructors. Remove the \"internal\" keyword and make the contract abstract to fix this." |
| 2076 | ); |
| 2077 | else |
| 2078 | m_errorReporter.warning( |
| 2079 | 2462_error, |
| 2080 | _function.location(), |
| 2081 | "Visibility for constructor is ignored. If you want the contract to be non-deployable, making it \"abstract\" is sufficient." |
| 2082 | ); |
| 2083 | } |
| 2084 | } |
| 2085 | |
| 2086 | void TypeChecker::typeCheckABIEncodeFunctions( |
| 2087 | FunctionCall const& _functionCall, |
nothing calls this directly
no test coverage detected