Skip to content

Commit

Permalink
[fea-rs] Fix panic if same file was included twice
Browse files Browse the repository at this point in the history
This wasn't something I had considered originally, but the fix is easy
and zero-overhead.
  • Loading branch information
cmyr committed Oct 4, 2024
1 parent 603af2a commit c2f5fe4
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
4 changes: 1 addition & 3 deletions fea-rs/src/token_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 3 additions & 0 deletions fea-rs/test-data/parse-tests/good/include_same_file_twice.fea
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit c2f5fe4

Please sign in to comment.