From c2f5fe40b4cd65ffd3cdf38530677c980174ba33 Mon Sep 17 00:00:00 2001 From: Colin Rofls Date: Fri, 4 Oct 2024 15:50:32 -0400 Subject: [PATCH] [fea-rs] Fix panic if same file was included twice This wasn't something I had considered originally, but the fix is easy and zero-overhead. --- fea-rs/src/token_tree.rs | 4 +- .../good/include_same_file_twice.PARSE_TREE | 51 +++++++++++++++++++ .../good/include_same_file_twice.fea | 3 ++ 3 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 fea-rs/test-data/parse-tests/good/include_same_file_twice.PARSE_TREE create mode 100644 fea-rs/test-data/parse-tests/good/include_same_file_twice.fea diff --git a/fea-rs/src/token_tree.rs b/fea-rs/src/token_tree.rs index 443ec4bb..2dbd4662 100644 --- a/fea-rs/src/token_tree.rs +++ b/fea-rs/src/token_tree.rs @@ -263,9 +263,7 @@ impl Node { fn update_positions_recurse(&mut self, mut pos: usize) { self.abs_pos = pos as _; - let Some(children) = Arc::get_mut(&mut self.children) else { - panic!("update_positions should only be called on a newly created node",); - }; + let children = Arc::make_mut(&mut self.children); for child in children { child.update_positions(pos); diff --git a/fea-rs/test-data/parse-tests/good/include_same_file_twice.PARSE_TREE b/fea-rs/test-data/parse-tests/good/include_same_file_twice.PARSE_TREE new file mode 100644 index 00000000..45d0f8d0 --- /dev/null +++ b/fea-rs/test-data/parse-tests/good/include_same_file_twice.PARSE_TREE @@ -0,0 +1,51 @@ +FILE@[0; 147) + #@0 "# we had an issue where we would panic if the same file was included twice" + WS@74 "\n" + FeatureNode@[75; 109) + FeatureKw@75 "feature" + WS@82 " " + Tag@83 "nam" + WS@86 " " + {@87 "{" + WS@88 "\n " + GposType2@[91; 102) + PosKw@91 "pos" + WS@94 " " + GlyphName@95 "A" + WS@96 " " + GlyphName@97 "B" + WS@98 " " + ValueRecordNode@[99; 101) + NUM@99 "20" + ;@101 ";" + WS@102 "\n" + }@103 "}" + WS@104 " " + Tag@105 "nam" + ;@108 ";" + WS@109 "\n" + WS@110 "\n" + FeatureNode@[111; 145) + FeatureKw@111 "feature" + WS@118 " " + Tag@119 "nam" + WS@122 " " + {@123 "{" + WS@124 "\n " + GposType2@[127; 138) + PosKw@127 "pos" + WS@130 " " + GlyphName@131 "A" + WS@132 " " + GlyphName@133 "B" + WS@134 " " + ValueRecordNode@[135; 137) + NUM@135 "20" + ;@137 ";" + WS@138 "\n" + }@139 "}" + WS@140 " " + Tag@141 "nam" + ;@144 ";" + WS@145 "\n" + WS@146 "\n" diff --git a/fea-rs/test-data/parse-tests/good/include_same_file_twice.fea b/fea-rs/test-data/parse-tests/good/include_same_file_twice.fea new file mode 100644 index 00000000..49a2ec2a --- /dev/null +++ b/fea-rs/test-data/parse-tests/good/include_same_file_twice.fea @@ -0,0 +1,3 @@ +# we had an issue where we would panic if the same file was included twice +include(short-tag.fea); +include(short-tag.fea);