Browse Source

Explicitly reject substitutions with invalid arithmetic expressions

Ian Goldberg 3 months ago
parent
commit
1697b5a234
1 changed files with 10 additions and 0 deletions
  1. 10 0
      sigma_compiler_core/src/substitution.rs

+ 10 - 0
sigma_compiler_core/src/substitution.rs

@@ -43,6 +43,7 @@ use super::transform::{paren_if_needed, prune_statement_tree};
 use super::{TaggedIdent, TaggedScalar, TaggedVarDict};
 use quote::quote;
 use std::collections::{HashSet, VecDeque};
+use syn::spanned::Spanned;
 use syn::visit::Visit;
 use syn::visit_mut::{self, VisitMut};
 use syn::{parse_quote, Error, Expr, Ident, Result};
@@ -151,6 +152,15 @@ pub fn transform(
                     });
                     let right = paren_if_needed(*right);
                     subs.push_back((id, right, used_priv_scalars));
+                } else {
+                    return Err(Error::new(
+                        right.span(),
+                        format!(
+                            "Unrecognized arithmetic expression in substitution: {} = {}",
+                            id,
+                            quote! {#right}
+                        ),
+                    ));
                 }
             }
         }