From 929d8508fda14ee2948c97a6b47673fbdb456760 Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Sat, 17 Jun 2023 19:47:43 +0200 Subject: [PATCH] Fix let function arguments not registering with the correct module name --- src/Review/ModuleNameLookupTable/Compute.elm | 27 ++++++++++++++++---- tests/ModuleNameLookupTableTest.elm | 9 +++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/Review/ModuleNameLookupTable/Compute.elm b/src/Review/ModuleNameLookupTable/Compute.elm index bb26514ea..555498e0b 100644 --- a/src/Review/ModuleNameLookupTable/Compute.elm +++ b/src/Review/ModuleNameLookupTable/Compute.elm @@ -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 diff --git a/tests/ModuleNameLookupTableTest.elm b/tests/ModuleNameLookupTableTest.elm index b0c5051ac..ea1f6d65b 100644 --- a/tests/ModuleNameLookupTableTest.elm +++ b/tests/ModuleNameLookupTableTest.elm @@ -93,6 +93,10 @@ a = localValue True Just Cmd.none + (let foo get = get + in + get + ) (+) (117 + 3) () @@ -155,6 +159,8 @@ Http.get -> Http.get .True -> Basics.True .Just -> Maybe.Just Cmd.none -> Platform.Cmd.none +.get -> .get +.get -> Http.get .+ -> Basics.+ .+ -> Basics.+ . -> Url.Parser. @@ -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)