kowainik / stan

🕵️ Haskell STatic ANalyser
https://kowainik.github.io/projects/stan
Mozilla Public License 2.0
566 stars 48 forks source link

Stan 0206 should not fire for type data #544

Open noughtmare opened 9 months ago

noughtmare commented 9 months ago

I have this code:

{-# LANGUAGE TypeData #-}

infixr :->
type data PCFType = PCFType :-> PCFType | Nat

And Stan reports:

 ✲ Name:        Data types with non-strict fields
 ✲ Description: Defining lazy fields in data types can lead to unexpected space leaks
 ✲ Severity:    Performance
 ✲ Category:    #SpaceLeak #Syntax
Possible solutions:
  - Add '!' before the type, e.g. !Int or !(Maybe Bool)
  - Enable the 'StrictData' extension: {-# LANGUAGE StrictData #-}
stan(STAN-0206)

But strictness fields are not allowed in type data declarations.

tomjaguarpaw commented 9 months ago

Thanks, I agree this is a bug. I suspect it will only be fixed if there's a volunteer contribution.

noughtmare commented 9 months ago

I've looked into it a bit and I think the change should be somewhere here:

https://github.com/kowainik/stan/blob/ddcd461be0bfe3ff7d5353ff6f5d64fb0536c38e/src/Stan/Analysis/Analyser.hs#L167-L180

But I don't quite know what to change yet.