roc icon indicating copy to clipboard operation
roc copied to clipboard

Unused def is not reported as unused

Open rtfeldman opened this issue 3 years ago • 1 comments

This (correctly) warns about the Action type alias being unused, but then (incorrectly) does not report that button is unused.

app "hello-rust"
    packages { pf: "platform" }
    imports []
    provides [ main ] to pf

Elem state :
    [
        Button (ButtonConfig state) (Elem state),
        Text Str,
        Col (List (Elem state)),
        Row (List (Elem state)),
    ]

ButtonConfig state : { onPress : state, PressEvent -> Action state }

PressEvent : { button : [ Touch, Mouse [ Left, Right, Middle ] ] }

Action state : [  ]

greeting =
    hi = "Hello"
    name = "World"

    "\(hi), \(name)!\n"

main =
    button = Button { onPress : \_, _ -> None } (Text "Hello, button!")

    greeting

rtfeldman avatar Feb 05 '22 15:02 rtfeldman

Looks to do the correct reporting on trunk!

» Elem state :
…     [
…         Button (ButtonConfig state) (Elem state),
…         Text Str,
…         Col (List (Elem state)),
…         Row (List (Elem state)),
…     ]
…
… ButtonConfig state : { onPress : state, PressEvent -> Action state }
…
… PressEvent : { button : [ Touch, Mouse [ Left, Right, Middle ] ] }
…
… Action state : [  ]
…
… greeting =
…     hi = "Hello"
…     name = "World"
…
…     "\(hi), \(name)!\n"
…
… main =
…     button = Button { onPress : \_, _ -> None } (Text "Hello, button!")
…
…     greeting
… main

── UNUSED TYPE ALIAS PARAMETER ─────────────────────────────────────────────────

The state type parameter is not used in the Action alias definition:

16│      Action state : [  ]
                ^^^^^

Roc does not allow unused type parameters!

Tip: If you want an unused type parameter (a so-called "phantom
type"), read the guide section on phantom values.

── UNUSED DEFINITION ───────────────────────────────────────────────────────────

button is not used anywhere in your code.

25│          button = Button { onPress : \_, _ -> None } (Text "Hello, button!")
             ^^^^^^

If you didn't intend on using button then remove it so future readers
of your code don't wonder why it is there.

ayazhafiz avatar Aug 10 '22 22:08 ayazhafiz

Closing as resolved on main.

ayazhafiz avatar Aug 17 '22 17:08 ayazhafiz