mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[Yul] Support conditionals
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
contract A {
|
||||
function f() public pure returns (uint) {
|
||||
uint x = 3 < 0 ? 2 > 1 ? 2 : 1 : 7 > 2 ? 7 : 6;
|
||||
return x;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 7
|
||||
@@ -0,0 +1,11 @@
|
||||
contract A {
|
||||
function f() public pure returns (uint) {
|
||||
uint x = true ? 1 : 0;
|
||||
uint y = false ? 0 : 1;
|
||||
return x + y;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 2
|
||||
@@ -0,0 +1,11 @@
|
||||
contract A {
|
||||
function f(bool cond) public pure returns (uint, uint) {
|
||||
(uint a, uint b) = cond ? (1, 2) : (3, 4);
|
||||
return (a, b);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f(bool): true -> 1, 2
|
||||
// f(bool): false -> 3, 4
|
||||
@@ -0,0 +1,13 @@
|
||||
contract A {
|
||||
function f() public pure returns (uint, uint, uint, uint) {
|
||||
uint y1 = 1;
|
||||
uint y2 = 1;
|
||||
uint x = 3 < 0 ? y1 = 3 : 6;
|
||||
uint z = 3 < 10 ? y2 = 5 : 6;
|
||||
return (x, y1, y2, z);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 6, 1, 5, 5
|
||||
@@ -0,0 +1,13 @@
|
||||
contract A {
|
||||
function f() public pure returns (uint, uint, uint, uint) {
|
||||
uint x = 3;
|
||||
uint y = 1;
|
||||
uint z = (x > y) ? x : y;
|
||||
uint w = x < y ? x : y;
|
||||
return (x, y, z, w);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 3, 1, 3, 1
|
||||
Reference in New Issue
Block a user