elm / compiler

Compiler for Elm, a functional language for reliable webapps.
https://elm-lang.org/
BSD 3-Clause "New" or "Revised" License
7.48k stars 659 forks source link

Detect misusage of Debug.log #2233

Closed Warry closed 2 years ago

Warry commented 2 years ago

Quick Summary: ???

A coworker struggled finding the reason why their Debug.log didn't fire anything. The log function was actually assigned to _, a common pattern we use in the company, but missing the last parametter. It was actually assigning the identity function to underscore.

Shouldn't it fire some kind of error or warning, as it's probably not intended ? Assigning a function to _ (underscore) could be a compile error, or maybe using Debug.* missing a parameter be forbidden to ensure no silent behaviour ?

It could go in elm-review, but we do not run this on each file save, so I don't know to how much extend this could be as good as a solution.

SSCCE

hello =
    let
        _ : a -> a
        _ =
            Debug.log "Hello"
    in
    "world"
github-actions[bot] commented 2 years ago

Thanks for reporting this! To set expectations:

Finally, please be patient with the core team. They are trying their best with limited resources.

lue-bird commented 2 years ago

Is also discussed in https://github.com/elm/core/issues/1082.