-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
False positive on NoUnused.CustomTypeConstructorArg
#25
Comments
Hi @jpagex Thanks for creating the issue 🙂 I am not sure what the correct approach is here. In the example you gave here, the condition But if we take I think to handle this case well we need to check for comparisons of values of this type and count all parameters as used. The annoying thing is that we would need type inference for that, and even that might not be enough on its own... :/ I fear that this might a very tricky issue to solve, though fortunately for few situations. If someone has a bright idea for this, let me know. In the meantime, a workaround is to extract the string out of an equals : Id a -> Id a -> Bool
equals (Id a) (Id b) = a == b |
Actually, the real use case is more of the following: type AgendaEventId
= ScheduleItemId Time.Weekday Hour Hour
| LessonId Id
| EventId Id In this case, the custom type is quite useful. In my use case, I only need to compare the IDs, which is why I used the The proposition you made was exactly how I solved it: areSameIds : AgendaEventId -> AgendaEventId -> Bool
areSameIds id1 id2 =
case ( id1, id2 ) of
( ScheduleItemId w1 s1 e1, ScheduleItemId w2 s2 e2 ) ->
w1 == w2 && s1 == s2 && e1 == e2
( LessonId l1, LessonId l2 ) ->
l1 == l2
( EventId e1, EventId e2 ) ->
e1 == e2
_ ->
False It is indeed an edge case and there is a workaround. I would consider this a bug. Nevertheless, being forced to create a function to be explicit on the comparison is an improvement in my opinion. I do not have a case in mind where it would be preferred to use the |
I'm not sure I agree that |
In this precise case I agree, I am not so sure either. For more complex opaque types, it could still be better to make it clear/explicit how to compare two objects instead of relying on the Nevertheless, making Thanks for your work. |
Another data point: we're using pzp1997/assoc-list where the keys are custom types where some constructors have arguments. |
@r-k-b could you provide an SSCCE so that we're both on the same page? |
Sure, here's one: module Main exposing (..)
import AssocList exposing (fromList)
type Route
= UserInfo Int
routes : AssocList.Dict Route String
routes =
fromList [ ( UserInfo 1, "foo" ), ( UserInfo 2, "bar" ) ]
{-| routeA == Just "bar"
-}
routeA : Maybe String
routeA =
{- The type constructor argument is indirectly "used" as a key to extract
the value, but the Rule warns that the argument is never extracted.
-}
AssocList.get (UserInfo 2) routes |
Fixed in v1.1.7 :) |
Thank you for the work. Unfortunately it does not solve my use case. Here is another SSCCE:
module Main exposing (..)
import Html exposing (Html)
type Id
= Id String
type Hour
= Hour Int
type AgendaEventId
= ScheduleItemId Time.Weekday Hour Hour
| LessonId Id
| EventId Id
type alias AgendaEvent =
{ id : AgendaEventId
, title : String
}
main : Html msg
main =
let
event =
{ id = EventId (Id "1")
, title = "Event 1"
}
simultaneousAgendaEvents =
[ { id = ScheduleItemId Time.Mon (Hour 480) (Hour 600)
, title = "Schedule 1"
}
, { id = LessonId (Id "2")
, title = "Lesson 1"
}
]
simultaneousPosition =
getSimultaneousPosition event simultaneousAgendaEvents
in
Html.text (String.fromInt simultaneousPosition)
getSimultaneousPosition : AgendaEvent -> List AgendaEvent -> Int
getSimultaneousPosition event events =
events
|> List.indexedMap (\a b -> ( a, b ))
|> List.filter (\( _, e ) -> e.id == event.id)
|> List.map (\( idx, _ ) -> idx)
|> List.head
|> Maybe.withDefault 0 |
Yeah... this is a part where you're doing something too clever for the rule. I think that for this we'd need type inference, which we won't have for quite some time, and even then I am not sure we'll be able tell in all cases. I'd say in this case we could? I'll re-open the issue, but don't expect this to be fixed anytime soon, it's going to be a lot of work to get there 😕 |
Thanks for this fast response! Do not worry at all! You are doing a great job and I love the tool! This is not blocking me. I just wanted to let you know about my case and give you a feedback. I am really grateful for the time you are investing. |
@jfmengels I might be missing something, but I don’t make the connection between this issue an the PR (#40) that closed this? |
Ugh. Someone opened an issue on |
I see. Maybe you can add an issue template to the deprecated repos that repeats that stuff has moved to the new ones. |
False positive on
NoUnused.CustomTypeConstructorArg
when the type is only use in equality comparisons.SSCCE (Short Self-Contained Correct Example)
When running
npx elm-review --template jfmengels/elm-review-unused/example
on the following code:I get:
Even though I need the
String
parameter.Expected behavior
No error reported.
Additional context
elm-review
CLI version: 2.3.3"jfmengels/elm-review": "2.3.8"
"jfmengels/elm-review-unused": "1.1.4"
The text was updated successfully, but these errors were encountered: