hsdev icon indicating copy to clipboard operation
hsdev copied to clipboard

Conditionals in package.yaml/cabal files

Open carymrobbins opened this issue 5 years ago • 2 comments

Let's imagine we have something like the following in our package.yaml -

  when:
    - condition: flag(prod)
      then:
        ghc-options:
          - -Wall
          - -Werror
      else:
        ghc-options:
          - -Wall

It seems that the first block with -Wall -Werror is used by hsdev even though the prod flag is not set.

This became apparent when redundant import warnings were being reported by hsdev and, because they were turned into errors, did not allow further error checking of other modules to proceed. In fact, what you'd generally want from hsdev, I'd imagine, is that everything to be interpreted as warnings so error checking can continue through the entire project. Otherwise, the file you are checking may not get error highlighting due to a warning produced in some imported source.

Is there a way to deal with this by supplying flags to hsdev? For instance, it would be quite valuable to be able to tell hsdev to use all of the defer flags (explicit is fine) from ghc, e.g.

% ghc --show-options | grep '^-fdefer'
-fdefer-type-errors
-fdefer-typed-holes
-fdefer-out-of-scope-variables

I've tried using hsdev scan --project <path> --tool stack -g -Wwarn but that doesn't seem to get around the -Werror.

carymrobbins avatar Dec 18 '19 19:12 carymrobbins

Unfortunately hsdev now doesn't support project flags. As a workaround in this particular case you may try specifying --ghc option in hsdev check (and similar) command. But, of course, general solution should allow passing project's flags to hsdev.

mvoidex avatar Dec 18 '19 19:12 mvoidex

I'm just surprised that it's defaulting the prod flag to true in my case. I'd think by default, if it didn't support flags, it would just default everything to false. But I'm likely underappreciating the complexity here.

carymrobbins avatar Dec 18 '19 20:12 carymrobbins