Skip to content

Commit

Permalink
avoid name collision
Browse files Browse the repository at this point in the history
  • Loading branch information
Rudxain committed Nov 5, 2022
1 parent 0aaf72f commit 26d9d64
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src-py/crickroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,15 @@ def convert(self, kw: str):
"""
give id up xpr;
"""
id = self.values[1]
# named `_id` to avoid collision with `id`
_id = self.values[1]
xpr = join_list(self.values[self.values.index('up') + 1:])

if id not in declared_variables:
self.write(f'auto {id}={xpr};')
declared_variables.add(id)
if _id not in declared_variables:
self.write(f'auto {_id}={xpr};')
declared_variables.add(_id)
else:
self.write(f'{id}={xpr};')
self.write(f'{_id}={xpr};')

if kw == KW.ENDLESS_LOOP.value:
self.write('while(true){')
Expand All @@ -197,10 +198,10 @@ def convert(self, kw: str):
"""
int id(ARGS){
"""
id = self.values[1]
_id = self.values[1]
ARGS: Final = ", ".join(["auto "+x for x in self.values[2:]])

self.write(f"auto {id} = []({ARGS}) {{")
self.write(f"auto {_id} = []({ARGS}) {{")

if kw == KW.RETURN1.value:
"""
Expand Down

0 comments on commit 26d9d64

Please sign in to comment.