Skip to content

Commit d32b0eb

Browse files
committed
Require with custom error for legacy pipeline
1 parent 12b404f commit d32b0eb

9 files changed

+24
-17
lines changed

libsolidity/codegen/ExpressionCompiler.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,30 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
12631263
// as require with custom errors is not supported in legacy codegen.
12641264
auto const* magicType = dynamic_cast<MagicType const*>(arguments[1]->annotation().type);
12651265
if (magicType && magicType->kind() == MagicType::Kind::Error)
1266-
solUnimplemented("Require with a custom error is only available using the via-ir pipeline.");
1266+
{
1267+
m_context << Instruction::ISZERO << Instruction::ISZERO;
1268+
auto success = m_context.appendConditionalJump();
1269+
1270+
auto const& errorConstructorCall = dynamic_cast<FunctionCall const&>(*arguments[1]);
1271+
errorConstructorCall.expression().accept(*this);
1272+
std::vector<Type const*> argumentTypes;
1273+
for (ASTPointer<Expression const> const& arg: errorConstructorCall.sortedArguments())
1274+
{
1275+
arg->accept(*this);
1276+
argumentTypes.push_back(arg->annotation().type);
1277+
}
1278+
1279+
auto const* errorDefinition = dynamic_cast<ErrorDefinition const*>(ASTNode::referencedDeclaration(errorConstructorCall.expression()));
1280+
solAssert(errorDefinition);
1281+
1282+
utils().revertWithError(
1283+
errorDefinition->functionType(true)->externalSignature(),
1284+
errorDefinition->functionType(true)->parameterTypes(),
1285+
argumentTypes
1286+
);
1287+
m_context << success;
1288+
break;
1289+
}
12671290

12681291
if (m_context.revertStrings() == RevertStrings::Strip)
12691292
{

test/libsolidity/semanticTests/errors/require_different_errors_same_parameters.sol

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ contract C
1414
}
1515
}
1616

17-
// ====
18-
// compileViaYul: true
1917
// ----
2018
// f() -> FAILURE, hex"f55fefe3", hex"0000000000000000000000000000000000000000000000000000000000000001", hex"0000000000000000000000000000000000000000000000000000000000000060", hex"0000000000000000000000000000000000000000000000000000000000000003", hex"0000000000000000000000000000000000000000000000000000000000000003", hex"74776f0000000000000000000000000000000000000000000000000000000000"
2119
// g() -> FAILURE, hex"44a06798", hex"0000000000000000000000000000000000000000000000000000000000000004", hex"0000000000000000000000000000000000000000000000000000000000000060", hex"0000000000000000000000000000000000000000000000000000000000000006", hex"0000000000000000000000000000000000000000000000000000000000000004", hex"6669766500000000000000000000000000000000000000000000000000000000"

test/libsolidity/semanticTests/errors/require_error_function_pointer_parameter.sol

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,5 @@ contract C
1414
}
1515
}
1616

17-
// ====
18-
// compileViaYul: true
1917
// ----
2018
// f() -> FAILURE, hex"271b1dfa", hex"c06afe3a8444fc0004668591e8306bfb9968e79ef37cdc8e0000000000000000"

test/libsolidity/semanticTests/errors/require_error_multiple_arguments.sol

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ contract C
1313
}
1414
}
1515

16-
// ====
17-
// compileViaYul: true
1816
// ----
1917
// f() -> FAILURE, hex"11a1077e", hex"0000000000000000000000000000000000000000000000000000000000000001", hex"0000000000000000000000000000000000000000000000000000000000000060", hex"0000000000000000000000000000000000000000000000000000000000000003", hex"0000000000000000000000000000000000000000000000000000000000000003", hex"74776f0000000000000000000000000000000000000000000000000000000000"
2018
// g() -> FAILURE, hex"11a1077e", hex"0000000000000000000000000000000000000000000000000000000000000004", hex"0000000000000000000000000000000000000000000000000000000000000060", hex"0000000000000000000000000000000000000000000000000000000000000006", hex"0000000000000000000000000000000000000000000000000000000000000004", hex"6669766500000000000000000000000000000000000000000000000000000000"

test/libsolidity/semanticTests/errors/require_error_string_literal.sol

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ contract C
1313
}
1414
}
1515

16-
// ====
17-
// compileViaYul: true
1816
// ----
1917
// f() -> FAILURE, hex"8d6ea8be", hex"0000000000000000000000000000000000000000000000000000000000000020", hex"000000000000000000000000000000000000000000000000000000000000000b", hex"6572726f72526561736f6e000000000000000000000000000000000000000000"
2018
// g() -> FAILURE, hex"8d6ea8be", hex"0000000000000000000000000000000000000000000000000000000000000020", hex"000000000000000000000000000000000000000000000000000000000000000d", hex"616e6f74686572526561736f6e00000000000000000000000000000000000000"

test/libsolidity/semanticTests/errors/require_error_string_memory.sol

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ contract C
1515
}
1616
}
1717

18-
// ====
19-
// compileViaYul: true
2018
// ----
2119
// f() -> FAILURE, hex"8d6ea8be", hex"0000000000000000000000000000000000000000000000000000000000000020", hex"000000000000000000000000000000000000000000000000000000000000000b", hex"6572726f72526561736f6e000000000000000000000000000000000000000000"
2220
// g() -> FAILURE, hex"8d6ea8be", hex"0000000000000000000000000000000000000000000000000000000000000020", hex"000000000000000000000000000000000000000000000000000000000000000d", hex"616e6f74686572526561736f6e00000000000000000000000000000000000000"

test/libsolidity/semanticTests/errors/require_error_uint256.sol

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ contract C
1313
}
1414
}
1515

16-
// ====
17-
// compileViaYul: true
1816
// ----
1917
// f() -> FAILURE, hex"110b3655", hex"0000000000000000000000000000000000000000000000000000000000000001"
2018
// g() -> FAILURE, hex"110b3655", hex"0000000000000000000000000000000000000000000000000000000000000002"

test/libsolidity/semanticTests/errors/require_evaluation_order.sol

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ contract C
2121
}
2222
}
2323

24-
// ====
25-
// compileViaYul: true
2624
// ----
2725
// f() -> 7
2826
// g() -> 7

test/libsolidity/semanticTests/errors/require_inherited_error.sol

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,5 @@ contract C is Base
1111
}
1212
}
1313

14-
// ====
15-
// compileViaYul: true
1614
// ----
1715
// f() -> FAILURE, hex"11a1077e", hex"0000000000000000000000000000000000000000000000000000000000000001", hex"0000000000000000000000000000000000000000000000000000000000000060", hex"0000000000000000000000000000000000000000000000000000000000000003", hex"0000000000000000000000000000000000000000000000000000000000000003", hex"74776f0000000000000000000000000000000000000000000000000000000000"

0 commit comments

Comments
 (0)