Skip to content

Commit 7c62440

Browse files
authored
fix(pgt_query): iter macros (#517)
fixes a pretty critical bug in the macros that caused us to skip some nodes! stumbled upon this while working on the pretty printer.
1 parent e3d1576 commit 7c62440

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

crates/pgt_query_macros/src/iter_mut.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@ pub fn iter_mut_mod(analyser: ProtoAnalyzer) -> proc_macro2::TokenStream {
1919

2020
for node in &nodes {
2121
// Use the enum variant name from the Node enum
22-
if let Some(variant_name) = type_to_variant.get(&node.name) {
22+
if let Some(variant_name) = type_to_variant.get(&node.enum_variant_name) {
2323
let variant_ident = format_ident!("{}", variant_name);
2424
node_variant_names.push(variant_ident);
2525

2626
let property_handlers = property_handlers(node);
2727
node_property_handlers.push(property_handlers);
28+
} else {
29+
panic!(
30+
"No enum variant found for node type: {}",
31+
node.enum_variant_name
32+
);
2833
}
2934
}
3035

crates/pgt_query_macros/src/iter_ref.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,19 @@ pub fn iter_ref_mod(analyser: ProtoAnalyzer) -> proc_macro2::TokenStream {
1717
}
1818

1919
for node in &nodes {
20-
if let Some(variant_name) = type_to_variant.get(&node.name) {
20+
if let Some(variant_name) = type_to_variant.get(&node.enum_variant_name) {
2121
let variant_ident = format_ident!("{}", variant_name);
2222
node_variant_names.push(variant_ident);
2323

2424
let property_handlers = property_handlers(node);
2525
node_property_handlers.push(quote! {
2626
#(#property_handlers)*
2727
});
28+
} else {
29+
panic!(
30+
"No enum variant found for node type: {}",
31+
node.enum_variant_name
32+
);
2833
}
2934
}
3035

crates/pgt_query_macros/src/proto_analyser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ pub(crate) struct Field {
3838
}
3939

4040
pub(crate) struct Node {
41-
pub name: String,
4241
#[allow(dead_code)]
42+
pub name: String,
4343
pub enum_variant_name: String,
4444
pub fields: Vec<Field>,
4545
}

0 commit comments

Comments
 (0)