Skip to content

Conversation

@teofr
Copy link
Contributor

@teofr teofr commented Jan 7, 2026

Currently the old style revert function (revert("description")) is being parsed as a revert statement, the issue with this is that it doesn't allow the binder to solve the right reference to it (the built-in reserve) or even for the user to shadow it with their own revert function.

Update: I also noticed that before this change some cases were parsed differently depending on context, so:

revert("Ooops!"); // This is parsed as a RevertStatement
if revert("Ooops!") {} // The condition expression is parsed as a FunctionCall to a built in function

@teofr teofr requested review from a team as code owners January 7, 2026 11:26
@changeset-bot
Copy link

changeset-bot bot commented Jan 7, 2026

🦋 Changeset detected

Latest commit: 9c327c8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@nomicfoundation/slang Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

@ggiraldez ggiraldez left a comment

Choose a reason for hiding this comment

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

Left a couple of minor comments, but otherwise looks good to me.

Comment on lines 635 to 640
let definition_id = {
let reference = self
.binder
.find_reference_by_identifier_node_id(node.error.last().unwrap().id());
reference.and_then(|reference| reference.resolution.as_definition_id())
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: prefer the inline expression:

let definition_id = self
    .binder
    .find_reference_by_identifier_node_id(node.error.last().unwrap().id())
    .and_then(|reference| reference.resolution.as_definition_id());

Comment on lines 2 to 11
function testBuiltIn() public pure {
revert("error");
}

function testShadowed() public pure {
function(string memory) pure revert = customRevert;
revert("error");
}

function customRevert(string memory) internal pure {}
Copy link
Contributor

Choose a reason for hiding this comment

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

To avoid the failing case for 0.4.11 you should remove the pure attributes, which will make the test clearer on its intent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, that makes it a lot better

Comment on lines 12 to 21

function revertFunction() public {
revert("error");
}


function revertFunctionInCondition() public {
if (revert("error")) {}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it may be better to move these two functions to a separate test case to avoid confusion with the name revert_stmt, maybe as revert_as_function. Or even to the revert_shadowing case above, renaming it to revert_as_function and changing the testShadowed() function to a more explicit testRevertCanBeShadowed().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved them around as suggested, it's more clear. Thanks

Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: removing these two new empty lines would remove the unnecessary diffs in the output files for this case.

@teofr teofr requested a review from ggiraldez January 9, 2026 16:08
Copy link
Contributor

@ggiraldez ggiraldez left a comment

Choose a reason for hiding this comment

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

Left another two minor suggestions, but looks great, thank you!

"@nomicfoundation/slang": minor
---

Fixed the old style revert calls (`revert("oops!")`) to be parsed as a normal function call rather than a reverse statement.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Fixed the old style revert calls (`revert("oops!")`) to be parsed as a normal function call rather than a reverse statement.
Fixed the old style revert calls (`revert("oops!")`) to be parsed as a normal function call rather than a `revert` statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! thanks

Comment on lines 12 to 21

function revertFunction() public {
revert("error");
}


function revertFunctionInCondition() public {
if (revert("error")) {}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: removing these two new empty lines would remove the unnecessary diffs in the output files for this case.

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.

3 participants