Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing cases to var usage analysis #2251

Merged
merged 2 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def put = \y. place (y : Text); end;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def put = \y. [x = 3, z = 7]; end;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def put = \y. [x = 3, y]; end;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def put = \y. [x = 3, z = y + 2]; end;
22 changes: 21 additions & 1 deletion src/swarm-lang/Swarm/Language/LSP/VarUsage.hs
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,24 @@ getUsage bindings (CSyntax _pos t _comments) = case t of
Just v -> checkOccurrences bindings v Bind [s1, s2]
Nothing -> getUsage bindings s1 <> getUsage bindings s2
SDelay s -> getUsage bindings s
_ -> mempty
SRcd m -> M.foldMapWithKey (\x -> maybe (getUsage bindings (STerm (TVar x))) (getUsage bindings)) m
SProj s _ -> getUsage bindings s
SAnnotate s _ -> getUsage bindings s
SSuspend s -> getUsage bindings s
-- Explicitly enumerate the cases with no variables, instead of a
-- catch-all, so that we get a warning when adding new constructors.
TUnit {} -> mempty
TConst {} -> mempty
TDir {} -> mempty
TInt {} -> mempty
TAntiInt {} -> mempty
TText {} -> mempty
TAntiText {} -> mempty
TBool {} -> mempty
TRobot {} -> mempty
TRef {} -> mempty
TRequireDevice {} -> mempty
TRequire {} -> mempty
SRequirements {} -> mempty
STydef {} -> mempty
TType {} -> mempty
16 changes: 16 additions & 0 deletions test/unit/TestLSP.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ testLSP =
checkFile
"single-bind-used.sw"
[]
, testCase "lambda with var used inside annotation" $
checkFile
"lambda-with-annot.sw"
[]
, testCase "record with used var" $
checkFile
"lambda-with-record-used.sw"
[]
, testCase "record with used var abbrev" $
checkFile
"lambda-with-record-used-abbrev.sw"
[]
, testCase "record with unused var" $
checkFile
"lambda-with-record-unused.sw"
[UnusedVar "y" VU.Lambda]
]
where
checkFile :: FilePath -> [UnusedVar] -> IO ()
Expand Down
Loading