mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Use state mutability in fallback/constructor check
This commit is contained in:
parent
93be0dd923
commit
a2aaa47ee2
@ -84,8 +84,13 @@ bool TypeChecker::visit(ContractDefinition const& _contract)
|
|||||||
{
|
{
|
||||||
if (!function->returnParameters().empty())
|
if (!function->returnParameters().empty())
|
||||||
m_errorReporter.typeError(function->returnParameterList()->location(), "Non-empty \"returns\" directive for constructor.");
|
m_errorReporter.typeError(function->returnParameterList()->location(), "Non-empty \"returns\" directive for constructor.");
|
||||||
if (function->isDeclaredConst())
|
if (function->stateMutability() != StateMutability::NonPayable && function->stateMutability() != StateMutability::Payable)
|
||||||
m_errorReporter.typeError(function->location(), "Constructor cannot be defined as constant.");
|
m_errorReporter.typeError(
|
||||||
|
function->location(),
|
||||||
|
"Constructor must be payable or non-payable, but is \"" +
|
||||||
|
stateMutabilityToString(function->stateMutability()) +
|
||||||
|
"\"."
|
||||||
|
);
|
||||||
if (function->visibility() != FunctionDefinition::Visibility::Public && function->visibility() != FunctionDefinition::Visibility::Internal)
|
if (function->visibility() != FunctionDefinition::Visibility::Public && function->visibility() != FunctionDefinition::Visibility::Internal)
|
||||||
m_errorReporter.typeError(function->location(), "Constructor must be public or internal.");
|
m_errorReporter.typeError(function->location(), "Constructor must be public or internal.");
|
||||||
}
|
}
|
||||||
@ -104,8 +109,13 @@ bool TypeChecker::visit(ContractDefinition const& _contract)
|
|||||||
fallbackFunction = function;
|
fallbackFunction = function;
|
||||||
if (_contract.isLibrary())
|
if (_contract.isLibrary())
|
||||||
m_errorReporter.typeError(fallbackFunction->location(), "Libraries cannot have fallback functions.");
|
m_errorReporter.typeError(fallbackFunction->location(), "Libraries cannot have fallback functions.");
|
||||||
if (fallbackFunction->isDeclaredConst())
|
if (function->stateMutability() != StateMutability::NonPayable && function->stateMutability() != StateMutability::Payable)
|
||||||
m_errorReporter.typeError(fallbackFunction->location(), "Fallback function cannot be declared constant.");
|
m_errorReporter.typeError(
|
||||||
|
function->location(),
|
||||||
|
"Fallback function must be payable or non-payable, but is \"" +
|
||||||
|
stateMutabilityToString(function->stateMutability()) +
|
||||||
|
"\"."
|
||||||
|
);
|
||||||
if (!fallbackFunction->parameters().empty())
|
if (!fallbackFunction->parameters().empty())
|
||||||
m_errorReporter.typeError(fallbackFunction->parameterList().location(), "Fallback function cannot take parameters.");
|
m_errorReporter.typeError(fallbackFunction->parameterList().location(), "Fallback function cannot take parameters.");
|
||||||
if (!fallbackFunction->returnParameters().empty())
|
if (!fallbackFunction->returnParameters().empty())
|
||||||
|
@ -1363,7 +1363,7 @@ BOOST_AUTO_TEST_CASE(fallback_function_with_constant_modifier)
|
|||||||
function() constant { x = 2; }
|
function() constant { x = 2; }
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
CHECK_ERROR(text, TypeError, "Fallback function cannot be declared constant.");
|
CHECK_ERROR(text, TypeError, "Fallback function must be payable or non-payable");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(fallback_function_twice)
|
BOOST_AUTO_TEST_CASE(fallback_function_twice)
|
||||||
@ -4873,7 +4873,7 @@ BOOST_AUTO_TEST_CASE(constant_constructor)
|
|||||||
function test() constant {}
|
function test() constant {}
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
CHECK_ERROR(text, TypeError, "Constructor cannot be defined as constant.");
|
CHECK_ERROR(text, TypeError, "Constructor must be payable or non-payable");
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(external_constructor)
|
BOOST_AUTO_TEST_CASE(external_constructor)
|
||||||
|
Loading…
Reference in New Issue
Block a user