Skip to content

Commit

Permalink
Merge pull request #3774 from Ten0/fix_auto_type_underscore_int_litte…
Browse files Browse the repository at this point in the history
…rals

Fix underscore support in int litterals with auto_type
  • Loading branch information
weiznich authored Sep 6, 2023
2 parents 748f4b7 + 92ca0af commit fed0407
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions dsl_auto_type/src/auto_type/expression_type_inference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,14 @@ impl TypeInferrer<'_> {

fn litteral_type(t: &proc_macro2::Literal) -> Result<syn::Type, syn::Error> {
let val = t.to_string();
let type_suffix = &val[val.find(|c: char| !c.is_ascii_digit()).ok_or_else(|| {
syn::Error::new_spanned(
t,
format_args!("Litterals must have type suffix for auto_type, e.g. {val}i64"),
)
})?..];
let type_suffix = &val[val
.find(|c: char| !c.is_ascii_digit() && c != '_')
.ok_or_else(|| {
syn::Error::new_spanned(
t,
format_args!("Litterals must have type suffix for auto_type, e.g. {val}i64"),
)
})?..];
syn::parse_str(type_suffix)
.map_err(|_| syn::Error::new_spanned(t, "Invalid type suffix for litteral"))
}

0 comments on commit fed0407

Please sign in to comment.