mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Create.
This commit is contained in:
parent
70b796bd1a
commit
b5d6d5fcf9
@ -622,13 +622,21 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
||||
else
|
||||
m_context << u256(0);
|
||||
m_context << Instruction::CREATE;
|
||||
solUnimplementedAssert(!_functionCall.annotation().tryCall, "");
|
||||
// Check if zero (out of stack or not enough balance).
|
||||
m_context << Instruction::DUP1 << Instruction::ISZERO;
|
||||
// TODO: Can we bubble up here? There might be different reasons for failure, I think.
|
||||
m_context.appendConditionalRevert(true);
|
||||
if (function.valueSet())
|
||||
m_context << swapInstruction(1) << Instruction::POP;
|
||||
// Check if zero (reverted)
|
||||
m_context << Instruction::DUP1 << Instruction::ISZERO;
|
||||
if (_functionCall.annotation().tryCall)
|
||||
{
|
||||
// If this is a try call, return "<address> 1" in the success case and
|
||||
// "0" in the error case.
|
||||
AssemblyItem errorCase = m_context.appendConditionalJump();
|
||||
m_context << u256(1);
|
||||
m_context << errorCase;
|
||||
}
|
||||
else
|
||||
// TODO: Can we bubble up here? There might be different reasons for failure, I think.
|
||||
m_context.appendConditionalRevert(true);
|
||||
break;
|
||||
}
|
||||
case FunctionType::Kind::SetGas:
|
||||
|
32
test/libsolidity/semanticTests/tryCatch/create.sol
Normal file
32
test/libsolidity/semanticTests/tryCatch/create.sol
Normal file
@ -0,0 +1,32 @@
|
||||
contract Reverts {
|
||||
constructor(uint) public { revert("test message."); }
|
||||
}
|
||||
contract Succeeds {
|
||||
constructor(uint) public { }
|
||||
}
|
||||
|
||||
contract C {
|
||||
function f() public returns (Reverts x, uint, string memory txt) {
|
||||
uint i = 3;
|
||||
try new Reverts(i) returns (Reverts r) {
|
||||
x = r;
|
||||
txt = "success";
|
||||
} catch Error(string memory s) {
|
||||
txt = s;
|
||||
}
|
||||
}
|
||||
function g() public returns (Succeeds x, uint, string memory txt) {
|
||||
uint i = 8;
|
||||
try new Succeeds(i) returns (Succeeds r) {
|
||||
x = r;
|
||||
txt = "success";
|
||||
} catch Error(string memory s) {
|
||||
txt = s;
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >=byzantium
|
||||
// ----
|
||||
// f() -> 0, 0, 96, 13, "test message."
|
||||
// g() -> 0xf01f7809444bd9a93a854361c6fae3f23d9e23db, 0, 96, 7, "success"
|
Loading…
Reference in New Issue
Block a user