Skip to content

fix: outer_variables crash#34

Open
katafrakt wants to merge 1 commit into
gp-pereira:mainfrom
katafrakt:fix-outer-variables
Open

fix: outer_variables crash#34
katafrakt wants to merge 1 commit into
gp-pereira:mainfrom
katafrakt:fix-outer-variables

Conversation

@katafrakt
Copy link
Copy Markdown

When calling Refactorex from Expert, I often see this error:

  11:22:06.870 instance_id=19E16560B72 [debug] Node port message:                                                                                                                               
  11:22:06.869 [error] Task #PID<0.5820.0> started from #PID<0.5806.0> terminating                                                                                                              
  ** (FunctionClauseError) no function clause matching in anonymous fn/1 in XPRefactorex.Refactor.Dataflow.outer_variables/1                                                                    
      (xp_refactorex 0.1.52) lib/refactorex/refactor/dataflow.ex:20: anonymous fn({:gen, {:env, [trailing_comments: [], leading_comments: [], line: 222, column: 9], nil}}) in                  
  XPRefactorex.Refactor.Dataflow.outer_variables/1                                                                                                                                              
      (elixir 1.19.4) lib/stream.ex:630: anonymous fn/4 in Stream.map/2                                                                                                                         
      (elixir 1.19.4) lib/enum.ex:5023: Enumerable.List.reduce/3                                                                                                                                
      (elixir 1.19.4) lib/stream.ex:1773: Enumerable.Stream.do_each/4                                                                                                                           
      (elixir 1.19.4) lib/enum.ex:4570: Enum.reverse/1                                                                                                                                          
      (xp_refactorex 0.1.52) lib/refactorex/refactor/dataflow.ex:21: XPRefactorex.Refactor.Dataflow.outer_variables/1                                                                           
      (xp_refactorex 0.1.52) lib/refactorex/refactor/function/extract_function.ex:42: XPRefactorex.Refactor.Function.ExtractFunction.refactor/2                                                 
      (xp_refactorex 0.1.52) lib/refactorex/refactor/function/extract_function.ex:2: XPRefactorex.Refactor.Function.ExtractFunction.visit/4                                                     
  Function: &:erlang.apply/2                                                                                                                                                                    
      Args: [#Function<0.114616880/1 in XPRefactorex.Refactor.available_refactorings/4>, [XPRefactorex.Refactor.Function.ExtractFunction]] 

I was able to replace it by calling outer_variables on any fragment which actually declares a variable - {:gen, _} is returned but never consumed. Swapping recursive_analyze to analyze_scope helped. Added a bunch of tests reproducing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant