mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #9740 from ethereum/issue_9629
ViewPureChecker::reportMutability: don't check visibility on constructors.
This commit is contained in:
commit
38e6f2723d
@ -9,7 +9,7 @@ Compiler Features:
|
|||||||
|
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
* Type Checker: Disallow ``virtual`` for modifiers in libraries.
|
* Type Checker: Disallow ``virtual`` for modifiers in libraries.
|
||||||
|
* ViewPureChecker: Prevent visibility check on constructors.
|
||||||
|
|
||||||
### 0.7.1 (2020-09-02)
|
### 0.7.1 (2020-09-02)
|
||||||
|
|
||||||
|
@ -261,21 +261,24 @@ void ViewPureChecker::reportMutability(
|
|||||||
{
|
{
|
||||||
// We do not warn for library functions because they cannot be payable anyway.
|
// We do not warn for library functions because they cannot be payable anyway.
|
||||||
// Also internal functions should be allowed to use `msg.value`.
|
// 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)
|
if (_nestedLocation)
|
||||||
m_errorReporter.typeError(
|
m_errorReporter.typeError(
|
||||||
4006_error,
|
4006_error,
|
||||||
_location,
|
_location,
|
||||||
SecondarySourceLocation().append("\"msg.value\" or \"callvalue()\" appear here inside the modifier.", *_nestedLocation),
|
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
|
else
|
||||||
m_errorReporter.typeError(
|
m_errorReporter.typeError(
|
||||||
5887_error,
|
5887_error,
|
||||||
_location,
|
_location,
|
||||||
"\"msg.value\" and \"callvalue()\" can only be used in payable public functions. Make the function "
|
m_currentFunction->isConstructor() ?
|
||||||
"\"payable\" or use an internal function to avoid this error."
|
"\"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;
|
m_errors = true;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
contract C {
|
||||||
|
uint256 value;
|
||||||
|
constructor() {
|
||||||
|
value = msg.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError 5887: (68-77): "msg.value" and "callvalue()" can only be used in payable constructors. Make the constructor "payable" to avoid this error.
|
@ -0,0 +1,7 @@
|
|||||||
|
contract C {
|
||||||
|
function get() public view returns(uint256) {
|
||||||
|
return msg.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError 5887: (78-87): "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.
|
Loading…
Reference in New Issue
Block a user