Skip to content

Commit

Permalink
Fix the 'ouble' bug
Browse files Browse the repository at this point in the history
This bug occurs when the `pos` variable in `collect_variables()`
(`collect_variables.cpp:57`) is set one character too far after erasing
an initializer. This leads to the output getting mangled because of the
skipped character.

For example, consider the script
```
local double i;
local double j;
```

This will lead to the output being
```
double i;
ouble j;
```

Because after parsing `i`, the `pos` will be on the second character of
`local`, i.e. it will see `ocal`, and the way the parser is coded makes
it so that it ends up skipping the first `d` of `double`.

To fix this, just set `pos` to be one character behind when erasing an
initializer.
  • Loading branch information
dc03 committed May 31, 2022
1 parent 5e72848 commit c8e288d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion CompilerSource/parser/collect_variables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void collect_variables(const LanguageFrontend *lang, enigma::parsing::AST *ast,
cout << "ERASE FROM CODE: " << code.substr(dec_start_pos,dec_equals_at-dec_start_pos) << endl;
code.replace(dec_start_pos,dec_equals_at-dec_start_pos, dec_name);
synt.replace(dec_start_pos,dec_equals_at-dec_start_pos, string(dec_name.length(),'n'));
pos -= dec_equals_at - dec_start_pos - 1 - dec_name.length();
pos -= dec_equals_at - dec_start_pos - dec_name.length();
}
dec_start_pos = pos;
}
Expand Down

0 comments on commit c8e288d

Please sign in to comment.