Skip to content

fix(parser): treat persistent/temporary/instance as identifiers for non-Soroban targets#1852

Closed
sridhar-panigrahi wants to merge 2 commits intohyperledger-solang:mainfrom
sridhar-panigrahi:fix/soroban-keyword-parser-incompatibility
Closed

fix(parser): treat persistent/temporary/instance as identifiers for non-Soroban targets#1852
sridhar-panigrahi wants to merge 2 commits intohyperledger-solang:mainfrom
sridhar-panigrahi:fix/soroban-keyword-parser-incompatibility

Conversation

@sridhar-panigrahi
Copy link
Copy Markdown

@sridhar-panigrahi sridhar-panigrahi commented Mar 16, 2026

What is the problem?

When PR #1664 added Soroban storage type support, it registered persistent, temporary, and instance as reserved keywords in the global keyword table. This means those words are now off-limits as identifiers in every compilation target — not just Soroban. A regular Solidity contract that uses something like uint256 persistent = 0; or a function named instance() will fail to parse under Solang even when targeting EVM or Polkadot.

Closes #1847.

How is it fixed?

The lexer is made aware of the target. A soroban flag is added to the Lexer struct. When the flag is off (which is the default), those three tokens are handed back to the parser as plain identifiers — just like any other user-defined name. When the flag is on, they behave exactly as before: full keywords with their own token types.

A new parse_soroban() function is added to solang-parser next to the existing parse(). The semantic analysis layer picks the right one at the point where it knows the compilation target.

What changed?

  • solang-parser/src/lexer.rs — added soroban: bool to the Lexer struct and a with_soroban_keywords() builder method; the keyword lookup now returns an Identifier token for the three Soroban words when the flag is not set.
  • solang-parser/src/lib.rsparse() is unchanged and remains the default non-Soroban entry point; parse_soroban() is added for Soroban targets.
  • src/sema/mod.rs — dispatches to parse_soroban() when the target is Soroban, parse() otherwise.
  • solang-parser/src/tests.rs — two new regression tests: one that verifies persistent, temporary, and instance are accepted as identifiers and function names under parse(), and one that verifies they still work as storage-type annotations under parse_soroban().

Testing

  • All existing parser tests pass (cargo test -p solang-parser -- --skip test_libsolidity)
  • All existing library tests pass (cargo test --no-default-features -p solang --lib)
  • Both new regression tests pass

…on-Soroban targets

PR #1664 introduced three Soroban-specific storage type keywords
(persistent, temporary, instance) directly into the global keyword map,
making them reserved words for all targets. This breaks standard Solidity
code that happens to use these common English words as variable or
function names.

The fix makes the lexer target-aware: a new `soroban` flag is added to
`Lexer`. When the flag is false (the default), the three tokens are
returned as plain `Identifier` tokens rather than keyword tokens.
`parse_soroban()` is added to `solang-parser` as a counterpart to the
existing `parse()` function; the semantic analysis layer now calls the
appropriate variant based on the compilation target.

Two new parser-level tests verify the behaviour in both modes.

Fixes #1847

Signed-off-by: Shridhar Panigrahi <sridharpanigrahi2006@gmail.com>
@sridhar-panigrahi sridhar-panigrahi force-pushed the fix/soroban-keyword-parser-incompatibility branch from 1fa5b1e to 62555ac Compare March 16, 2026 08:26
@sridhar-panigrahi
Copy link
Copy Markdown
Author

@salaheldinsoliman , please let me know your thoughts on this !

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.

Solang parser incompatibility from introducing Soroban storage types

1 participant