Tests for assembly access of user defined value types.

This commit is contained in:
hrkrshnn 2021-09-28 14:41:57 +02:00
parent ee0e3e9377
commit 41f9aab219
2 changed files with 70 additions and 0 deletions

View File

@ -0,0 +1,35 @@
pragma abicoder v1;
type MyBytes2 is bytes2;
contract C {
function f(MyBytes2 val) external returns (bytes2 ret) {
assembly {
ret := val
}
}
function g(bytes2 val) external returns (bytes2 ret) {
assembly {
ret := val
}
}
function h(uint256 val) external returns (MyBytes2) {
MyBytes2 ret;
assembly {
ret := val
}
return ret;
}
}
// ====
// compileViaYul: false
// ----
// f(bytes2): "ab" -> 0x6162000000000000000000000000000000000000000000000000000000000000
// g(bytes2): "ab" -> 0x6162000000000000000000000000000000000000000000000000000000000000
// f(bytes2): "abcdef" -> 0x6162000000000000000000000000000000000000000000000000000000000000
// g(bytes2): "abcdef" -> 0x6162000000000000000000000000000000000000000000000000000000000000
// h(uint256): "ab" -> 0x6162000000000000000000000000000000000000000000000000000000000000
// h(uint256): "abcdef" -> 0x6162000000000000000000000000000000000000000000000000000000000000

View File

@ -0,0 +1,35 @@
pragma abicoder v2;
type MyBytes2 is bytes2;
contract C {
function f(MyBytes2 val) external returns (bytes2 ret) {
assembly {
ret := val
}
}
function g(bytes2 val) external returns (bytes2 ret) {
assembly {
ret := val
}
}
function h(uint256 val) external returns (MyBytes2) {
MyBytes2 ret;
assembly {
ret := val
}
return ret;
}
}
// ====
// compileViaYul: also
// ----
// f(bytes2): "ab" -> 0x6162000000000000000000000000000000000000000000000000000000000000
// g(bytes2): "ab" -> 0x6162000000000000000000000000000000000000000000000000000000000000
// f(bytes2): "abcdef" -> FAILURE
// g(bytes2): "abcdef" -> FAILURE
// h(uint256): "ab" -> 0x6162000000000000000000000000000000000000000000000000000000000000
// h(uint256): "abcdef" -> 0x6162000000000000000000000000000000000000000000000000000000000000