Skip to content

Codegen: Fix ICE on parenthesized custom error construction in require statement - #16876

Merged
blishko merged 1 commit into
developfrom
fix-crash-on-parenthesized-custom-error-in-require
Jul 24, 2026
Merged

Codegen: Fix ICE on parenthesized custom error construction in require statement#16876
blishko merged 1 commit into
developfrom
fix-crash-on-parenthesized-custom-error-in-require

Conversation

@blishko

@blishko blishko commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

In a require statement, a second argument can be provided, which can be a string or a custom error.
Parser allows the argument to be included in parentheses. Typechecker is also fine with such an expression. However, code generation, for both legacy and IR pipelines, previously assumed the custom error construction is not parenthesized.
Specifically, the code previously assumed this AST node is FunctionCall. But when parenthesized, this node would be a TupleExpression, resulting in a std::bad_cast exception.
The proposed fix strips away the unary tuple layers from the expression before casting, using the helper resolveOuterUnaryTuples from ASTUtils.

Fixes #16683.

…e statement

In a require statement, a second argument can be provided, which can be
a string or a custom error.
Parser allows the argument to be included in parentheses. Typechecker is
also fine with such an expression. However, code generation, for both
legacy and IR pipelines, previously assumed the custom error
construction is not parenthesized.
Specifically, the code previously assumed this AST node is `FunctionCall`.
But when parenthesized, this node would be a `TupleExpression`,
resulting in a `std::bad_cast` exception.
The proposed fix strips away the unary tuple layers from the expression
before casting, using the helper `resolveOuterUnaryTuples` from
`ASTUtils`.
@blishko
blishko force-pushed the fix-crash-on-parenthesized-custom-error-in-require branch from 57327f3 to a3a3ff3 Compare July 20, 2026 14:45
@@ -0,0 +1,11 @@
// This could be a syntax test, but we want to check compilation with --via-ir as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #15670

@matheusaaguiar matheusaaguiar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@blishko
blishko merged commit 96bdc54 into develop Jul 24, 2026
82 of 83 checks passed
@blishko
blishko deleted the fix-crash-on-parenthesized-custom-error-in-require branch July 24, 2026 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

solc: std::bad_cast in code generation for require(false, (CustomError(1)))

2 participants