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

Fields in data families are reported as unused in most cases #171

Open
jasagredo opened this issue Jun 21, 2024 · 0 comments
Open

Fields in data families are reported as unused in most cases #171

jasagredo opened this issue Jun 21, 2024 · 0 comments

Comments

@jasagredo
Copy link

jasagredo commented Jun 21, 2024

This example shows getA as a weed if foo5 is not defined:

{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NamedFieldPuns #-}
module MyLib where

data family DF a

data instance DF Int = A { getA :: Int }

foo :: DF Int -> IO ()
foo (A x) = print x

bar :: DF Int -> IO ()
bar (A{getA}) = print getA

baz :: DF Int -> IO ()
baz (A{..}) = print getA

foo2 :: Int -> DF Int
foo2 x = A x

foo3 :: Int -> DF Int
foo3 x = A { getA = x }

foo4 :: Int -> DF Int -> DF Int
foo4 x a = a { getA = x }

foo5 :: DF Int -> Int
foo5 a = getA a

Note that if this is not a data family, the field is declared as used as soon as it is pattern-matched, without mentioning the actual field name. This shows no weeds

module MyLib where

data A = A { getA :: Int }

foo :: A -> IO ()
foo (A x) = print x

I'm using the following weeder.toml file, and an executable that uses all the functions available:

roots = ["Main.main"]

type-class-roots = true

unused-types = true

The readme says:

Type families
Weeder cannot yet analyse uses of type family instances. For this reason type family instances will be marked as implicit roots if analysis of types is enabled via unused-types.

However either I am misunderstanding that note, or these are not being marked as roots.

ryndubei added a commit to ryndubei/weeder that referenced this issue Jul 17, 2024
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

No branches or pull requests

1 participant