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

Method typeCheckConstructor

libsolidity/analysis/TypeChecker.cpp:2045–2084  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2043}
2044
2045void 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
2086void TypeChecker::typeCheckABIEncodeFunctions(
2087 FunctionCall const& _functionCall,

Callers

nothing calls this directly

Calls 14

stateMutabilityToStringFunction · 0.85
isConstructorMethod · 0.80
overridesMethod · 0.80
typeErrorMethod · 0.80
noVisibilitySpecifiedMethod · 0.80
scopeMethod · 0.80
isPublicMethod · 0.80
abstractMethod · 0.80
declarationErrorMethod · 0.80
locationMethod · 0.45
emptyMethod · 0.45
stateMutabilityMethod · 0.45

Tested by

no test coverage detected