Browse Source

fix #220

begin/end does not create a new variable scope, so wrap blocks in
`(fun () -> BLOCK end)()` instead of a `begin BLOCK end`.
Andreas Stenius 9 years ago
parent
commit
59cfc378d1
2 changed files with 3 additions and 1 deletions
  1. 1 1
      src/erlydtl_beam_compiler.erl
  2. 2 0
      test/erlydtl_test_defs.erl

+ 1 - 1
src/erlydtl_beam_compiler.erl

@@ -722,7 +722,7 @@ body_ast(DjangoParseTree, BodyScope, TreeWalker) ->
           end, #ast_info{}, AstInfoList),
 
     {Ast, TreeWalker2} = end_scope(
-                           fun ([ScopeVars|ScopeBody]) -> [?Q("begin _@ScopeVars, [_@ScopeBody] end")] end,
+                           fun ([ScopeVars|ScopeBody]) -> [?Q("(fun() -> _@ScopeVars, [_@ScopeBody] end)()")] end,
                            ScopeId, AstList, TreeWalker1),
     {{erl_syntax:list(Ast), Info}, TreeWalker2}.
 

+ 2 - 0
test/erlydtl_test_defs.erl

@@ -2032,6 +2032,8 @@ setup_compile("reader_options") ->
  {ok, [[]|[{compile_opts, [{reader, {?MODULE, extra_reader}}, {reader_options, [{user_id, <<"007">>}, {user_name, <<"Agent">>}]}]}]]};
 setup_compile("ssi_reader_options") ->
  {ok, [[]|[{compile_opts, [{reader, {?MODULE, extra_reader}}, {reader_options, [{user_id, <<"007">>}, {user_name, <<"Agent">>}]}]}]]};
+%%setup_compile("extend_doubleblock") ->
+%%    {ok, [[]|[{compile_opts, [debug_compiler]}]]};
 setup_compile(_) ->
     {ok, [[]]}.