Skip to content

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

@jasagredo

Description

@jasagredo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions