Giter Site home page Giter Site logo

Comments (13)

swsnr avatar swsnr commented on June 21, 2024

It looks like flycheck-haskell do not take cabal defined macros into account.

It doesn't. You can easily add the necessary macros to the corresponding options, though.

PS. Why dont just use cabal build to build modules, or just get all parameters which cabal gives to ghc using e.g. http://hackage.haskell.org/package/cabal-cargs ?

If you ask me this way, I'd say that I didn't yet need this myself, and none else–including you—has bothered to make a pull request… not that I'd merge it, though, because I do have reasons for the things I do, you know.

from flycheck-haskell.

ntc2 avatar ntc2 commented on June 21, 2024

@lunaryorn: could you explain how to "add the necessary macros to the corresponding options"? I'm getting a similar error from #if !MIN_VERSION_base(4,8,0) guards.

from flycheck-haskell.

swsnr avatar swsnr commented on June 21, 2024

@ntc2 There's flycheck-ghc-args which is simple a list of additional flags for GHC in Flycheck. You can add -cpp and -DMIN_VERSION_base(4, 8, 0) to it to define the macro for Flycheck syntax checking/

from flycheck-haskell.

ntc2 avatar ntc2 commented on June 21, 2024

@lunaryorn: thanks for your help! Adding -cpp and -DMIN_VERSION_base(4, 8, 0) to flycheck-ghc-args did not work for me, but I was able to find other settings that do work.

Following a blog (http://www.christopherbiscardi.com/tag/min_version_base/) I found that adding

"-I<absolute path in Cabal sandbox to>/build/autogen" "-optP-include" "-optPcabal_macros.h"

to flycheck-ghc-args works, because cabal_macros.h is where the MIN_VERSION macros are defined.

Then, following @s9gf4ult 's suggestion, I found that installing cabal-cargs and doing (setq flycheck-ghc-args (split-string (shell-command-to-string "cabal-cargs"))) achieves this in a more general way (although might be broken if any paths had spaces in them; my paths do not).

The above fixes make the FlyCheck haskell-ghc checker succeed, but haskell-hlint still fails with

Suspicious state from syntax checker haskell-hlint: Checker haskell-hlint returned non-zero exit code 1, but no errors from output: hlint: Cannot expand #if directive in file /home/conathan/cfar/reopt.git/src/Reopt/Concrete/flycheck_Semantics.hs  at line 39 col 1:
    MIN_VERSION_base(a,b,c) is not a defined macro

Checker definition probably flawed.

(No idea what's going on with the flycheck_ on the path in the error message.)

from flycheck-haskell.

swsnr avatar swsnr commented on June 21, 2024

@ntc2 The prefix comes from the temporary file that Flycheck creates to check modified buffers.

You'd need to define the macro for hlint as well, but I don't know how to do that. Presumably there's an hlint option for that, but it don't think it's wrapped in Flycheck.

Please open a new issue on Flycheck's main issue tracker for the hlint problem. Thanks.

from flycheck-haskell.

mrkkrp avatar mrkkrp commented on June 21, 2024

If anyone is having trouble with this, easiest solution, IMHO is this:

(setq
 flycheck-ghc-args
 '("-cpp"
   "-DMIN_VERSION_base(a,b,c)"))

;; alternatively:

(require 'flycheck)

(add-to-list 'flycheck-ghc-args "-cpp")
(add-to-list 'flycheck-ghc-args "-DMIN_VERSION_base(a,b,c)")

This worked for me, no need to install anything with Cabal. Not sure there are any adverse effects.


Edit: there are still problems with hlint, this solution should work better once flycheck/flycheck#713 is fixed.

from flycheck-haskell.

ntc2 avatar ntc2 commented on June 21, 2024

@mrkkrp: in general any package <pkg> can have a MIN_VERSION_<pkg> macro -- I think Cabal generates one for each dependency in the .cabal -- but in practice not many of them get used. So, no adverse effects, but that is not a general solution.

from flycheck-haskell.

mrkkrp avatar mrkkrp commented on June 21, 2024

@ntc2, Yeah, true, although I'm sure in 90% of cases it's base. What about progress with that hlint issue? Should I try to add option for hlint parameters? Unless someone already doing this, I think I will open a PR, because this would fix the problem for me completely.

from flycheck-haskell.

ntc2 avatar ntc2 commented on June 21, 2024

@mrkkrp: it doesn't look like anything is happening on the hlint issue. You're right that MIN_VERSION_base is the common case, although grepping through projects I've worked on recently I also see MIN_VERSION_ macros for template_haskell, time, and directory in use. Of course, it's not hard to add three more -D args to flycheck-ghc-args :)

from flycheck-haskell.

swsnr avatar swsnr commented on June 21, 2024

I clearly said right away that I won't add that myself and will leave that to someone else's pull request. I haven't got any so far after two months, so I'm definitely not going to take any blame for that issue still being open.

from flycheck-haskell.

mrkkrp avatar mrkkrp commented on June 21, 2024

@lunaryorn, I personally don't blame you at all, I just asked if anyone is already doing that.

from flycheck-haskell.

ntc2 avatar ntc2 commented on June 21, 2024

@lunaryorn: sorry, I was not intending to blame you or anyone else. I was just responding to @mrkkrp's question about whether any progress has been made on the issue. I really appreciate all your hard work on flycheck; I have contributed nothing.

from flycheck-haskell.

mrkkrp avatar mrkkrp commented on June 21, 2024

@ntc2, OK, my PR introducing flycheck-hlint-args has been merged, so now I use this:

(defun mk-haskell-set-min-versions (lib-list)
  "Help Flycheck handle Cabal MIN_VERSION_ definitions.

LIB-LIST should of the following form:

  (LIB-NAME V0 V1 V2)

Where LIB-NAME is a string, name of library and V0, V1, V2 are
version components."
  (add-to-list 'flycheck-ghc-args   "-cpp")
  (add-to-list 'flycheck-hlint-args "-XCPP")
  (dolist (item lib-list)
    (cl-destructuring-bind (lib a b c) item
      (add-to-list
       'flycheck-ghc-args
       (format "-DMIN_VERSION_%s(a,b,c)=(a<=%d&&b<=%d&&c<=%d)"
               lib a b c))
      (add-to-list
       'flycheck-hlint-args
       (format "--cpp-define=MIN_VERSION_%s(a,b,c)=(a<=%d&&b<=%d&&c<=%d)"
               lib a b c)))))

(mk-haskell-set-min-versions
 '(("base" 4 8 0)))

No, I don't like it either, but everything is working fine at last.

from flycheck-haskell.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.