Merge pull request #6320 from ethereum/callvalue_nonpayable

Inline Assembly: Issue error for callvalue in nonpayable function
This commit is contained in:
chriseth
2019-03-20 10:07:09 +01:00
committed by GitHub
12 changed files with 84 additions and 6 deletions
@@ -3,4 +3,4 @@ contract C {
function f() costs(1 ether) public view {}
}
// ----
// TypeError: (101-115): This modifier uses "msg.value" and thus the function has to be payable or internal.
// TypeError: (101-115): This modifier uses "msg.value" or "callvalue()" and thus the function has to be payable or internal.
@@ -4,4 +4,4 @@ contract C {
}
}
// ----
// TypeError: (52-61): "msg.value" can only be used in payable public functions. Make the function "payable" or use an internal function to avoid this error.
// TypeError: (52-61): "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.
@@ -0,0 +1,11 @@
contract C
{
function () external {
uint x;
assembly {
x := callvalue()
}
}
}
// ----
// TypeError: (92-103): "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.
@@ -0,0 +1,10 @@
contract C
{
function f(uint x) public {
assembly {
x := callvalue()
}
}
}
// ----
// TypeError: (81-92): "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.
@@ -0,0 +1,11 @@
contract C
{
function f() internal returns (uint x) {
assembly {
x := callvalue()
}
}
function g() public returns (uint) {
return f();
}
}
@@ -0,0 +1,14 @@
contract C
{
modifier m {
uint x;
assembly {
x := callvalue()
}
_;
}
function f() m public {
}
}
// ----
// TypeError: (99-100): This modifier uses "msg.value" or "callvalue()" and thus the function has to be payable or internal.
@@ -0,0 +1,9 @@
contract C
{
function () external payable {
uint x;
assembly {
x := callvalue()
}
}
}
@@ -0,0 +1,8 @@
contract C
{
function f(uint x) public payable {
assembly {
x := callvalue()
}
}
}
@@ -0,0 +1,12 @@
contract C
{
modifier m {
uint x;
assembly {
x := callvalue()
}
_;
}
function f() m public payable {
}
}
@@ -3,4 +3,4 @@ contract C {
function f() m(1 ether, msg.value) public view {}
}
// ----
// TypeError: (118-127): "msg.value" can only be used in payable public functions. Make the function "payable" or use an internal function to avoid this error.
// TypeError: (118-127): "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.