Skip to content

Commit

Permalink
Fix let function arguments not registering with the correct module name
Browse files Browse the repository at this point in the history
  • Loading branch information
jfmengels committed Jun 17, 2023
1 parent 84aae3b commit 929d850
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/Review/ModuleNameLookupTable/Compute.elm
Original file line number Diff line number Diff line change
Expand Up @@ -1220,11 +1220,28 @@ expressionEnterVisitor node context =
(\declaration scopes ->
case Node.value declaration of
Expression.LetFunction function ->
registerVariable
{ variableType = LetVariable
, node = (Node.value function.declaration).name
}
scopes
let
{ name, expression, arguments } =
Node.value function.declaration

withLetVariable : NonEmpty Scope
withLetVariable =
registerVariable
{ variableType = LetVariable
, node = name
}
scopes
in
if List.isEmpty arguments then
withLetVariable

else
let
names : Dict String VariableInfo
names =
collectNamesFromPattern PatternVariable arguments Dict.empty
in
NonEmpty.mapHead (\scope -> { scope | cases = ( expression, names ) :: scope.cases }) withLetVariable

Expression.LetDestructuring _ _ ->
scopes
Expand Down
9 changes: 9 additions & 0 deletions tests/ModuleNameLookupTableTest.elm
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ a = localValue
True
Just
Cmd.none
(let foo get = get
in
get
)
(+)
(117 + 3)
(<?>)
Expand Down Expand Up @@ -155,6 +159,8 @@ Http.get -> Http.get
<nothing>.True -> Basics.True
<nothing>.Just -> Maybe.Just
Cmd.none -> Platform.Cmd.none
<nothing>.get -> <nothing>.get
<nothing>.get -> Http.get
<nothing>.+ -> Basics.+
<nothing>.+ -> Basics.+
<nothing>.<?> -> Url.Parser.<?>
Expand Down Expand Up @@ -689,6 +695,9 @@ collectPatterns lookupFunction context node =
Pattern.AsPattern subPattern _ ->
collectPatterns lookupFunction context subPattern

Pattern.VarPattern _ ->
[]

_ ->
Debug.todo ("Other patterns in case expressions are not handled: " ++ Debug.toString node)

Expand Down

0 comments on commit 929d850

Please sign in to comment.