Closed erlandsona closed 2 years ago
@erlandsona Just want to check, but are you sure you don't pattern match using Stuff.Ctor ->
, right? That sounds unlikely seeing as applying the fix creates a compiler error.
I have trouble reproducing it. This is what I tried
Given
module B exposing (C(..))
type C = D
Then I tried:
module A exposing (a)
import B exposing (C(..))
a =
case x of
D -> 1
and also
module A exposing (a)
import B exposing (C(..))
a (D x) = 1
I must be missing something, but I feel a bit blind without the part where you use the constructor.
In ModuleA.elm
module ModuleA exposing (Millions(..), decoder)
type Millions
= Millions Float
decoder : Decoder Millions
decoder = Decode.float |> Decode.map Millions
Then in ModuleB.elm
import ModuleA exposing (Millions(..))
fn : Millions -> Float
fn (Millions f) = f
That should trigger it... the issue here is that we're providing the runtime instances of the Millions via the decoder so we never actually "construct" one of them outside of ModuleA but ModuleB is definitely using the constructor.
Hmm, it's a bit embarrassing but I'm still unable to reproduce this. What I'm trying is to add a test with your examples to the test suite for the rule, and they all behave as expected, not returning any error.
Would it be possible for you to create an SSCCE? Maybe you can re-use someone else's SSCCE like this one or use it as inspiration to get you started.
Are you perhaps running elm-review
with arguments, like elm-review src/
, thereby ignoring some folders (like src-gen/
which would contain ModuleA
for instance)? That's one of the few known ways where people can artificially create false positives :thinking:
So I just forked the sscce & tried reproducing the issue locally myself and no bones 🤔 What's weird is nearly 1-to-1 with what the code looks like in production but maybe there's something I'm just not seeing. We don't really have much/any codegen (yet 😏) so I that's likely not the culprit. And far as running the cli here's our Make task...
ELM_REVIEW := node_modules/.bin/elm-review
ELM_DIR := elm
.PHONY : elm-review
elm-review : $(ELM_REVIEW)
> @echo "Running elm-review"
> cd $(ELM_DIR) && ../$(ELM_REVIEW) --compiler ../node_modules/.bin/elm
Here's the link to my repro attempt... https://github.com/erlandsona/elm-review-unused-sscce
Guess this is gonna be more nefarious trackin' down than something reproducible in the small :/
Since we can't reproduce, I'm going to close the issue. Please comment back if you're able to do it again (or open a different issue).
Fair enough... Also with suppress
it's generally been a non-issue anyways so woooooo!
Wait? Do you still have the issue in your codebase?
Haven't checked in a while 😅 I think so?
Well, if you ever figure that out again, you know what to do :smile:
Describe the bug A clear and concise description of what the bug is.
Not entirely sure why this is happening as the Constructor is being used in another file to unpack a decoded value. The fix causes a compile error but I don't want to remove the rule for the file?
SSCCE (Short Self-Contained Correct Example) Steps to reproduce the behavior:
Decode.int |> Decode.map Ctor
import Stuff exposing (TheType(..))
Ctor
in a function head pattern match but not to construct a value.Expected behavior This should NOT cause the rule to activate, let me know if you need anything else but hope this silently helps someone else before they hit this as well...
Additional Context src/review/elm.json