ViewPureChecker::reportMutability: don't check visibility on constructors.

This commit is contained in:
Alexander Arlt
2020-09-07 11:35:33 -05:00
parent 2b29f4e56d
commit df8bbeeb22
4 changed files with 23 additions and 5 deletions
+7 -4
View File
@@ -261,21 +261,24 @@ void ViewPureChecker::reportMutability(
{
// We do not warn for library functions because they cannot be payable anyway.
// Also internal functions should be allowed to use `msg.value`.
if (m_currentFunction->isPublic() && !m_currentFunction->libraryFunction())
if ((m_currentFunction->isConstructor() || m_currentFunction->isPublic()) && !m_currentFunction->libraryFunction())
{
if (_nestedLocation)
m_errorReporter.typeError(
4006_error,
_location,
SecondarySourceLocation().append("\"msg.value\" or \"callvalue()\" appear here inside the modifier.", *_nestedLocation),
"This modifier uses \"msg.value\" or \"callvalue()\" and thus the function has to be payable or internal."
m_currentFunction->isConstructor() ?
"This modifier uses \"msg.value\" or \"callvalue()\" and thus the constructor has to be payable."
: "This modifier uses \"msg.value\" or \"callvalue()\" and thus the function has to be payable or internal."
);
else
m_errorReporter.typeError(
5887_error,
_location,
"\"msg.value\" and \"callvalue()\" can only be used in payable public functions. Make the function "
"\"payable\" or use an internal function to avoid this error."
m_currentFunction->isConstructor() ?
"\"msg.value\" and \"callvalue()\" can only be used in payable constructors. Make the constructor \"payable\" to avoid this error."
: "\"msg.value\" and \"callvalue()\" can only be used in payable public functions. Make the function \"payable\" or use an internal function to avoid this error."
);
m_errors = true;
}