Skip to content

Commit 421d219

Browse files
authored
Merge pull request #29 from django-ftl/variable-reuse-issue-27
Variable reuse issue
2 parents c0bb1b6 + eacb782 commit 421d219

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/fluent_compiler/compiler.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ def compile_expr_variable_reference(argument, block, compiler_env):
904904

905905
if block.scope.has_assignment(arg_tmp_name): # already assigned to this, can re-use
906906
if not wrap_with_handle_argument:
907-
return block.variable(arg_tmp_name)
907+
return block.scope.variable(arg_tmp_name)
908908

909909
block.add_assignment(arg_handled_tmp_name, handle_argument_func_call)
910910
return block.scope.variable(arg_handled_tmp_name)

tests/test_compiler.py

+15
Original file line numberDiff line numberDiff line change
@@ -1278,3 +1278,18 @@ def test_non_unique_escaper(self):
12781278
self.locale,
12791279
escapers=[html_escaper, html_escaper],
12801280
)
1281+
1282+
def test_variable_reuse(self):
1283+
code, errs = self.compile_messages(
1284+
"""
1285+
example = My name is { $name ->
1286+
[Peter] Peter11
1287+
*[other] Jane11
1288+
}
1289+
My gender is { $name ->
1290+
[Peter] Male
1291+
*[other] Female
1292+
}
1293+
"""
1294+
)
1295+
assert not errs

0 commit comments

Comments
 (0)