Skip to content

Commit

Permalink
feature: unsupported message for $idents (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
prestwich authored Sep 23, 2023
1 parent 0c21fcc commit 91ca63c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
11 changes: 10 additions & 1 deletion crates/syn-solidity/src/ident/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::fmt;
use syn::{
ext::IdentExt,
parse::{Parse, ParseStream},
Result,
Result, Token,
};

mod path;
Expand Down Expand Up @@ -105,6 +105,7 @@ impl SolIdent {

/// Parses any identifier including keywords.
pub fn parse_any(input: ParseStream<'_>) -> Result<Self> {
check_dollar(input)?;
input.call(Ident::parse_any).map(Self)
}

Expand All @@ -121,3 +122,11 @@ impl SolIdent {
}
}
}

fn check_dollar(input: ParseStream<'_>) -> Result<()> {
if input.peek(Token![$]) {
Err(input.error("Solidity identifiers starting with `$` are unsupported. This is a known limitation of syn-solidity."))
} else {
Ok(())
}
}
10 changes: 10 additions & 0 deletions crates/syn-solidity/tests/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,13 @@ fn ident_path() {
fn ident_path_trailing() {
let _e = syn::parse_str::<SolPath>("a.b.").unwrap_err();
}

#[test]
fn ident_dollar() {
let id: Result<SolIdent, _> = syn::parse_str("$hello");
assert!(id.is_err());
assert!(id
.unwrap_err()
.to_string()
.contains("Solidity identifiers starting with `$` are unsupported."));
}

0 comments on commit 91ca63c

Please sign in to comment.