mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #4555 from ethereum/asm-syntax-tests
Add more comprehensive tests for embedded inline assembly LValue/RValue access
This commit is contained in:
commit
afccf15f03
@ -0,0 +1,9 @@
|
|||||||
|
contract C {
|
||||||
|
function f() public pure {
|
||||||
|
assembly {
|
||||||
|
let x := C
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError: (72-73): Expected a library.
|
@ -0,0 +1,7 @@
|
|||||||
|
contract C {
|
||||||
|
function f() public pure {
|
||||||
|
assembly {
|
||||||
|
let x := f
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
library L {
|
||||||
|
}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function f() public pure {
|
||||||
|
assembly {
|
||||||
|
let x := L
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
contract C {
|
||||||
|
function f() public pure {
|
||||||
|
assembly {
|
||||||
|
let x := super
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// DeclarationError: (72-77): Identifier not found.
|
@ -0,0 +1,13 @@
|
|||||||
|
contract C {
|
||||||
|
function f() public {
|
||||||
|
assembly {
|
||||||
|
super := 1
|
||||||
|
f := 1
|
||||||
|
C := 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError: (58-63): Only local variables can be assigned to in inline assembly.
|
||||||
|
// TypeError: (75-76): Only local variables can be assigned to in inline assembly.
|
||||||
|
// TypeError: (88-89): Only local variables can be assigned to in inline assembly.
|
@ -0,0 +1,16 @@
|
|||||||
|
contract C {
|
||||||
|
function f() public pure {
|
||||||
|
assembly {
|
||||||
|
function f(a) {}
|
||||||
|
|
||||||
|
f()
|
||||||
|
f(1)
|
||||||
|
f(1, 2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError: (87-88): Expected 1 arguments but got 0.
|
||||||
|
// Warning: (87-90): Top-level expressions are not supposed to return values (this expression returns -1 values). Use ``pop()`` or assign them.
|
||||||
|
// TypeError: (108-109): Expected 1 arguments but got 2.
|
||||||
|
// Warning: (108-115): Top-level expressions are not supposed to return values (this expression returns 1 value). Use ``pop()`` or assign them.
|
@ -0,0 +1,9 @@
|
|||||||
|
contract C {
|
||||||
|
function f() public pure {
|
||||||
|
assembly {
|
||||||
|
k()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// DeclarationError: (63-64): Function not found.
|
@ -0,0 +1,13 @@
|
|||||||
|
contract C {
|
||||||
|
function f() public pure {
|
||||||
|
assembly {
|
||||||
|
l:
|
||||||
|
|
||||||
|
l()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// Warning: (63-64): The use of labels is deprecated. Please use "if", "switch", "for" or function calls instead.
|
||||||
|
// Warning: (63-64): Jump instructions and labels are low-level EVM features that can lead to incorrect stack access. Because of that they are discouraged. Please consider using "switch", "if" or "for" statements instead.
|
||||||
|
// TypeError: (73-74): Attempt to call label instead of function.
|
@ -0,0 +1,11 @@
|
|||||||
|
contract C {
|
||||||
|
function f() public pure {
|
||||||
|
assembly {
|
||||||
|
let x := 1
|
||||||
|
|
||||||
|
x()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError: (81-82): Attempt to call variable instead of function.
|
@ -0,0 +1,11 @@
|
|||||||
|
contract C {
|
||||||
|
function f() public pure {
|
||||||
|
assembly {
|
||||||
|
function k() {}
|
||||||
|
|
||||||
|
k
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError: (86-87): Function k used without being called.
|
@ -0,0 +1,13 @@
|
|||||||
|
contract C {
|
||||||
|
uint[] x;
|
||||||
|
function() external {
|
||||||
|
uint[] storage y = x;
|
||||||
|
assembly {
|
||||||
|
y_slot := 1
|
||||||
|
y_offset := 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError: (115-121): Storage variables cannot be assigned to.
|
||||||
|
// TypeError: (139-147): Storage variables cannot be assigned to.
|
@ -0,0 +1,13 @@
|
|||||||
|
contract C {
|
||||||
|
uint[] x;
|
||||||
|
function() external {
|
||||||
|
uint[] memory y = x;
|
||||||
|
assembly {
|
||||||
|
pop(y_slot)
|
||||||
|
pop(y_offset)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError: (118-124): The suffixes _offset and _slot can only be used on storage variables.
|
||||||
|
// TypeError: (142-150): The suffixes _offset and _slot can only be used on storage variables.
|
Loading…
Reference in New Issue
Block a user